]>
git.saurik.com Git - apt.git/blob - cmdline/apt-extracttemplates.cc
10 #include <apt-pkg/init.h>
11 #if APT_PKG_MAJOR >= 3
12 #define APT_COMPATIBILITY 986
13 #include <apt-pkg/debversion.h>
15 #include <apt-pkg/pkgcache.h>
16 #include <apt-pkg/configuration.h>
17 #include <apt-pkg/progress.h>
18 #include <apt-pkg/sourcelist.h>
19 #include <apt-pkg/pkgcachegen.h>
20 #include <apt-pkg/version.h>
23 #define TMPDIR "/var/lib/debconf/"
24 #define STR(x) (x ? x : "")
25 //#define TMPDIR "tmp/"
29 fprintf(stderr
, "apt-extracttemplates deb [deb]\n");
33 char *writefile(const char *prefix
, const char *data
)
37 snprintf(fn
, sizeof(fn
), "%s%s.%u%d", TMPDIR
, prefix
, getpid(), i
++);
39 if (data
== NULL
) data
= "";
42 if (!ofs
) return NULL
;
48 void writeconfig(const DebFile
&file
)
50 char *templatefile
= writefile("template", file
.Template
);
51 char *configscript
= writefile("config", file
.Config
);
53 if (templatefile
== 0 || configscript
== 0)
55 fprintf(stderr
, "Cannot write config script or templates\n");
58 printf("%s %s %s %s\n",
59 STR(file
.Package
), // Package
60 STR(file
.Version
), // Version
61 templatefile
, // Template
62 configscript
// Config
66 void init(MMap
*&Map
, pkgCache
*&Cache
)
68 // Initialize the apt cache
69 if (pkgInitConfig(*_config
) == false || pkgInitSystem(*_config
, _system
) == false)
71 fprintf(stderr
, "Cannot initialize apt cache\n");
77 pkgMakeStatusCache(List
,Prog
,&Map
,true);
78 Cache
= new pkgCache(Map
);
81 int main(int argc
, char **argv
, char **env
)
87 const char *debconfver
= NULL
;
89 init(Map
, DebFile::Cache
);
90 if (Map
== 0 || DebFile::Cache
== 0)
92 fprintf(stderr
, "Cannot initialize APT cache\n");
96 debconfver
= DebFile::GetInstalledVer("debconf");
98 if (debconfver
== NULL
)
100 fprintf(stderr
, "Cannot get debconf version. Is debconf installed?\n");
105 debs
= new char *[numdebs
];
106 memcpy(debs
, &argv
[1], sizeof(char *) * numdebs
);
110 fprintf(stderr
, "apt-extracttemplates foo.deb [...]\n");
114 for (idx
= 0; idx
< numdebs
; idx
++)
116 DebFile
file(debs
[idx
]);
117 if (file
.Go() == false)
119 fprintf(stderr
, "Cannot read %s\n", debs
[idx
]);
122 if (file
.Template
!= 0 && file
.ParseInfo() == true)
124 if (file
.DepVer
!= 0 && *file
.DepVer
!= 0 &&
125 pkgCheckDep(file
.DepVer
,
126 debconfver
, file
.DepOp
) == false)
128 if (file
.PreDepVer
!= 0 && *file
.PreDepVer
!= 0 &&
129 pkgCheckDep(file
.PreDepVer
,
130 debconfver
, file
.PreDepOp
) == false)
139 delete DebFile::Cache
;