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