1 /* febootstrap-supermin-helper reimplementation in C.
2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/types.h>
36 struct timeval start_t;
39 static const char *format = "cpio";
41 enum { HELP_OPTION = CHAR_MAX + 1 };
43 static const char *options = "f:k:vV";
44 static const struct option long_options[] = {
45 { "help", 0, 0, HELP_OPTION },
46 { "format", required_argument, 0, 'f' },
47 { "kmods", required_argument, 0, 'k' },
48 { "verbose", 0, 0, 'v' },
49 { "version", 0, 0, 'V' },
54 usage (const char *progname)
56 printf ("%s: build the supermin appliance on the fly\n"
59 " %s [-options] inputs [...] whitelist host_cpu kernel initrd\n"
63 "This script is used by febootstrap to build the supermin appliance\n"
64 "(kernel and initrd output files). You should NOT need to run this\n"
65 "program directly except if you are debugging tricky supermin\n"
66 "appliance problems.\n"
68 "NB: The kernel and initrd parameters are OUTPUT parameters. If\n"
69 "those files exist, they are overwritten by the output.\n"
73 " Display this help text and exit.\n"
74 " -f cpio | --format cpio\n"
75 " Specify output format (default: cpio).\n"
76 " -k file | --kmods file\n"
77 " Specify kernel module whitelist.\n"
79 " Enable verbose messages (give multiple times for more verbosity).\n"
81 " Display version number and exit.\n",
82 progname, progname, progname, progname);
86 main (int argc, char *argv[])
88 /* First thing: start the clock. */
89 gettimeofday (&start_t, NULL);
91 const char *whitelist = NULL;
93 /* Command line arguments. */
95 int c = getopt_long (argc, argv, options, long_options, NULL);
116 printf (PACKAGE_NAME " " PACKAGE_VERSION "\n");
125 /* Select the correct writer module. */
126 struct writer *writer;
128 if (strcmp (format, "cpio") == 0)
129 writer = &cpio_writer;
131 fprintf (stderr, "%s: incorrect output format (-f): must be cpio\n",
136 char **inputs = &argv[optind];
137 int nr_inputs = argc - optind - 3;
144 /* See: https://bugzilla.redhat.com/show_bug.cgi?id=558593 */
145 const char *hostcpu = argv[argc-3];
148 const char *kernel = argv[argc-2];
149 const char *appliance = argv[argc-1];
152 print_timestamped_message ("whitelist = %s, "
156 whitelist ? : "(not specified)",
157 hostcpu, kernel, appliance);
159 for (i = 0; i < nr_inputs; ++i)
160 print_timestamped_message ("inputs[%d] = %s", i, inputs[i]);
163 /* Remove the output files if they exist. */
167 /* Create kernel output file. */
169 modpath = create_kernel (hostcpu, kernel);
172 print_timestamped_message ("finished creating kernel");
174 /* Create the appliance. */
175 create_appliance (inputs, nr_inputs, whitelist, modpath, appliance, writer);
178 print_timestamped_message ("finished creating appliance");