+#include "sysinfo.h"
+#include "platform.h"
+
+static void print_version(void)
+{
+ printf("pb-discover (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
+}
+
+static void print_usage(void)
+{
+ print_version();
+ printf(
+"Usage: pb-discover [-a, --no-autoboot] [-h, --help] [-l, --log log-file]\n"
+" [-n, --dry-run] [-v, --verbose] [-V, --version]\n");
+}
+
+/**
+ * enum opt_value - Tri-state options variables.
+ */
+
+enum opt_value {opt_undef = 0, opt_yes, opt_no};
+
+/**
+ * struct opts - Values from command line options.
+ */
+
+struct opts {
+ enum opt_value no_autoboot;
+ enum opt_value show_help;
+ const char *log_file;
+ enum opt_value dry_run;
+ enum opt_value show_version;
+ enum opt_value verbose;
+};
+
+/**
+ * opts_parse - Parse the command line options.
+ */
+
+static int opts_parse(struct opts *opts, int argc, char *argv[])
+{
+ static const struct option long_options[] = {
+ {"no-autoboot", no_argument, NULL, 'a'},
+ {"help", no_argument, NULL, 'h'},
+ {"log", required_argument, NULL, 'l'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"version", no_argument, NULL, 'V'},
+ { NULL, 0, NULL, 0},
+ };
+ static const char short_options[] = "ahl:nvV";
+ static const struct opts default_values = {
+ .no_autoboot = opt_no,
+ .log_file = "/var/log/petitboot/pb-discover.log",
+ .dry_run = opt_no,
+ .verbose = opt_no,
+ };
+
+ *opts = default_values;
+
+ while (1) {
+ int c = getopt_long(argc, argv, short_options, long_options,
+ NULL);
+
+ if (c == EOF)
+ break;
+
+ switch (c) {
+ case 'a':
+ opts->no_autoboot = opt_yes;
+ break;
+ case 'h':
+ opts->show_help = opt_yes;
+ break;
+ case 'l':
+ opts->log_file = optarg;
+ break;
+ case 'n':
+ opts->dry_run = opt_yes;
+ break;
+ case 'v':
+ opts->verbose = opt_yes;
+ break;
+ case 'V':
+ opts->show_version = opt_yes;
+ break;
+ default:
+ opts->show_help = opt_yes;
+ return -1;
+ }
+ }
+
+ return optind != argc;
+}
+
+static int running;
+
+static void sigint_handler(int __attribute__((unused)) signum)
+{
+ running = 0;
+}