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