SF.net SVN: morphix: [2363] trunk/mmaker/src
[email protected] Thu, 20 Jul 2006 04:51:45 -0700
| Newsgroups | gmane.linux.morphix.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 2363
Author: alextreme
Date: 2006-07-20 04:51:36 -0700 (Thu, 20 Jul 2006)
ViewCVS: http://svn.sourceforge.net/morphix/?rev=2363&view=rev
Log Message:
-----------
* initial addition of -s sources.tar.gz (for automatic sources
retrieval)
Modified Paths:
--------------
trunk/mmaker/libmorphix/makemodule.c
trunk/mmaker/libmorphix/makemodule.h
trunk/mmaker/src/main.c
Modified: trunk/mmaker/libmorphix/makemodule.c
===================================================================
--- trunk/mmaker/libmorphix/makemodule.c 2006-07-19 19:26:09 UTC (rev 2362)
+++ trunk/mmaker/libmorphix/makemodule.c 2006-07-20 11:51:36 UTC (rev 2363)
@@ -98,6 +98,27 @@
return TRUE;
}
+/* Note that the returned data must be free()'ed! */
+
+gchar* ExecuteCommandReturnStdin(gchar *command) {
+ gchar *outbuffer = NULL;
+ gint exitstatus;
+ fprintf(stderr,"Exec: %s\n",command);
+
+ if (g_spawn_command_line_sync(command,&outbuffer,NULL,&exitstatus,NULL) == FALSE) {
+ fprintf(stderr,"Error occured executing command\n");
+ if (outbuffer != NULL && globals_lm.all_output == TRUE) {
+ fprintf(stderr, "%s", outbuffer);
+ }
+ g_free(outbuffer);
+ return FALSE;
+ }
+ if (outbuffer != NULL && globals_lm.all_output == TRUE) {
+ fprintf(stderr, "%s", outbuffer);
+ }
+ return outbuffer;
+}
+
/**
Executes a command, while replacing parent in/out/err with child in/out/err
blocks until child returns
@@ -1050,22 +1071,27 @@
if (repos->suite != NULL) {
fprintf(fd,"deb %s %s main contrib non-free\n",repos->name,repos->suite);
+ fprintf(fd,"deb-src %s %s main contrib non-free\n",repos->name,repos->suite);
}
else {
fprintf(fd,"deb %s %s main contrib non-free\n",repos->name,module->suite);
+ fprintf(fd,"deb-src %s %s main contrib non-free\n",repos->name,module->suite);
}
}
else {
if (repos->suite != NULL) {
fprintf(fd,"deb %s %s main\n",repos->name,repos->suite);
+ fprintf(fd,"deb-src %s %s main\n",repos->name,repos->suite);
}
else {
fprintf(fd,"deb %s %s main\n",repos->name,module->suite);
+ fprintf(fd,"deb-src %s %s main\n",repos->name,module->suite);
}
}
}
else if (repos->type == REPOS_TYPE_PLAIN) {
fprintf(fd,"deb %s ./\n",repos->name);
+ fprintf(fd,"deb-src %s ./\n",repos->name);
}
ptr = ptr->next;
}
@@ -1181,6 +1207,62 @@
return TRUE;
}
+gboolean getAptPackageSources(mmodule *module, gchar *sources_location) {
+ gchar *cmdline = NULL;
+ gchar *stdinput = NULL;
+ gchar **buf_array = NULL;
+
+ gint count = 5; // skip first 5 lines of dpkg -l
+
+ if (sources_location == NULL) { // no sources wanted
+ return TRUE;
+ }
+
+ cmdline = g_strdup_printf("%s/sources", module->dirname);
+ if (mkdir(cmdline,0755) != 0) {
+ g_free(cmdline);
+ return FALSE;
+ }
+ g_free(cmdline);
+
+ /**
+ Why via dpkg -l? Well, we also want to download
+ the source to all dependancies, module->packagelist
+ simply isn't enough...
+ */
+
+ cmdline = g_strdup_printf("%s %s sh -c \"COLUMNS=160 dpkg -l | gzip > /morphix/packages.gz\"",P_CHROOT,dirname);
+ stdinput = ExecuteCommandReturnStdin(cmdline);
+ g_free(cmdline);
+ buf_array = g_strsplit(stdinput,"\n",0);
+
+ /** Each line looks like: XXX packagename version description */
+
+ while(buf_array[count] != NULL) {
+ if (buf_array[count][0] == 'i') { // package installed
+ gchar packagename[160] = "";
+ gint ret = sscanf(buf_array[count],"ii %159s",packagename);
+ if (ret > 0) {
+ cmdline = g_strdup_printf("%s %s cd /sources && apt-get --download-only source %s",P_CHROOT, module->dirname, packagename);
+ ExecuteCommand(cmdline);
+ g_free(cmdline);
+ }
+ }
+ count++;
+ }
+
+ cmdline = g_strdup_printf("tar zcvf %s %s/sources", sources_location, module->dirname);
+ ExecuteCommand(cmdline);
+ g_free(cmdline);
+
+ cmdline = g_strdup_printf("rm -rf %s/sources", module->dirname);
+ // Enable this after everything works...
+ // ExecuteCommand(cmdline);
+ g_free(cmdline);
+
+ return TRUE;
+}
+
/**
Returns the kernel version, if available.
Returns NULL otherwise
@@ -1233,10 +1315,11 @@
@param debbzip2 gchar*; path to the debootstrapped bzip2 archive, or NULL
@param debootdir gchar *; path where the module should be built or NULL
@param extra_package_list GList *; list of package-paths from the host system or NULL
+ @param sources_location gchar *; location of where the sources should be stored
return FALSE on error
*/
-gboolean makeModuleToFile(mmodule *module,gchar *xmlfilename,gchar *outputfilename,gboolean leave_dir, gchar *debtarball, gchar *debbzip2, gchar *debootdir, GList *extra_package_list) {
+gboolean makeModuleToFile(mmodule *module,gchar *xmlfilename,gchar *outputfilename,gboolean leave_dir, gchar *debtarball, gchar *debbzip2, gchar *debootdir, GList *extra_package_list, gchar *sources_location) {
globals_lm.redirect_input = FALSE;
globals_lm.fakebuild = FALSE;
@@ -1264,6 +1347,9 @@
if (!installLocalPackages(module)) {
return FALSE;
}
+ if (!getAptPackageSources(module, sources_location)) {
+ return FALSE;
+ }
if (!executeRetrieveFiles(module)) {
return FALSE;
}
@@ -1293,6 +1379,9 @@
if (!installLocalPackages(module)) {
return FALSE;
}
+ if (!getAptPackageSources(module, sources_location)) {
+ return FALSE;
+ }
if (!moveMorphixEtcFiles(module)) {
return FALSE;
}
Modified: trunk/mmaker/libmorphix/makemodule.h
===================================================================
--- trunk/mmaker/libmorphix/makemodule.h 2006-07-19 19:26:09 UTC (rev 2362)
+++ trunk/mmaker/libmorphix/makemodule.h 2006-07-20 11:51:36 UTC (rev 2363)
@@ -31,7 +31,8 @@
gboolean addRepositories(mmodule *module,gchar *dirname);
gboolean setupDebootstrap(mmodule *module);
gboolean addPackages(mmodule *module, gboolean depmod, GList *extra_package_list);
-gboolean makeModuleToFile(mmodule *module,gchar *xmlfilename,gchar *outputfilename,gboolean leave_dir, gchar *debtarball, gchar *debbzip2,gchar *debootdir, GList *extra_package_list);
+gboolean getAptPackageSources(mmodule *module, gchar *sources_location);
+gboolean makeModuleToFile(mmodule *module,gchar *xmlfilename,gchar *outputfilename,gboolean leave_dir, gchar *debtarball, gchar *debbzip2,gchar *debootdir, GList *extra_package_list, gchar *sources_location);
gboolean bindDevProc(mmodule *module,gchar *dirname);
gchar *getTempdir();
gchar *getKernelVersion(mmodule *module);
Modified: trunk/mmaker/src/main.c
===================================================================
--- trunk/mmaker/src/main.c 2006-07-19 19:26:09 UTC (rev 2362)
+++ trunk/mmaker/src/main.c 2006-07-20 11:51:36 UTC (rev 2363)
@@ -24,19 +24,22 @@
#include "../libmorphix/makemodule.h"
void usage(gchar *filename) {
- printf("Usage: %s [-g debootstrap.tar.gz] [-b debootstrap.tar.bz] [-a /path/to/package1.deb [-a /path/to/package2.deb]] [-m miniroot.gz] [-k vmlinuz-mykernel] [-t /tempdir] [-d /debootstrapped] [-p http://proxy.mydomain.com:8080] [-v] [-i] [-c] input.xml output.mod\n\n",filename);
+ printf("Usage: %s [-g debootstrap.tar.gz] [-b debootstrap.tar.bz] [-a /path/to/package1.deb [-a /path/to/package2.deb]] [-m miniroot.gz] [-k vmlinuz-mykernel] [-t /tempdir] [-d /debootstrapped] [-p http://proxy.mydomain.com:8080] [-s /path/to/sources.gz] [-v] [-i] [-c] input.xml output.mod\n\n",filename);
- printf("\t-g:\tuse supplied tarball as debootstrap for building module with\n");
printf("\t-a:\tadd this package to the module\n");
- printf("\t-b:\tditto for bzip2\n");
+ printf("\t-b:\tuse supplied bzip2-compressed tarball as debootstrap for building the module with\n");
+ printf("\t-c:\tclean, remove the temporary directory (%s/libmorphix*) afterwards, incompatible with -m\n",getTempRoot());
+ printf("\t-d:\tuse this directory instead of debootstrapping fresh (copies files over)\n");
+ printf("\t-g:\tuse supplied gzip-compressed tarball as debootstrap for building the module with\n");
+ printf("\t-i:\tinteractive mode\n");
+ printf("\t-k:\t(base module) output the kernel here\n");
printf("\t-m:\t(base module) output the miniroot here (needs mkminiroot-morphix)\n");
- printf("\t-k:\t(base module) output the kernel here\n");
+ printf("\t-s:\tStore all package sources in this image (make sure given repositories are also allow source retrieval)\n");
+ printf("\t-p:\tuse this to specify a http proxy for apt. Use URI as 'http://proxy.mydomain.com:8080'\n");
printf("\t-t:\tuse this temp directory instead of making a new one\n");
- printf("\t-d:\tuse this directory instead of debootstrapping fresh (copies files over)\n");
- printf("\t-p:\tuse this to specify a http proxy for apt. Use URI as 'http://proxy.mydomain.com:8080'\n");
- printf("\t-i:\tinteractive mode\n");
+
printf("\t-v:\tverbose mode\n");
- printf("\t-c:\tclean, remove the temporary directory (%s/libmorphix*) afterwards, incompatible with -m\n",getTempRoot());
+
printf("\nThis tool is made possible by an infinite amount of monkeys\n");
}
@@ -65,6 +68,7 @@
gchar *debbzip2 = NULL;
gchar *proxy = NULL;
gchar optchar;
+ gchar *sources_location = NULL;
gint opts = 0;
GList *packagelist = NULL;
@@ -128,6 +132,11 @@
opts+=1;
verbose = TRUE;
break;
+ case 's':
+ // we also want to store the source packages
+ opts+=2;
+ sources_location = (char *) g_strdup(optarg);
+ break;
case '?':
printf("Unknown command line option...\n");
usage(argv[0]);
@@ -163,13 +172,13 @@
unsetenv("LANG");
setTempDir(module,tempdir);
- if (!makeModuleToFile(module,argv[1+opts],argv[2+opts],leave_dir,debtarball,debbzip2,debootdir, packagelist)) {
+ if (!makeModuleToFile(module,argv[1+opts],argv[2+opts],leave_dir,debtarball,debbzip2,debootdir, packagelist, sources_location)) {
fprintf(stderr,"Error: Building of module failed!\n");
fprintf(stderr,"Please make sure all settings are correct. If you believe this is a bug, please contact the maintainer of this package\n");
}
else {
if (miniroot != NULL && strcmp(module->type,"basemod") == 0) {
- printf("Info: Building miniroot from temporary directory using mkminiroot-morphix\n");
+ printf("Info: Building miniroot from temporary dxirectory using mkminiroot-morphix\n");
if (g_file_test("/usr/sbin/mkminiroot-morphix",G_FILE_TEST_EXISTS) == TRUE) {
printf("Info: mkminiroot-morphix exists\n");
cmdline = g_strdup_printf("/usr/sbin/mkminiroot-morphix %s %s/miniroot-dir %s",module->dirname,getTempRoot(),miniroot);
@@ -213,6 +222,9 @@
if (debtarball != NULL) {
g_free(debtarball);
}
+ if (sources_location != NULL) {
+ g_free(sources_location);
+ }
if (debbzip2 != NULL) {
g_free(debbzip2);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV