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