1 /* 2 * Copyright (c)2004 The DragonFly Project. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * Neither the name of the DragonFly Project nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 * OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * main.c 36 * Main program for installer backend. 37 * $Id: main.c,v 1.18 2005/03/11 19:57:27 cpressey Exp $ 38 */ 39 40 #include <err.h> 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <string.h> 44 #include <unistd.h> 45 46 #ifdef ENABLE_NLS 47 #include <libintl.h> 48 #define _(String) gettext (String) 49 #else 50 #define _(String) (String) 51 #endif 52 53 #include "libaura/mem.h" 54 55 #include "libdfui/dfui.h" 56 #include "libdfui/dump.h" 57 #include "libdfui/system.h" 58 59 #include "flow.h" 60 #include "pathnames.h" 61 62 static void usage(char **); 63 64 int 65 main(int argc, char **argv) 66 { 67 char os_root[256]; 68 char *rendezvous = NULL; 69 int do_reboot = 0; 70 int opt; 71 int transport = 0; 72 int booted_from_livecd = 0; 73 int upgrade_menu_toggle = 0; 74 75 #ifdef ENABLE_NLS 76 setlocale (LC_ALL, ""); 77 bindtextdomain (PACKAGE, LOCALEDIR); 78 textdomain (PACKAGE); 79 #endif 80 81 /* 82 * XXX TODO: set transport and rendezvous from 83 * corresponding environment variables, if set. 84 */ 85 86 strlcpy(os_root, DEFAULT_OS_ROOT, sizeof(os_root)); 87 88 #ifdef DEBUG 89 dfui_debug_file = fopen("/tmp/dfuibe_installer_debug.log", "w"); 90 #endif 91 92 /* 93 * Get command-line arguments. 94 */ 95 while ((opt = getopt(argc, argv, "o:r:t:")) != -1) { 96 switch (opt) { 97 case 'o': 98 strlcpy(os_root, optarg, sizeof(os_root)); 99 break; 100 case 'r': 101 rendezvous = aura_strdup(optarg); 102 break; 103 case 't': 104 transport = user_get_transport(optarg); 105 break; 106 case '?': 107 default: 108 usage(argv); 109 } 110 } 111 argc -= optind; 112 argv += optind; 113 114 if (transport == 0) 115 transport = user_get_transport("tcp"); 116 117 if (rendezvous == NULL) { 118 if (transport == DFUI_TRANSPORT_TCP) 119 rendezvous = aura_strdup("9999"); 120 else 121 rendezvous = aura_strdup("test"); 122 } 123 124 do_reboot = flow(transport, rendezvous, os_root, 125 booted_from_livecd, upgrade_menu_toggle); 126 free(rendezvous); 127 128 if (do_reboot) 129 exit(5); 130 else 131 exit(0); 132 } 133 134 static void 135 usage(char **argv) 136 { 137 fprintf(stderr, _("Usage: %s [-o rootdir] [-r rendezvous] " 138 "[-t npipe|tcp]\n"), argv[0]); 139 exit(1); 140 } 141