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