[1] | 1 | /***************************************************************************
|
---|
[1080] | 2 | $Id: mondo-cli.c 1191 2007-02-20 10:20:31Z bruno $
|
---|
[1] | 3 | *******************************************************************/
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * @file
|
---|
| 7 | * Functions for handling command-line arguments passed to mondoarchive.
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | /** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
|
---|
| 11 |
|
---|
[1067] | 12 | #include "my-stuff.h"
|
---|
[1187] | 13 | #include "mondostructures.h"
|
---|
[1] | 14 | #include "mondo-cli-EXT.h"
|
---|
[1187] | 15 | #include "libmondo.h"
|
---|
| 16 | #include <pthread.h>
|
---|
[1080] | 17 | #include "mr_mem.h"
|
---|
[1120] | 18 | #include "mr_msg.h"
|
---|
[1] | 19 |
|
---|
[116] | 20 | //static char cvsid[] = "$Id: mondo-cli.c 1191 2007-02-20 10:20:31Z bruno $";
|
---|
[1] | 21 |
|
---|
| 22 | extern int g_loglevel;
|
---|
| 23 | extern bool g_text_mode;
|
---|
[116] | 24 | extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks
|
---|
| 25 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
[1] | 26 | extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN];
|
---|
| 27 | extern char g_tmpfs_mountpt[MAX_STR_LEN];
|
---|
| 28 | extern bool g_sigpipe;
|
---|
| 29 |
|
---|
| 30 | /*@ file pointer **************************************************/
|
---|
| 31 | extern FILE *g_tape_stream;
|
---|
| 32 |
|
---|
| 33 | /*@ long long *****************************************************/
|
---|
| 34 | extern long long g_tape_posK;
|
---|
| 35 |
|
---|
| 36 | /*@ long **********************************************************/
|
---|
| 37 | extern long g_noof_sets;
|
---|
| 38 |
|
---|
| 39 | /*@ bool******** **************************************************/
|
---|
[116] | 40 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
| 41 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
[1] | 42 | extern bool g_cd_recovery;
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * Whether we're restoring from ISOs. Obviously not, since this is the
|
---|
| 46 | * backup program.
|
---|
| 47 | * @note You @b MUST declare this variable somewhere in your program if
|
---|
| 48 | * you use libmondo. Otherwise the link will fail.
|
---|
| 49 | * @ingroup globalGroup
|
---|
| 50 | */
|
---|
| 51 | bool g_ISO_restore_mode = FALSE;
|
---|
| 52 |
|
---|
| 53 | extern double g_kernel_version;
|
---|
| 54 | extern int g_current_media_number;
|
---|
| 55 | extern pid_t g_main_pid;
|
---|
[116] | 56 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
|
---|
[1] | 57 |
|
---|
[948] | 58 | /* Do we use extended attributes and acl ?
|
---|
| 59 | * By default no, use --acl & --attr options to force their usage */
|
---|
| 60 | char *g_getfacl = NULL;
|
---|
| 61 | char *g_getfattr = NULL;
|
---|
[1] | 62 |
|
---|
| 63 | /**
|
---|
| 64 | * @addtogroup cliGroup
|
---|
| 65 | * @{
|
---|
| 66 | */
|
---|
| 67 | /**
|
---|
| 68 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
|
---|
| 69 | * @param argc The argument count, including the program name; @p argc passed to main().
|
---|
| 70 | * @param argv The argument vector; @p argv passed to main().
|
---|
| 71 | * @param bkpinfo The backup information structure to populate.
|
---|
| 72 | * @return The number of problems with the command line (0 for success).
|
---|
| 73 | */
|
---|
| 74 | int
|
---|
[116] | 75 | handle_incoming_parameters(int argc, char *argv[],
|
---|
| 76 | struct s_bkpinfo *bkpinfo)
|
---|
[1] | 77 | {
|
---|
[116] | 78 | /*@ int *** */
|
---|
| 79 | int res = 0;
|
---|
| 80 | int retval = 0;
|
---|
[1187] | 81 | int i = 0, j = 0;
|
---|
[1] | 82 |
|
---|
[116] | 83 | /*@ buffers *************** */
|
---|
[1187] | 84 | char *tmp = NULL;
|
---|
[116] | 85 | char flag_val[128][MAX_STR_LEN];
|
---|
| 86 | bool flag_set[128];
|
---|
[1] | 87 |
|
---|
[116] | 88 | sensibly_set_tmpdir_and_scratchdir(bkpinfo);
|
---|
[1187] | 89 |
|
---|
[116] | 90 | for (i = 0; i < 128; i++) {
|
---|
| 91 | flag_val[i][0] = '\0';
|
---|
| 92 | flag_set[i] = FALSE;
|
---|
| 93 | }
|
---|
| 94 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 95 | bkpinfo->media_size[j] = 650;
|
---|
| 96 | } /* default */
|
---|
| 97 | res =
|
---|
| 98 | retrieve_switches_from_command_line(argc, argv, flag_val,
|
---|
| 99 | flag_set);
|
---|
| 100 | retval += res;
|
---|
| 101 | if (!retval) {
|
---|
| 102 | res = process_switches(bkpinfo, flag_val, flag_set);
|
---|
| 103 | retval += res;
|
---|
| 104 | }
|
---|
[1] | 105 | /*
|
---|
| 106 | if (!retval)
|
---|
| 107 | {
|
---|
| 108 | */
|
---|
[1108] | 109 | mr_msg(3, "Switches:-");
|
---|
[116] | 110 | for (i = 0; i < 128; i++) {
|
---|
| 111 | if (flag_set[i]) {
|
---|
[1187] | 112 | mr_msg(3, "-%c %s", i, flag_val[i]);
|
---|
[116] | 113 | }
|
---|
[1] | 114 | }
|
---|
| 115 | // }
|
---|
[1187] | 116 | mr_asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
|
---|
[116] | 117 | paranoid_system(tmp);
|
---|
[1187] | 118 | mr_free(tmp);
|
---|
| 119 |
|
---|
| 120 | mr_asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
|
---|
[116] | 121 | paranoid_system(tmp);
|
---|
[1187] | 122 | mr_free(tmp);
|
---|
| 123 |
|
---|
[116] | 124 | sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld",
|
---|
| 125 | random() % 32767);
|
---|
| 126 | sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
|
---|
| 127 | "/mondo.scratch.%ld", random() % 32767);
|
---|
[1187] | 128 |
|
---|
| 129 | mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
[116] | 130 | paranoid_system(tmp);
|
---|
[1187] | 131 | mr_free(tmp);
|
---|
| 132 |
|
---|
| 133 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir);
|
---|
[116] | 134 | paranoid_system(tmp);
|
---|
[1080] | 135 | mr_free(tmp);
|
---|
[116] | 136 | return (retval);
|
---|
[1] | 137 | }
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * Store the sizespec(s) stored in @p value into @p bkpinfo.
|
---|
| 142 | * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated.
|
---|
| 143 | * @param value The sizespec (e.g. "2g", "40m").
|
---|
| 144 | * @return 0, always.
|
---|
| 145 | * @bug Return code not needed.
|
---|
| 146 | */
|
---|
| 147 | int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value)
|
---|
| 148 | {
|
---|
[116] | 149 | int j;
|
---|
[1191] | 150 | char *tmp = NULL;
|
---|
| 151 | char *p = NULL;
|
---|
| 152 | char *q = NULL;
|
---|
[1] | 153 |
|
---|
[116] | 154 | assert(bkpinfo != NULL);
|
---|
| 155 | assert(value != NULL);
|
---|
[1] | 156 |
|
---|
[116] | 157 | bkpinfo->media_size[0] = -1; /* dummy value */
|
---|
| 158 | for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
|
---|
| 159 | j++, p = strchr(p, ',') + 1) {
|
---|
[1191] | 160 | mr_asprintf(&tmp, p);
|
---|
| 161 | q = strchr(tmp, ',');
|
---|
| 162 | if (q != NULL) {
|
---|
| 163 | *q = '\0';
|
---|
| 164 | }
|
---|
[116] | 165 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
|
---|
[1191] | 166 | mr_free(tmp);
|
---|
| 167 |
|
---|
| 168 | mr_msg(3, "media_size[%d] = %ld", j,
|
---|
[116] | 169 | bkpinfo->media_size[j]);
|
---|
[1] | 170 | }
|
---|
[116] | 171 | for (; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 172 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
|
---|
[1] | 173 | }
|
---|
[116] | 174 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 175 | if (bkpinfo->media_size[j] <= 0) {
|
---|
[1108] | 176 | mr_msg(1, "You gave media #%d an invalid size\n", j);
|
---|
[116] | 177 | return (-1);
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 | return (0);
|
---|
[1] | 181 | }
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | /**
|
---|
| 185 | * Process mondoarchive's command-line switches.
|
---|
| 186 | * @param bkpinfo The backup information structure to populate.
|
---|
| 187 | * @param flag_val An array of the argument passed to each switch (the letter is the index).
|
---|
| 188 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
|
---|
| 189 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
|
---|
| 190 | * FALSE if it's not.
|
---|
| 191 | * @return The number of problems with the switches, or 0 for success.
|
---|
| 192 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
|
---|
| 193 | */
|
---|
| 194 | int
|
---|
[116] | 195 | process_switches(struct s_bkpinfo *bkpinfo,
|
---|
| 196 | char flag_val[128][MAX_STR_LEN], bool flag_set[128])
|
---|
[1] | 197 | {
|
---|
| 198 |
|
---|
[116] | 199 | /*@ ints *** */
|
---|
| 200 | int i = 0;
|
---|
| 201 | int retval = 0;
|
---|
| 202 | int percent = 0;
|
---|
[1] | 203 |
|
---|
[116] | 204 | /*@ buffers ** */
|
---|
[1191] | 205 | char *tmp = NULL;
|
---|
| 206 | char *tmp1 = NULL;
|
---|
| 207 | char *tmp2 = NULL;
|
---|
| 208 | char *psz = NULL;
|
---|
| 209 | char *p = NULL;
|
---|
| 210 | char *q = NULL;
|
---|
[1] | 211 |
|
---|
[949] | 212 | long itbs = 0L;
|
---|
[1] | 213 |
|
---|
[289] | 214 | struct stat buf;
|
---|
| 215 |
|
---|
[116] | 216 | malloc_string(tmp);
|
---|
[1] | 217 |
|
---|
[116] | 218 | assert(bkpinfo != NULL);
|
---|
| 219 | assert(flag_val != NULL);
|
---|
| 220 | assert(flag_set != NULL);
|
---|
[1] | 221 |
|
---|
[116] | 222 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[1] | 223 |
|
---|
[1191] | 224 | /* compulsory */
|
---|
[116] | 225 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
|
---|
| 226 | flag_set['t'] + flag_set['u'] + flag_set['r'] +
|
---|
[1063] | 227 | flag_set['w'] + flag_set['C'] + flag_set['U'];
|
---|
[116] | 228 | if (i == 0) {
|
---|
| 229 | retval++;
|
---|
[1191] | 230 | log_to_screen(_("You must specify the media type\n"));
|
---|
[1] | 231 | }
|
---|
[116] | 232 | if (i > 1) {
|
---|
| 233 | retval++;
|
---|
[1191] | 234 | log_to_screen(_("Please specify only one media type\n"));
|
---|
[1] | 235 | }
|
---|
[116] | 236 | if (flag_set['K']) {
|
---|
| 237 | g_loglevel = atoi(flag_val['K']);
|
---|
| 238 | if (g_loglevel < 3) {
|
---|
| 239 | g_loglevel = 3;
|
---|
| 240 | }
|
---|
[1] | 241 | }
|
---|
[116] | 242 | if (flag_set['L'] && flag_set['0']) {
|
---|
| 243 | retval++;
|
---|
[1191] | 244 | log_to_screen(_("You cannot have 'no compression' _and_ LZOP.\n"));
|
---|
[1] | 245 | }
|
---|
[116] | 246 | bkpinfo->backup_data = flag_set['O'];
|
---|
| 247 | bkpinfo->verify_data = flag_set['V'];
|
---|
| 248 | if (flag_set['I'] && !bkpinfo->backup_data) {
|
---|
[1191] | 249 | log_to_screen(_("-I switch is ignored if just verifying"));
|
---|
[116] | 250 | }
|
---|
| 251 | if (flag_set['E'] && !bkpinfo->backup_data) {
|
---|
[1191] | 252 | log_to_screen(_("-E switch is ignored if just verifying"));
|
---|
[116] | 253 | }
|
---|
[1] | 254 |
|
---|
[116] | 255 | if (!find_home_of_exe("afio")) {
|
---|
| 256 | if (find_home_of_exe("star")) {
|
---|
| 257 | flag_set['R'] = TRUE;
|
---|
[1108] | 258 | mr_msg(1, "Using star instead of afio");
|
---|
[116] | 259 | } else {
|
---|
| 260 | fatal_error
|
---|
| 261 | ("Neither afio nor star is installed. Please install at least one.");
|
---|
| 262 | }
|
---|
[1] | 263 | }
|
---|
| 264 |
|
---|
[116] | 265 | if (flag_set['R']) {
|
---|
| 266 | bkpinfo->use_star = TRUE;
|
---|
| 267 | if (flag_set['L']) {
|
---|
| 268 | fatal_error("You may not use star and lzop at the same time.");
|
---|
| 269 | }
|
---|
| 270 | if (!find_home_of_exe("star")) {
|
---|
| 271 | fatal_error
|
---|
| 272 | ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
|
---|
| 273 | }
|
---|
[1] | 274 | }
|
---|
[116] | 275 | if (flag_set['W']) {
|
---|
| 276 | bkpinfo->nonbootable_backup = TRUE;
|
---|
| 277 | log_to_screen("Warning - you have opted for non-bootable backup");
|
---|
| 278 | if (flag_set['f'] || flag_set['l']) {
|
---|
| 279 | log_to_screen
|
---|
[1191] | 280 | (_("You don't need to specify bootloader or bootdevice"));
|
---|
[116] | 281 | }
|
---|
[1] | 282 | }
|
---|
[116] | 283 | if (flag_set['t'] && flag_set['H']) {
|
---|
| 284 | fatal_error
|
---|
| 285 | ("Sorry, you may not nuke w/o warning from tape. Drop -H, please.");
|
---|
| 286 | }
|
---|
| 287 | if (flag_set['I']) {
|
---|
| 288 | if (!strcmp(bkpinfo->include_paths, "/")) {
|
---|
[1108] | 289 | mr_msg(2, "'/' is pleonastic.");
|
---|
[116] | 290 | bkpinfo->include_paths[0] = '\0';
|
---|
| 291 | }
|
---|
| 292 | if (bkpinfo->include_paths[0]) {
|
---|
| 293 | strcat(bkpinfo->include_paths, " ");
|
---|
| 294 | }
|
---|
[1080] | 295 | mr_asprintf(&tmp1, flag_val['I']);
|
---|
[603] | 296 | p = tmp1;
|
---|
| 297 | q = tmp1;
|
---|
[542] | 298 |
|
---|
| 299 | /* Cut the flag_val['I'] in parts containing all paths to test them */
|
---|
| 300 | while (p != NULL) {
|
---|
| 301 | q = strchr(p, ' ');
|
---|
| 302 | if (q != NULL) {
|
---|
| 303 | *q = '\0';
|
---|
| 304 | if (stat(p, &buf) != 0) {
|
---|
[1108] | 305 | mr_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
[542] | 306 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 307 | }
|
---|
[633] | 308 | p = q+1 ;
|
---|
[542] | 309 | } else {
|
---|
| 310 | if (stat(p, &buf) != 0) {
|
---|
[1108] | 311 | mr_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
[542] | 312 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 313 | }
|
---|
| 314 | p = NULL;
|
---|
| 315 | }
|
---|
[289] | 316 | }
|
---|
[1080] | 317 | mr_free(tmp1);
|
---|
[542] | 318 |
|
---|
[116] | 319 | strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
|
---|
| 320 | flag_val['I'],
|
---|
[543] | 321 | 4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
|
---|
[1108] | 322 | mr_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
---|
[116] | 323 | if (bkpinfo->include_paths[0] == '-') {
|
---|
| 324 | retval++;
|
---|
[1191] | 325 | log_to_screen(_("Please supply a sensible value with '-I'\n"));
|
---|
[116] | 326 | }
|
---|
| 327 | }
|
---|
[1] | 328 |
|
---|
[116] | 329 | if (g_kernel_version >= 2.6 && !flag_set['d']
|
---|
| 330 | && (flag_set['c'] || flag_set['w'])) {
|
---|
| 331 | fatal_error
|
---|
| 332 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
|
---|
[1] | 333 | }
|
---|
| 334 |
|
---|
[116] | 335 | if (flag_set['J']) {
|
---|
| 336 | if (flag_set['I']) {
|
---|
| 337 | retval++;
|
---|
| 338 | log_to_screen
|
---|
[1191] | 339 | (_("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't combine -J with -I. Thanks. :-)"));
|
---|
[116] | 340 | }
|
---|
| 341 | bkpinfo->make_filelist = FALSE;
|
---|
| 342 | strcpy(bkpinfo->include_paths, flag_val['J']);
|
---|
[1] | 343 | }
|
---|
[1191] | 344 |
|
---|
[116] | 345 | if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) {
|
---|
| 346 | if (!flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 347 | && strstr(flag_val['d'], "/dev/")) {
|
---|
| 348 | fatal_error
|
---|
| 349 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
|
---|
| 350 | }
|
---|
| 351 | if (flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 352 | && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 353 | fatal_error
|
---|
| 354 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
|
---|
| 355 | }
|
---|
| 356 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 357 | log_to_screen
|
---|
[1191] | 358 | (_("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."));
|
---|
[116] | 359 | }
|
---|
| 360 |
|
---|
| 361 | if (system("which cdrecord > /dev/null 2> /dev/null")
|
---|
| 362 | && system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 363 | fatal_error
|
---|
| 364 | ("Please install dvdrecord/cdrecord and try again.");
|
---|
| 365 | }
|
---|
| 366 | if (flag_set['C']) {
|
---|
| 367 | bkpinfo->cdrw_speed = atoi(flag_val['C']);
|
---|
| 368 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 369 | fatal_error
|
---|
| 370 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 371 | }
|
---|
| 372 | if (!flag_set['L']) {
|
---|
| 373 | log_to_screen
|
---|
[1191] | 374 | (_("You must use -L with -C. Therefore I am setting it for you."));
|
---|
[116] | 375 | flag_set['L'] = 1;
|
---|
| 376 | flag_val['L'][0] = '\0';
|
---|
| 377 | }
|
---|
| 378 | } else {
|
---|
[1108] | 379 | mr_msg(3, "flag_val['c'] = %s", flag_val['c']);
|
---|
| 380 | mr_msg(3, "flag_val['w'] = %s", flag_val['w']);
|
---|
[116] | 381 | if (flag_set['c']) {
|
---|
| 382 | bkpinfo->cdrw_speed = atoi(flag_val['c']);
|
---|
| 383 | } else if (flag_set['w']) {
|
---|
| 384 | bkpinfo->cdrw_speed = atoi(flag_val['w']);
|
---|
| 385 | } else if (flag_set['r']) {
|
---|
| 386 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 390 | fatal_error
|
---|
| 391 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
[1] | 394 | }
|
---|
[1191] | 395 |
|
---|
[116] | 396 | if (flag_set['t'] && !flag_set['d']) {
|
---|
| 397 | log_it("Hmm! No tape drive specified. Let's see what we can do.");
|
---|
| 398 | if (find_tape_device_and_size(flag_val['d'], tmp)) {
|
---|
| 399 | fatal_error
|
---|
| 400 | ("Tape device not specified. I couldn't find it either.");
|
---|
| 401 | }
|
---|
| 402 | flag_set['d'] = TRUE;
|
---|
[1191] | 403 | mr_asprintf(&tmp2,
|
---|
| 404 | _("You didn't specify a tape streamer device. I'm assuming %s"),
|
---|
[116] | 405 | flag_val['d']);
|
---|
[1191] | 406 | log_to_screen(tmp2);
|
---|
| 407 | mr_free(tmp2);
|
---|
[116] | 408 | percent = 0;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
[1063] | 411 | if (flag_set['U']) // USB
|
---|
| 412 | {
|
---|
| 413 | if (! flag_set['d']) {
|
---|
| 414 | fatal_error
|
---|
| 415 | ("You need to specify a device file with -d for bootable USB device creation");
|
---|
| 416 | }
|
---|
| 417 | if (!flag_set['s']) {
|
---|
| 418 | fatal_error("You did not specify a size (-s) for your USB device. Aborting");
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 |
|
---|
[116] | 422 | if (flag_set['r']) // DVD
|
---|
| 423 | {
|
---|
| 424 | if (flag_set['m']) {
|
---|
| 425 | fatal_error
|
---|
| 426 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
|
---|
| 427 | }
|
---|
| 428 | if (!flag_set['d']) {
|
---|
| 429 | if (!find_dvd_device(flag_val['d'], FALSE)) {
|
---|
| 430 | flag_set['d'] = TRUE;
|
---|
[1191] | 431 | log_to_screen(_("I guess DVD drive is at %s"), flag_val['d']);
|
---|
[116] | 432 | }
|
---|
| 433 | }
|
---|
| 434 | if (!find_home_of_exe("growisofs")) {
|
---|
| 435 | fatal_error
|
---|
| 436 | ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 437 | }
|
---|
| 438 | if (!find_home_of_exe("dvd+rw-format")) {
|
---|
| 439 | fatal_error
|
---|
| 440 | ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 441 | }
|
---|
| 442 | if (strchr(flag_val['d'], ',')) {
|
---|
| 443 | fatal_error
|
---|
| 444 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 445 | }
|
---|
| 446 | if (!flag_set['s']) {
|
---|
| 447 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
|
---|
| 448 | strcat(flag_val['s'], "m");
|
---|
| 449 | log_to_screen
|
---|
[1191] | 450 | (_("You did not specify a size (-s) for DVD. I'm guessing %s."),
|
---|
[116] | 451 | flag_val['s']);
|
---|
| 452 | flag_set['s'] = 1;
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
[1] | 455 |
|
---|
[116] | 456 | if (flag_set['t'] || flag_set['u']) { /* tape size */
|
---|
| 457 | if (strchr(flag_val['d'], ',')) {
|
---|
| 458 | fatal_error
|
---|
| 459 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 460 | }
|
---|
| 461 | if (flag_set['O']) {
|
---|
| 462 | if (flag_set['s']) {
|
---|
| 463 | if (flag_set['t']) {
|
---|
| 464 | fatal_error
|
---|
| 465 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
|
---|
| 466 | }
|
---|
| 467 | if (process_the_s_switch(bkpinfo, flag_val['s'])) {
|
---|
| 468 | fatal_error("Bad -s switch");
|
---|
| 469 | }
|
---|
| 470 | } else if (flag_set['u'] || flag_set['t']) {
|
---|
| 471 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 472 | bkpinfo->media_size[i] = 0;
|
---|
| 473 | }
|
---|
| 474 | } else {
|
---|
| 475 | retval++;
|
---|
| 476 | log_to_screen("Tape size not specified.\n");
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
[1063] | 479 | } else { /* CD|USB size */
|
---|
[116] | 480 | if (flag_set['s']) {
|
---|
| 481 | if (process_the_s_switch(bkpinfo, flag_val['s'])) {
|
---|
| 482 | fatal_error("Bad -s switch");
|
---|
| 483 | }
|
---|
| 484 | }
|
---|
| 485 | if (flag_set['w']) {
|
---|
| 486 | bkpinfo->wipe_media_first = TRUE;
|
---|
| 487 | } /* CD-RW */
|
---|
[1] | 488 | }
|
---|
[116] | 489 | if (flag_set['n']) {
|
---|
| 490 | strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
|
---|
| 491 | if (!flag_set['d']) {
|
---|
| 492 | strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
|
---|
| 493 | }
|
---|
[1191] | 494 | mr_asprintf(&tmp2, "mount | grep -E '^%s .*$' | cut -d' ' -f3",
|
---|
[116] | 495 | bkpinfo->nfs_mount);
|
---|
| 496 | strncpy(bkpinfo->isodir,
|
---|
[1191] | 497 | call_program_and_get_last_line_of_output(tmp2),
|
---|
[116] | 498 | MAX_STR_LEN / 4);
|
---|
[1191] | 499 | mr_free(tmp2);
|
---|
[116] | 500 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
| 501 | retval++;
|
---|
[1191] | 502 | log_to_screen(_("NFS share is not mounted. Please mount it.\n"));
|
---|
[116] | 503 | }
|
---|
[1108] | 504 | mr_msg(3, "mount = %s", bkpinfo->nfs_mount);
|
---|
| 505 | mr_msg(3, "isodir= %s", bkpinfo->isodir);
|
---|
[1] | 506 | }
|
---|
[1191] | 507 |
|
---|
[116] | 508 | if (flag_set['c']) {
|
---|
| 509 | bkpinfo->backup_media_type = cdr;
|
---|
[1] | 510 | }
|
---|
[116] | 511 | if (flag_set['C']) {
|
---|
| 512 | bkpinfo->backup_media_type = cdstream;
|
---|
[1] | 513 | }
|
---|
[116] | 514 | if (flag_set['i']) {
|
---|
| 515 | bkpinfo->backup_media_type = iso;
|
---|
| 516 | }
|
---|
| 517 | if (flag_set['n']) {
|
---|
| 518 | bkpinfo->backup_media_type = nfs;
|
---|
| 519 | }
|
---|
| 520 | if (flag_set['r']) {
|
---|
| 521 | bkpinfo->backup_media_type = dvd;
|
---|
| 522 | }
|
---|
| 523 | if (flag_set['t']) {
|
---|
| 524 | bkpinfo->backup_media_type = tape;
|
---|
| 525 | }
|
---|
| 526 | if (flag_set['u']) {
|
---|
| 527 | bkpinfo->backup_media_type = udev;
|
---|
| 528 | }
|
---|
| 529 | if (flag_set['w']) {
|
---|
| 530 | bkpinfo->backup_media_type = cdrw;
|
---|
| 531 | }
|
---|
[1063] | 532 | if (flag_set['U']) {
|
---|
| 533 | bkpinfo->backup_media_type = usb;
|
---|
| 534 | }
|
---|
[948] | 535 | if (flag_set['z']) {
|
---|
| 536 | if (find_home_of_exe("getfattr")) {
|
---|
[1080] | 537 | mr_asprintf(&g_getfattr,"getfattr");
|
---|
[948] | 538 | }
|
---|
| 539 | if (find_home_of_exe("getfacl")) {
|
---|
[1080] | 540 | mr_asprintf(&g_getfacl,"getfacl");
|
---|
[948] | 541 | }
|
---|
| 542 | }
|
---|
[1] | 543 |
|
---|
[805] | 544 | /* optional, popular */
|
---|
[116] | 545 | if (flag_set['g']) {
|
---|
| 546 | g_text_mode = FALSE;
|
---|
| 547 | }
|
---|
[805] | 548 |
|
---|
[116] | 549 | if (flag_set['E']) {
|
---|
| 550 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 551 | strcat(bkpinfo->exclude_paths, " ");
|
---|
| 552 | }
|
---|
[1080] | 553 | mr_asprintf(&tmp1, flag_val['E']);
|
---|
[605] | 554 | p = tmp1;
|
---|
| 555 | q = tmp1;
|
---|
[542] | 556 |
|
---|
| 557 | /* Cut the flag_val['E'] in parts containing all paths to test them */
|
---|
| 558 | while (p != NULL) {
|
---|
| 559 | q = strchr(p, ' ');
|
---|
| 560 | if (q != NULL) {
|
---|
| 561 | *q = '\0';
|
---|
[805] | 562 | /* Fix bug 14 where ending / cause a problem later
|
---|
| 563 | * so handled here for the moment */
|
---|
| 564 | q--;
|
---|
[809] | 565 | if (*q == '/') {
|
---|
[805] | 566 | *q = '\0';
|
---|
| 567 | }
|
---|
| 568 | q++;
|
---|
| 569 | /* End of bug fix */
|
---|
[542] | 570 | if (stat(p, &buf) != 0) {
|
---|
[1108] | 571 | mr_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
[542] | 572 | }
|
---|
[633] | 573 | p = q+1 ;
|
---|
[542] | 574 | } else {
|
---|
| 575 | if (stat(p, &buf) != 0) {
|
---|
[1108] | 576 | mr_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
[542] | 577 | }
|
---|
| 578 | p = NULL;
|
---|
| 579 | }
|
---|
[289] | 580 | }
|
---|
[1080] | 581 | mr_free(tmp1);
|
---|
[542] | 582 |
|
---|
[116] | 583 | strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
|
---|
| 584 | flag_val['E'],
|
---|
[543] | 585 | 4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
|
---|
[116] | 586 | }
|
---|
| 587 | if (flag_set['e']) {
|
---|
| 588 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 589 | }
|
---|
| 590 | if (flag_set['N']) // exclude NFS mounts & devices
|
---|
| 591 | {
|
---|
[1191] | 592 | mr_asprintf(&psz, list_of_NFS_mounts_only());
|
---|
[116] | 593 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 594 | strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN);
|
---|
| 595 | }
|
---|
| 596 | strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN);
|
---|
[1191] | 597 | mr_free(psz);
|
---|
[1108] | 598 | mr_msg(3, "-N means we're now excluding %s",
|
---|
[116] | 599 | bkpinfo->exclude_paths);
|
---|
| 600 | }
|
---|
| 601 | if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) {
|
---|
| 602 | fatal_error
|
---|
| 603 | ("Your '-E' parameter is too long. Please use '-J'. (See manual.)");
|
---|
| 604 | }
|
---|
| 605 | if (flag_set['b']) {
|
---|
[1191] | 606 | mr_asprintf(&psz, flag_val['b']);
|
---|
[1108] | 607 | mr_msg(1, "psz = '%s'", psz);
|
---|
[116] | 608 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
| 609 | psz[strlen(psz) - 1] = '\0';
|
---|
| 610 | itbs = atol(psz) * 1024L;
|
---|
| 611 | } else {
|
---|
| 612 | itbs = atol(psz);
|
---|
| 613 | }
|
---|
[1191] | 614 | mr_free(psz);
|
---|
| 615 |
|
---|
[1108] | 616 | mr_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
| 617 | mr_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
[116] | 618 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
| 619 | fatal_error
|
---|
| 620 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
| 621 | }
|
---|
| 622 | bkpinfo->internal_tape_block_size = itbs;
|
---|
| 623 | }
|
---|
[1191] | 624 |
|
---|
[116] | 625 | if (flag_set['D']) {
|
---|
| 626 | bkpinfo->differential = 1;
|
---|
[1] | 627 | // bkpinfo->differential = atoi (flag_val['D']);
|
---|
[116] | 628 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
|
---|
| 629 | fatal_error
|
---|
| 630 | ("The D option should be between 1 and 9 inclusive");
|
---|
| 631 | }
|
---|
[1] | 632 | }
|
---|
[1191] | 633 |
|
---|
[116] | 634 | if (flag_set['x']) {
|
---|
| 635 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
|
---|
[296] | 636 | if (run_program_and_log_output("which ntfsclone", 2)) {
|
---|
| 637 | fatal_error("Please install ntfsprogs package/tarball.");
|
---|
[116] | 638 | }
|
---|
[1] | 639 | }
|
---|
[116] | 640 | if (flag_set['m']) {
|
---|
| 641 | bkpinfo->manual_cd_tray = TRUE;
|
---|
[1] | 642 | }
|
---|
[116] | 643 | if (flag_set['k']) {
|
---|
| 644 | strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
|
---|
| 645 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
| 646 | strcpy(bkpinfo->kernel_path, "FAILSAFE");
|
---|
| 647 | }
|
---|
| 648 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
|
---|
| 649 | && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
| 650 | retval++;
|
---|
[1191] | 651 | mr_asprintf(&tmp2,
|
---|
| 652 | _("You specified kernel '%s', which does not exist\n"),
|
---|
[116] | 653 | bkpinfo->kernel_path);
|
---|
[1191] | 654 | log_to_screen(tmp2);
|
---|
| 655 | mr_free(tmp2);
|
---|
[116] | 656 | }
|
---|
| 657 | }
|
---|
[1191] | 658 |
|
---|
[116] | 659 | if (flag_set['p']) {
|
---|
| 660 | strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
|
---|
| 661 | }
|
---|
[1] | 662 |
|
---|
[1063] | 663 | if (flag_set['d']) { /* backup directory (if ISO/NFS/USB) */
|
---|
[116] | 664 | if (flag_set['i']) {
|
---|
| 665 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
|
---|
[1191] | 666 | mr_asprintf(&tmp2, "ls -l %s", bkpinfo->isodir);
|
---|
| 667 | if (run_program_and_log_output(tmp2, FALSE)) {
|
---|
[116] | 668 | fatal_error
|
---|
| 669 | ("output folder does not exist - please create it");
|
---|
| 670 | }
|
---|
[1191] | 671 | mr_free(tmp2);
|
---|
[116] | 672 | } else if (flag_set['n']) {
|
---|
| 673 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
|
---|
| 674 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
| 675 | strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 676 | }
|
---|
[1] | 677 | }
|
---|
[116] | 678 |
|
---|
| 679 | if (flag_set['n']) {
|
---|
[1191] | 680 | mr_asprintf(&tmp2, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
|
---|
[116] | 681 | bkpinfo->nfs_remote_dir);
|
---|
[1191] | 682 | if (run_program_and_log_output(tmp2, FALSE)) {
|
---|
[116] | 683 | retval++;
|
---|
[1191] | 684 | mr_free(tmp2);
|
---|
| 685 | mr_asprintf(&tmp2,
|
---|
| 686 | _("Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n"),
|
---|
[116] | 687 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
[1191] | 688 | log_to_screen(tmp2);
|
---|
[116] | 689 | }
|
---|
[1191] | 690 | mr_free(tmp2);
|
---|
[1] | 691 | }
|
---|
| 692 |
|
---|
[116] | 693 | if (!flag_set['d']
|
---|
[1063] | 694 | && (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['U'])) {
|
---|
[116] | 695 | if (g_kernel_version >= 2.6) {
|
---|
| 696 | if (popup_and_get_string
|
---|
[1191] | 697 | (_("Device"), _("Please specify the device"),
|
---|
[116] | 698 | bkpinfo->media_device, MAX_STR_LEN / 4)) {
|
---|
| 699 | retval++;
|
---|
[1191] | 700 | log_to_screen(_("User opted to cancel."));
|
---|
[116] | 701 | }
|
---|
| 702 | } else if (find_cdrw_device(bkpinfo->media_device)) {
|
---|
| 703 | retval++;
|
---|
| 704 | log_to_screen
|
---|
[1191] | 705 | (_("Tried and failed to find CD-R[W] drive automatically.\n"));
|
---|
[116] | 706 | } else {
|
---|
| 707 | flag_set['d'] = TRUE;
|
---|
| 708 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
| 709 | }
|
---|
[1] | 710 | }
|
---|
| 711 |
|
---|
[116] | 712 | if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) {
|
---|
| 713 | retval++;
|
---|
[1191] | 714 | log_to_screen(_("Please specify the backup device/directory.\n"));
|
---|
[116] | 715 | fatal_error
|
---|
| 716 | ("You didn't use -d to specify the backup device/directory.");
|
---|
[1] | 717 | }
|
---|
[116] | 718 | /* optional, obscure */
|
---|
| 719 | for (i = '0'; i <= '9'; i++) {
|
---|
| 720 | if (flag_set[i]) {
|
---|
| 721 | bkpinfo->compression_level = i - '0';
|
---|
| 722 | } /* not '\0' but '0' */
|
---|
[1] | 723 | }
|
---|
[116] | 724 | if (flag_set['S']) {
|
---|
| 725 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
|
---|
| 726 | random() % 32768);
|
---|
[1] | 727 | }
|
---|
[116] | 728 | if (flag_set['T']) {
|
---|
| 729 | sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],
|
---|
| 730 | random() % 32768);
|
---|
[1191] | 731 | mr_asprintf(&tmp2, "touch %s/.foo.dat", flag_val['T']);
|
---|
| 732 | if (run_program_and_log_output(tmp2, 1)) {
|
---|
[116] | 733 | retval++;
|
---|
| 734 | log_to_screen
|
---|
[1191] | 735 | (_("Please specify a tempdir which I can write to. :)"));
|
---|
[116] | 736 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 737 | }
|
---|
[1191] | 738 | mr_free(tmp2);
|
---|
| 739 |
|
---|
| 740 | mr_asprintf(&tmp2, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'],
|
---|
[116] | 741 | flag_val['T']);
|
---|
[1191] | 742 | if (run_program_and_log_output(tmp2, 1)) {
|
---|
[116] | 743 | retval++;
|
---|
| 744 | log_to_screen
|
---|
[1191] | 745 | (_("Please don't specify a SAMBA or VFAT or NFS tmpdir."));
|
---|
[116] | 746 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 747 | }
|
---|
[1191] | 748 | mr_free(tmp2);
|
---|
[1] | 749 | }
|
---|
[1191] | 750 |
|
---|
[116] | 751 | if (flag_set['A']) {
|
---|
| 752 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
|
---|
| 753 | }
|
---|
| 754 | if (flag_set['B']) {
|
---|
| 755 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
|
---|
| 756 | }
|
---|
| 757 | if (flag_set['F']) {
|
---|
| 758 | g_skip_floppies = TRUE;
|
---|
| 759 | }
|
---|
| 760 | if (flag_set['H']) {
|
---|
| 761 | g_cd_recovery = TRUE;
|
---|
| 762 | }
|
---|
| 763 | if (flag_set['l']) {
|
---|
[1] | 764 | #ifdef __FreeBSD__
|
---|
| 765 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
| 766 | #else
|
---|
| 767 | # ifdef __IA64__
|
---|
| 768 | # define BOOT_LOADER_CHARS "GER"
|
---|
| 769 | # else
|
---|
| 770 | # define BOOT_LOADER_CHARS "GLR"
|
---|
| 771 | # endif
|
---|
| 772 | #endif
|
---|
[116] | 773 | if (!strchr
|
---|
| 774 | (BOOT_LOADER_CHARS,
|
---|
| 775 | (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
[1191] | 776 | mr_msg(1, "%c? What is %c? I need G, L, E or R.",
|
---|
[116] | 777 | bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
| 778 | fatal_error
|
---|
| 779 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
| 780 | }
|
---|
[1] | 781 | #undef BOOT_LOADER_CHARS
|
---|
| 782 | }
|
---|
[1191] | 783 |
|
---|
[116] | 784 | if (flag_set['f']) {
|
---|
| 785 | strncpy(bkpinfo->boot_device,
|
---|
| 786 | resolve_softlinks_to_get_to_actual_device_file(flag_val
|
---|
| 787 | ['f']),
|
---|
| 788 | MAX_STR_LEN / 4);
|
---|
| 789 | }
|
---|
[1191] | 790 |
|
---|
| 791 | if (flag_set['Q']) {
|
---|
| 792 | if (bkpinfo->boot_device == NULL) {
|
---|
| 793 | fatal_error("-f option required when using -Q\n");
|
---|
| 794 | }
|
---|
| 795 | i = which_boot_loader(bkpinfo->boot_device);
|
---|
| 796 | mr_msg(3, "boot loader is %c, residing at %s", i, bkpinfo->boot_device);
|
---|
| 797 | log_to_screen(_("boot loader is %c, residing at %s\n"), i, tmp);
|
---|
| 798 | finish(0);
|
---|
| 799 | }
|
---|
| 800 |
|
---|
[116] | 801 | if (flag_set['P']) {
|
---|
| 802 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
|
---|
| 803 | }
|
---|
[1191] | 804 |
|
---|
[116] | 805 | if (flag_set['L']) {
|
---|
| 806 | bkpinfo->use_lzo = TRUE;
|
---|
| 807 | if (run_program_and_log_output("which lzop", FALSE)) {
|
---|
| 808 | retval++;
|
---|
| 809 | log_to_screen
|
---|
[1191] | 810 | (_("Please install LZOP. You can't use '-L' until you do.\n"));
|
---|
[116] | 811 | }
|
---|
| 812 | }
|
---|
[1] | 813 |
|
---|
[998] | 814 | if (flag_set['G']) {
|
---|
| 815 | bkpinfo->use_gzip = TRUE;
|
---|
| 816 | if (run_program_and_log_output("which gzip", FALSE)) {
|
---|
| 817 | retval++;
|
---|
| 818 | log_to_screen
|
---|
| 819 | ("Please install gzip. You can't use '-G' until you do.\n");
|
---|
| 820 | }
|
---|
| 821 | }
|
---|
| 822 |
|
---|
[116] | 823 | if (!flag_set['o']
|
---|
| 824 | &&
|
---|
| 825 | !run_program_and_log_output
|
---|
[681] | 826 | ("grep -Ei suse /etc/issue.net | grep -E '9.0' | grep 64", TRUE)) {
|
---|
[116] | 827 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 828 | log_to_screen
|
---|
[1191] | 829 | (_("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."));
|
---|
[116] | 830 | }
|
---|
[1191] | 831 |
|
---|
[116] | 832 | if (flag_set['o']) {
|
---|
| 833 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 834 | }
|
---|
[1] | 835 | #ifndef __FreeBSD__
|
---|
[116] | 836 | else {
|
---|
| 837 | if (!is_this_a_valid_disk_format("vfat")) {
|
---|
| 838 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 839 | log_to_screen
|
---|
[1191] | 840 | (_("Your kernel appears not to support vfat filesystems. I am therefore"));
|
---|
[116] | 841 | log_to_screen
|
---|
[1191] | 842 | (_("using LILO instead of SYSLINUX as the CD/floppy's boot loader."));
|
---|
[116] | 843 | }
|
---|
| 844 | if (run_program_and_log_output("which mkfs.vfat", FALSE)) {
|
---|
| 845 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 846 | #ifdef __IA32__
|
---|
[116] | 847 | log_to_screen
|
---|
[1191] | 848 | (_("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"));
|
---|
[116] | 849 | log_to_screen
|
---|
[1191] | 850 | (_("your boot loader. I shall therefore use LILO instead."));
|
---|
[1] | 851 | #endif
|
---|
| 852 | #ifdef __IA64__
|
---|
[116] | 853 | log_to_screen
|
---|
[1191] | 854 | (_("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"));
|
---|
| 855 | log_to_screen(_("environment correctly. Please install it."));
|
---|
[116] | 856 | fatal_error("Aborting");
|
---|
[1] | 857 | #endif
|
---|
[116] | 858 | }
|
---|
[1] | 859 | #ifdef __IA64__
|
---|
[116] | 860 | /* We force ELILO usage on IA64 */
|
---|
| 861 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 862 | #endif
|
---|
[116] | 863 | }
|
---|
[1] | 864 | #endif
|
---|
| 865 |
|
---|
[116] | 866 | if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
|
---|
| 867 | paranoid_system("touch /boot/boot.b");
|
---|
| 868 | }
|
---|
[1] | 869 |
|
---|
[116] | 870 | i = flag_set['O'] + flag_set['V'];
|
---|
| 871 | if (i == 0) {
|
---|
| 872 | retval++;
|
---|
[1191] | 873 | log_to_screen(_("Specify backup (-O), verify (-V) or both (-OV).\n"));
|
---|
[116] | 874 | }
|
---|
[1] | 875 |
|
---|
| 876 | /* and finally... */
|
---|
| 877 |
|
---|
[1080] | 878 | mr_free(tmp);
|
---|
[116] | 879 | return (retval);
|
---|
[1] | 880 | }
|
---|
| 881 |
|
---|
| 882 |
|
---|
| 883 | /**
|
---|
| 884 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
| 885 | * @p flag_set and @p flag_val.
|
---|
| 886 | * @param argc The argument count (@p argc passed to main()).
|
---|
| 887 | * @param argv The argument vector (@p argv passed to main()).
|
---|
| 888 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
| 889 | * has an argument then set flag_val[switch] to that argument.
|
---|
| 890 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
| 891 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
| 892 | * @return The number of problems with the command line (0 for success).
|
---|
| 893 | */
|
---|
| 894 | int
|
---|
[116] | 895 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
| 896 | char flag_val[128][MAX_STR_LEN],
|
---|
| 897 | bool flag_set[128])
|
---|
[1] | 898 | {
|
---|
[116] | 899 | /*@ ints ** */
|
---|
| 900 | int opt = 0;
|
---|
[1191] | 901 | char *tmp = NULL;
|
---|
[116] | 902 | int i = 0;
|
---|
[1191] | 903 | int len = 0;
|
---|
[1] | 904 |
|
---|
[116] | 905 | /*@ bools *** */
|
---|
| 906 | bool bad_switches = FALSE;
|
---|
[1] | 907 |
|
---|
[116] | 908 | assert(flag_val != NULL);
|
---|
| 909 | assert(flag_set != NULL);
|
---|
[1] | 910 |
|
---|
[116] | 911 | for (i = 0; i < 128; i++) {
|
---|
| 912 | flag_val[i][0] = '\0';
|
---|
| 913 | flag_set[i] = FALSE;
|
---|
[1] | 914 | }
|
---|
[116] | 915 | while ((opt =
|
---|
| 916 | getopt(argc, argv,
|
---|
[1063] | 917 | "0123456789A:B:C:DE:FGHI:J:K:LNOP:QRS:T:UVWb:c:d:ef:gik:l:mn:op:rs:tuw:x:z"))
|
---|
[116] | 918 | != -1) {
|
---|
| 919 | if (opt == '?') {
|
---|
| 920 | bad_switches = TRUE;
|
---|
| 921 | /*log_it("Invalid option: %c\n",optopt); */
|
---|
| 922 | } else {
|
---|
| 923 | if (flag_set[optopt]) {
|
---|
| 924 | bad_switches = TRUE;
|
---|
[1191] | 925 | mr_asprintf(&tmp, _("Switch -%c previously defined as %s\n"), opt,
|
---|
[116] | 926 | flag_val[i]);
|
---|
| 927 | log_to_screen(tmp);
|
---|
[1191] | 928 | mr_free(tmp);
|
---|
[116] | 929 | } else {
|
---|
| 930 | flag_set[opt] = TRUE;
|
---|
| 931 | if (optarg) {
|
---|
| 932 | len = strlen(optarg);
|
---|
| 933 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
| 934 | optarg[--len] = '\0';
|
---|
| 935 | log_to_screen
|
---|
[1191] | 936 | (_("Warning - param '%s' should not have trailing slash!"),
|
---|
[116] | 937 | optarg);
|
---|
| 938 | }
|
---|
| 939 | if (opt == 'd') {
|
---|
| 940 | if (strchr(flag_val[opt], '/')
|
---|
| 941 | && flag_val[opt][0] != '/') {
|
---|
[1191] | 942 | mr_asprintf(&tmp,
|
---|
| 943 | _("-%c flag --- must be absolute path --- '%s' isn't absolute"),
|
---|
[116] | 944 | opt, flag_val[opt]);
|
---|
| 945 | log_to_screen(tmp);
|
---|
[1191] | 946 | mr_free(tmp);
|
---|
[116] | 947 | bad_switches = TRUE;
|
---|
| 948 | }
|
---|
| 949 | }
|
---|
| 950 | strcpy(flag_val[opt], optarg);
|
---|
| 951 | }
|
---|
| 952 | }
|
---|
[1] | 953 | }
|
---|
| 954 | }
|
---|
[116] | 955 | for (i = optind; i < argc; i++) {
|
---|
| 956 | bad_switches = TRUE;
|
---|
[1191] | 957 | mr_asprintf(&tmp, _("Invalid arg -- %s\n"), argv[i]);
|
---|
[116] | 958 | log_to_screen(tmp);
|
---|
[1191] | 959 | mr_free(tmp);
|
---|
[116] | 960 | }
|
---|
| 961 | return (bad_switches);
|
---|
[1] | 962 | }
|
---|
| 963 |
|
---|
| 964 |
|
---|
| 965 | /**
|
---|
| 966 | * Print a not-so-helpful help message and exit.
|
---|
| 967 | */
|
---|
[1164] | 968 | void help_screen(void)
|
---|
[1] | 969 | {
|
---|
[1108] | 970 | mr_msg(1, "Type 'man mondo-archive' for more information\n");
|
---|
[116] | 971 | exit(1);
|
---|
[1] | 972 | }
|
---|
| 973 |
|
---|
| 974 |
|
---|
| 975 | /**
|
---|
| 976 | * Terminate Mondo in response to a signal.
|
---|
| 977 | * @param sig The signal number received.
|
---|
| 978 | */
|
---|
| 979 | void terminate_daemon(int sig)
|
---|
| 980 | {
|
---|
[1191] | 981 | char *tmp = NULL;
|
---|
| 982 | char *tmp2 = NULL;
|
---|
[1] | 983 |
|
---|
[116] | 984 | switch (sig) {
|
---|
[1] | 985 | case SIGINT:
|
---|
[1191] | 986 | mr_asprintf(&tmp, _("SIGINT signal received from OS"));
|
---|
| 987 | mr_asprintf(&tmp2, _("You interrupted me :-)"));
|
---|
[1] | 988 | break;
|
---|
| 989 | case SIGKILL:
|
---|
[1191] | 990 | mr_asprintf(&tmp, _("SIGKILL signal received from OS"));
|
---|
| 991 | mr_asprintf(&tmp2,
|
---|
| 992 | _("I seriously have no clue how this signal even got to me. Something's wrong with your system."));
|
---|
[1] | 993 | break;
|
---|
| 994 | case SIGTERM:
|
---|
[1191] | 995 | mr_asprintf(&tmp, _("SIGTERM signal received from OS"));
|
---|
| 996 | mr_asprintf(&tmp2, _("Got terminate signal"));
|
---|
[1] | 997 | break;
|
---|
| 998 | case SIGHUP:
|
---|
[1191] | 999 | mr_asprintf(&tmp, _("SIGHUP signal received from OS"));
|
---|
| 1000 | mr_asprintf(&tmp2, _("Hangup on line"));
|
---|
[1] | 1001 | break;
|
---|
| 1002 | case SIGSEGV:
|
---|
[1191] | 1003 | mr_asprintf(&tmp, _("SIGSEGV signal received from OS"));
|
---|
| 1004 | mr_asprintf(&tmp2,
|
---|
| 1005 | _("Internal programming error. Please send a backtrace as well as your log."));
|
---|
[1] | 1006 | break;
|
---|
| 1007 | case SIGPIPE:
|
---|
[1191] | 1008 | mr_asprintf(&tmp, _("SIGPIPE signal received from OS"));
|
---|
| 1009 | mr_asprintf(&tmp2, _("Pipe was broken"));
|
---|
[1] | 1010 | break;
|
---|
[116] | 1011 | case SIGABRT:
|
---|
[1191] | 1012 | mr_asprintf(&tmp, _("SIGABRT signal received from OS"));
|
---|
| 1013 | mr_asprintf(&tmp2,
|
---|
| 1014 | _("Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."));
|
---|
[116] | 1015 | break;
|
---|
[1] | 1016 | default:
|
---|
[1191] | 1017 | mr_asprintf(&tmp, _("(Unknown)"));
|
---|
| 1018 | mr_asprintf(&tmp2, _("(Unknown)"));
|
---|
[116] | 1019 | }
|
---|
[1] | 1020 |
|
---|
[116] | 1021 | log_to_screen(tmp);
|
---|
| 1022 | log_to_screen(tmp2);
|
---|
[1191] | 1023 | mr_free(tmp);
|
---|
| 1024 | mr_free(tmp2);
|
---|
[116] | 1025 | if (sig == SIGABRT) {
|
---|
| 1026 | sleep(10);
|
---|
| 1027 | }
|
---|
| 1028 | kill_buffer();
|
---|
| 1029 | fatal_error
|
---|
| 1030 | ("Mondoarchive is terminating in response to a signal from the OS");
|
---|
| 1031 | finish(254); // just in case
|
---|
[1] | 1032 | }
|
---|
| 1033 |
|
---|
| 1034 |
|
---|
| 1035 | /**
|
---|
| 1036 | * Turn signal-trapping on or off.
|
---|
| 1037 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
| 1038 | */
|
---|
| 1039 | void set_signals(int on)
|
---|
| 1040 | {
|
---|
[116] | 1041 | int signals[] =
|
---|
| 1042 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
| 1043 | int i;
|
---|
| 1044 |
|
---|
| 1045 | signal(SIGPIPE, sigpipe_occurred);
|
---|
| 1046 | for (i = 0; signals[i]; i++) {
|
---|
| 1047 | if (on) {
|
---|
| 1048 | signal(signals[i], terminate_daemon);
|
---|
| 1049 | } else {
|
---|
| 1050 | signal(signals[i], termination_in_progress);
|
---|
| 1051 | }
|
---|
| 1052 | }
|
---|
[1] | 1053 | }
|
---|
| 1054 |
|
---|
| 1055 |
|
---|
| 1056 | /**
|
---|
| 1057 | * Exit immediately without cleaning up.
|
---|
| 1058 | * @param sig The signal we are exiting due to.
|
---|
| 1059 | */
|
---|
| 1060 | void termination_in_progress(int sig)
|
---|
| 1061 | {
|
---|
[1108] | 1062 | mr_msg(1, "Termination in progress");
|
---|
[116] | 1063 | usleep(1000);
|
---|
| 1064 | pthread_exit(0);
|
---|
[1] | 1065 | }
|
---|
| 1066 |
|
---|
| 1067 | /* @} - end of cliGroup */
|
---|