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 flags = 0; 73 74 #ifdef ENABLE_NLS 75 setlocale (LC_ALL, ""); 76 bindtextdomain (PACKAGE, LOCALEDIR); 77 textdomain (PACKAGE); 78 #endif 79 80 /* 81 * XXX TODO: set transport and rendezvous from 82 * corresponding environment variables, if set. 83 */ 84 85 strlcpy(os_root, DEFAULT_OS_ROOT, sizeof(os_root)); 86 87 #ifdef DEBUG 88 dfui_debug_file = fopen("/tmp/dfuibe_installer_debug.log", "w"); 89 #endif 90 91 /* 92 * Get command-line arguments. 93 */ 94 while ((opt = getopt(argc, argv, "o:r:t:")) != -1) { 95 switch (opt) { 96 case 'o': 97 strlcpy(os_root, optarg, sizeof(os_root)); 98 break; 99 case 'r': 100 rendezvous = aura_strdup(optarg); 101 break; 102 case 't': 103 transport = user_get_transport(optarg); 104 break; 105 case '?': 106 default: 107 usage(argv); 108 } 109 } 110 argc -= optind; 111 argv += optind; 112 113 if (transport == 0) 114 transport = user_get_transport("tcp"); 115 116 if (rendezvous == NULL) { 117 if (transport == DFUI_TRANSPORT_TCP) 118 rendezvous = aura_strdup("9999"); 119 else 120 rendezvous = aura_strdup("test"); 121 } 122 123 do_reboot = flow(transport, rendezvous, os_root, 124 flags); 125 free(rendezvous); 126 127 if (do_reboot) 128 exit(5); 129 else 130 exit(0); 131 } 132 133 static void 134 usage(char **argv) 135 { 136 fprintf(stderr, _("Usage: %s [-o rootdir] [-r rendezvous] " 137 "[-t npipe|tcp]\n"), argv[0]); 138 exit(1); 139 } 140