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