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