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