1 | /* $Id: libmondo-tools.c 1671 2007-10-01 12:12:54Z bruno $
|
---|
2 | misc tools
|
---|
3 | */
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * @file
|
---|
7 | * Miscellaneous tools that didn't really fit anywhere else.
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "my-stuff.h"
|
---|
11 | #include "mr_mem.h"
|
---|
12 | #include "mr_msg.h"
|
---|
13 | #include "mr_file.h"
|
---|
14 | #include "mr_gettext.h"
|
---|
15 | #include "mr_conf.h"
|
---|
16 |
|
---|
17 | #include "mondostructures.h"
|
---|
18 | #include "libmondo-tools.h"
|
---|
19 | #include "newt-specific-EXT.h"
|
---|
20 | #include "libmondo-files-EXT.h"
|
---|
21 | #include "libmondo-fork-EXT.h"
|
---|
22 | #include "libmondo-raid-EXT.h"
|
---|
23 | #include <sys/socket.h>
|
---|
24 | #include <netdb.h>
|
---|
25 | #include <stdlib.h>
|
---|
26 | #include <netinet/in.h>
|
---|
27 | #include <arpa/inet.h>
|
---|
28 | #include <sys/utsname.h>
|
---|
29 |
|
---|
30 | /*@unused@*/
|
---|
31 | //static char cvsid[] = "$Id: libmondo-tools.c 1671 2007-10-01 12:12:54Z bruno $";
|
---|
32 |
|
---|
33 | extern int g_tape_buffer_size_MB;
|
---|
34 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
35 | extern char *g_serial_string;
|
---|
36 | extern bool g_text_mode;
|
---|
37 | extern int g_currentY;
|
---|
38 | extern int g_current_media_number;
|
---|
39 | extern char *MONDO_LOGFILE;
|
---|
40 |
|
---|
41 | extern struct mr_ar_conf *mr_conf;
|
---|
42 |
|
---|
43 | /* Reference to global bkpinfo */
|
---|
44 | extern struct s_bkpinfo *bkpinfo;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @addtogroup globalGroup
|
---|
48 | * @{
|
---|
49 | */
|
---|
50 | bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
|
---|
51 | g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
|
---|
52 | bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
|
---|
53 | double g_kernel_version;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * The place where /boot is mounted. - Used locally only
|
---|
57 | */
|
---|
58 | static char *g_boot_mountpt = NULL;
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * The serial string (used to differentiate between backups) of the current backup.
|
---|
62 | */
|
---|
63 | char *g_serial_string = NULL;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * The location where tmpfs is mounted, or "" if it's not mounted.
|
---|
67 | */
|
---|
68 | char *g_tmpfs_mountpt = NULL;
|
---|
69 | char *g_magicdev_command = NULL;
|
---|
70 |
|
---|
71 | /* @} - end of globalGroup */
|
---|
72 |
|
---|
73 |
|
---|
74 | extern pid_t g_buffer_pid;
|
---|
75 | extern pid_t g_main_pid;
|
---|
76 |
|
---|
77 | extern t_bkptype g_backup_media_type;
|
---|
78 | extern char *g_backup_media_string;
|
---|
79 |
|
---|
80 | extern bool am_I_in_disaster_recovery_mode(void);
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * @addtogroup utilityGroup
|
---|
85 | * @{
|
---|
86 | */
|
---|
87 | /**
|
---|
88 | * Assertion handler. Prints a friendly message to the user,
|
---|
89 | * offering to ignore all, dump core, break to debugger,
|
---|
90 | * exit, or ignore. Intended to be used with an assert() macro.
|
---|
91 | *
|
---|
92 | * @param file The file in which the assertion triggered.
|
---|
93 | * @param function The function (@c __FUNCTION__) in which the assertion triggered.
|
---|
94 | * @param line The line number of the assert() statement.
|
---|
95 | * @param exp The expression that failed (as a string).
|
---|
96 | */
|
---|
97 | void _mondo_assert_fail(const char *file,
|
---|
98 | const char *function, int line, const char *exp)
|
---|
99 | {
|
---|
100 | static int ignoring_assertions = 0;
|
---|
101 | bool is_valid = TRUE;
|
---|
102 |
|
---|
103 | log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
|
---|
104 | function);
|
---|
105 | if (ignoring_assertions) {
|
---|
106 | log_it("Well, the user doesn't care...");
|
---|
107 | return;
|
---|
108 | }
|
---|
109 | #ifndef _XWIN
|
---|
110 | if (!g_text_mode)
|
---|
111 | newtSuspend();
|
---|
112 | #endif
|
---|
113 | printf(_("ASSERTION FAILED: `%s'\n"), exp);
|
---|
114 | printf(_("\tat %s:%d in %s\n\n"), file, line, function);
|
---|
115 | printf(_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
|
---|
116 | do {
|
---|
117 | is_valid = TRUE;
|
---|
118 | switch (toupper(getchar())) {
|
---|
119 | case 'A': // ignore (A)ll
|
---|
120 | ignoring_assertions = 1;
|
---|
121 | break;
|
---|
122 | case 'B': // a(B)ort
|
---|
123 | signal(SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
|
---|
124 | raise(SIGABRT);
|
---|
125 | break; /* "can't get here" */
|
---|
126 | case 'D': // (D)ebug, aka asm("int 3")
|
---|
127 | #ifdef __IA32__
|
---|
128 | __asm__ __volatile__("int $3"); // break to debugger
|
---|
129 | #endif
|
---|
130 | break;
|
---|
131 | case 'E': // (E)xit
|
---|
132 | fatal_error("Failed assertion -- see above for details");
|
---|
133 | break; /* "can't get here" */
|
---|
134 | case 'I': // (I)gnore
|
---|
135 | break;
|
---|
136 | /* These next two work as follows:
|
---|
137 | the `default' catches the user's invalid choice and says so;
|
---|
138 | the '\n' catches the newline on the end and prints the prompt again.
|
---|
139 | */
|
---|
140 | case '\n':
|
---|
141 | printf
|
---|
142 | (_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
|
---|
143 | break;
|
---|
144 | default:
|
---|
145 | is_valid = FALSE;
|
---|
146 | printf(_("Invalid choice.\n"));
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | } while (!is_valid);
|
---|
150 |
|
---|
151 | if (ignoring_assertions) {
|
---|
152 | log_it("Ignoring ALL assertions from now on.");
|
---|
153 | } else {
|
---|
154 | log_it("Ignoring assertion: %s", exp);
|
---|
155 | }
|
---|
156 |
|
---|
157 | getchar(); // skip \n
|
---|
158 |
|
---|
159 | #ifndef _XWIN
|
---|
160 | if (!g_text_mode)
|
---|
161 | newtResume();
|
---|
162 | #endif
|
---|
163 | }
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Clean's up users' KDE desktops.
|
---|
167 | * @bug Details about this function are unknown.
|
---|
168 | */
|
---|
169 | void clean_up_KDE_desktop_if_necessary(void)
|
---|
170 | {
|
---|
171 | char *tmp;
|
---|
172 |
|
---|
173 | mr_asprintf(&tmp,
|
---|
174 | "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
|
---|
175 | file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
|
---|
176 | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
|
---|
177 | else { print $0;};}' $file.old > $file ; fi ; done");
|
---|
178 | run_program_and_log_output(tmp, 5);
|
---|
179 | mr_free(tmp);
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Locate mondoarchive's home directory. Searches in /usr/share/mondo,
|
---|
185 | * /usr/local/share/mondo, /opt, or if all else fails, search /usr.
|
---|
186 | *
|
---|
187 | * @param home_sz String to store the home directory ("" if it could not be found).
|
---|
188 | * @return 0 for success, nonzero for failure.
|
---|
189 | */
|
---|
190 | int find_and_store_mondoarchives_home(char *home_sz)
|
---|
191 | {
|
---|
192 | assert(home_sz != NULL);
|
---|
193 | strcpy(home_sz, MONDO_SHARE);
|
---|
194 | return (0);
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | char *get_architecture(void) {
|
---|
199 | #ifdef __IA32__
|
---|
200 | # ifdef __X86_64__
|
---|
201 | return ("x86_64");
|
---|
202 | # else
|
---|
203 | return ("i386");
|
---|
204 | # endif
|
---|
205 | #endif
|
---|
206 | #ifdef __X86_64__
|
---|
207 | return ("x86_64");
|
---|
208 | #endif
|
---|
209 | #ifdef __IA64__
|
---|
210 | return ("ia64");
|
---|
211 | #endif
|
---|
212 | return ("unknown");
|
---|
213 | }
|
---|
214 |
|
---|
215 |
|
---|
216 | char *get_uname_m(void) {
|
---|
217 |
|
---|
218 | struct utsname utsn;
|
---|
219 | char *tmp = NULL;
|
---|
220 |
|
---|
221 | uname(&utsn);
|
---|
222 | mr_asprintf(&tmp, utsn.machine);
|
---|
223 | return (tmp);
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 | /* BERLIOS: Use uname instead */
|
---|
229 | double get_kernel_version(void)
|
---|
230 | {
|
---|
231 | char *p, tmp[200];
|
---|
232 | double d;
|
---|
233 | #ifdef __FreeBSD__
|
---|
234 | // JOSH - FIXME :)
|
---|
235 | d = 5.2; // :-)
|
---|
236 | #else
|
---|
237 | strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
|
---|
238 | p = strchr(tmp, '.');
|
---|
239 | if (p) {
|
---|
240 | p = strchr(++p, '.');
|
---|
241 | if (p) {
|
---|
242 | while (*p) {
|
---|
243 | *p = *(p + 1);
|
---|
244 | p++;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 | // mr_msg(1, "tmp = '%s'", tmp);
|
---|
249 | d = atof(tmp);
|
---|
250 | #endif
|
---|
251 | mr_msg(1, "g_kernel_version = %f", d);
|
---|
252 | return (d);
|
---|
253 | }
|
---|
254 |
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Get the current time.
|
---|
258 | * @return number of seconds since the epoch.
|
---|
259 | */
|
---|
260 | long get_time(void)
|
---|
261 | {
|
---|
262 | return (long) time((void *) 0);
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Initialize a RAID volume structure, setting fields to zero. The
|
---|
268 | * actual hard drive is unaffected.
|
---|
269 | *
|
---|
270 | * @param raidrec The RAID volume structure to initialize.
|
---|
271 | * @note This function is system dependent.
|
---|
272 | */
|
---|
273 | #ifdef __FreeBSD__
|
---|
274 | void initialize_raidrec(struct vinum_volume *raidrec)
|
---|
275 | {
|
---|
276 | int i, j;
|
---|
277 | raidrec->volname[0] = '\0';
|
---|
278 | raidrec->plexes = 0;
|
---|
279 | for (i = 0; i < 9; ++i) {
|
---|
280 | raidrec->plex[i].raidlevel = -1;
|
---|
281 | raidrec->plex[i].stripesize = 0;
|
---|
282 | raidrec->plex[i].subdisks = 0;
|
---|
283 | for (j = 0; j < 9; ++j) {
|
---|
284 | strcpy(raidrec->plex[i].sd[j].which_device, "");
|
---|
285 | }
|
---|
286 | }
|
---|
287 | }
|
---|
288 | #else
|
---|
289 | void initialize_raidrec(struct raid_device_record *raidrec)
|
---|
290 | {
|
---|
291 | assert(raidrec != NULL);
|
---|
292 | raidrec->raid_device[0] = '\0';
|
---|
293 | raidrec->raid_level = -9;
|
---|
294 | raidrec->persistent_superblock = 1;
|
---|
295 | raidrec->chunk_size = 64;
|
---|
296 | raidrec->parity = -1;
|
---|
297 | raidrec->data_disks.entries = 0;
|
---|
298 | raidrec->spare_disks.entries = 0;
|
---|
299 | raidrec->parity_disks.entries = 0;
|
---|
300 | raidrec->failed_disks.entries = 0;
|
---|
301 | raidrec->additional_vars.entries = 0;
|
---|
302 | }
|
---|
303 | #endif
|
---|
304 |
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Insert modules that Mondo requires.
|
---|
308 | * Currently inserts @c msdos, @c vfat, and @c loop for Linux;
|
---|
309 | * @c msdosfs and @c ext2fs for FreeBSD.
|
---|
310 | */
|
---|
311 | void insmod_crucial_modules(void)
|
---|
312 | {
|
---|
313 | #ifdef __FreeBSD__
|
---|
314 | system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
|
---|
315 | system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null");
|
---|
316 | #else
|
---|
317 | system("modprobe -a msdos vfat loop &> /dev/null");
|
---|
318 | #endif
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Finish configuring the backup information structure. Call this function
|
---|
324 | * to set the parameters that depend on those that can be given on the command
|
---|
325 | * line.
|
---|
326 | *
|
---|
327 | * @param bkpinfo The backup information structure. Fields modified/used:
|
---|
328 | * - Used: @c bkpinfo->backup_data
|
---|
329 | * - Used: @c bkpinfo->backup_media_type
|
---|
330 | * - Used: @c bkpinfo->writer_speed
|
---|
331 | * - Used: @c bkpinfo->compression_level
|
---|
332 | * - Used: @c bkpinfo->include_paths
|
---|
333 | * - Used: @c bkpinfo->prefix
|
---|
334 | * - Used: @c bkpinfo->isodir
|
---|
335 | * - Used: @c bkpinfo->manual_tray
|
---|
336 | * - Used: @c bkpinfo->make_cd_use_lilo
|
---|
337 | * - Used: @c bkpinfo->media_device
|
---|
338 | * - Used: @c bkpinfo->nfs_mount
|
---|
339 | * - Used: @c bkpinfo->nonbootable_backup
|
---|
340 | * - Used: @c bkpinfo->scratchdir
|
---|
341 | * - Used: @c bkpinfo->tmpdir
|
---|
342 | * - Used: @c bkpinfo->use_lzo
|
---|
343 | * - Modified: @c bkpinfo->call_before_iso
|
---|
344 | * - Modified: @c bkpinfo->call_make_iso
|
---|
345 | * - Modified: @c bkpinfo->optimal_set_size
|
---|
346 | * - Modified: @c bkpinfo->zip_exe
|
---|
347 | * - Modified: @c bkpinfo->zip_suffix
|
---|
348 | *
|
---|
349 | * @return number of errors, or 0 for success.
|
---|
350 | * @note Also creates directories that are specified in the @c bkpinfo structure but
|
---|
351 | * do not exist.
|
---|
352 | */
|
---|
353 | int post_param_configuration()
|
---|
354 | {
|
---|
355 | char *extra_cdrom_params = NULL;
|
---|
356 | char *mondo_mkisofs_sz = NULL;
|
---|
357 | char *command = NULL;
|
---|
358 | char *hostname = NULL;
|
---|
359 | char *ip_address = NULL;
|
---|
360 | int retval = 0;
|
---|
361 | long avm = 0;
|
---|
362 | char *colon = NULL;
|
---|
363 | char *tmp = NULL;
|
---|
364 | char *call_before_iso_user = NULL;
|
---|
365 | int rdsiz_MB;
|
---|
366 | char *iso_dev = NULL;
|
---|
367 | char *iso_mnt = NULL;
|
---|
368 | char *iso_tmp = NULL;
|
---|
369 | char *iso_path = NULL;
|
---|
370 | FILE *fd1 = NULL;
|
---|
371 |
|
---|
372 | assert(bkpinfo != NULL);
|
---|
373 | bkpinfo->optimal_set_size =
|
---|
374 | (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
|
---|
375 | 1024;
|
---|
376 |
|
---|
377 | mr_msg(1, "Foo");
|
---|
378 | if (bkpinfo->backup_media_type == tape) {
|
---|
379 | mr_msg(1, "Bar");
|
---|
380 | mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
|
---|
381 | mr_msg(1, "tmp = '%s'", tmp);
|
---|
382 | if (run_program_and_log_output(tmp, 3)) {
|
---|
383 | fatal_error
|
---|
384 | ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
|
---|
385 | }
|
---|
386 | mr_free(tmp);
|
---|
387 | }
|
---|
388 | make_hole_for_dir(bkpinfo->scratchdir);
|
---|
389 | if (bkpinfo->backup_media_type == iso)
|
---|
390 | make_hole_for_dir(bkpinfo->isodir);
|
---|
391 |
|
---|
392 | run_program_and_log_output("uname -a", 5);
|
---|
393 | run_program_and_log_output("cat /etc/*-release", 5);
|
---|
394 | sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
|
---|
395 | mr_asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt);
|
---|
396 | paranoid_system(command);
|
---|
397 | mr_free(command);
|
---|
398 | rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
|
---|
399 | #ifdef __FreeBSD__
|
---|
400 | mr_asprintf(&tmp,
|
---|
401 | call_program_and_get_last_line_of_output
|
---|
402 | ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
|
---|
403 | avm += atol(tmp);
|
---|
404 | mr_free(tmp);
|
---|
405 | mr_asprintf(&tmp,
|
---|
406 | call_program_and_get_last_line_of_output
|
---|
407 | ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
|
---|
408 | avm += atol(tmp);
|
---|
409 | mr_free(tmp);
|
---|
410 | mr_asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
|
---|
411 | g_tmpfs_mountpt);
|
---|
412 | #else
|
---|
413 | mr_asprintf(&tmp,
|
---|
414 | call_program_and_get_last_line_of_output
|
---|
415 | ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1"));
|
---|
416 | avm += atol(tmp);
|
---|
417 | mr_free(tmp);
|
---|
418 | mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
|
---|
419 | g_tmpfs_mountpt, rdsiz_MB, 'm');
|
---|
420 | run_program_and_log_output("cat /proc/cpuinfo", 5);
|
---|
421 | /* BERLIOS: rpm is not necessarily there ! */
|
---|
422 | run_program_and_log_output
|
---|
423 | ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
|
---|
424 | 5);
|
---|
425 | #endif
|
---|
426 | if (avm / 1024 > rdsiz_MB * 3) {
|
---|
427 | if (run_program_and_log_output(command, 5)) {
|
---|
428 | g_tmpfs_mountpt[0] = '\0';
|
---|
429 | log_it("Failed to mount tmpfs");
|
---|
430 | } else {
|
---|
431 | log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
|
---|
432 | }
|
---|
433 | } else {
|
---|
434 | g_tmpfs_mountpt[0] = '\0';
|
---|
435 | log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
|
---|
436 | }
|
---|
437 | mr_free(command);
|
---|
438 |
|
---|
439 | if (bkpinfo->use_lzo) {
|
---|
440 | strcpy(bkpinfo->zip_exe, "lzop");
|
---|
441 | strcpy(bkpinfo->zip_suffix, "lzo");
|
---|
442 | } else if (bkpinfo->use_gzip) {
|
---|
443 | strcpy(bkpinfo->zip_exe, "gzip");
|
---|
444 | strcpy(bkpinfo->zip_suffix, "gz");
|
---|
445 | } else if (bkpinfo->compression_level != 0) {
|
---|
446 | strcpy(bkpinfo->zip_exe, "bzip2");
|
---|
447 | strcpy(bkpinfo->zip_suffix, "bz2");
|
---|
448 | } else {
|
---|
449 | bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
|
---|
450 | }
|
---|
451 |
|
---|
452 | // CD-R or CD-RW or DVD
|
---|
453 | if (bkpinfo->backup_media_type == cdrw
|
---|
454 | || bkpinfo->backup_media_type == dvd
|
---|
455 | || bkpinfo->backup_media_type == iso
|
---|
456 | || bkpinfo->backup_media_type == nfs
|
---|
457 | || bkpinfo->backup_media_type == cdr) {
|
---|
458 | if (!bkpinfo->manual_tray) {
|
---|
459 | mr_strcat(extra_cdrom_params, "-waiti ");
|
---|
460 | }
|
---|
461 | if (bkpinfo->backup_media_type == cdrw) {
|
---|
462 | mr_strcat(extra_cdrom_params, "blank=fast ");
|
---|
463 | }
|
---|
464 | if (bkpinfo->nonbootable_backup) {
|
---|
465 | mr_asprintf(&mondo_mkisofs_sz, "%s -no-boot", mr_conf->iso_creation_opt);
|
---|
466 | } else if
|
---|
467 | #ifdef __FreeBSD__
|
---|
468 | (TRUE)
|
---|
469 | #else
|
---|
470 | (bkpinfo->make_cd_use_lilo)
|
---|
471 | #endif
|
---|
472 | #ifdef __IA64__
|
---|
473 | {
|
---|
474 | mr_asprintf(&mondo_mkisofs_sz, "%s -b images/mindi-boot.2880.img -c boot.cat", mr_conf->iso_creation_opt);
|
---|
475 | }
|
---|
476 | #else
|
---|
477 | {
|
---|
478 | mr_asprintf(&mondo_mkisofs_sz, "%s -b isolinux.bin -c boot.cat", mr_conf->iso_creation_opt);
|
---|
479 | }
|
---|
480 | #endif
|
---|
481 | else {
|
---|
482 | mr_asprintf(&mondo_mkisofs_sz, "%s -b isolinux.bin -c boot.cat", mr_conf->iso_creation_opt);
|
---|
483 | }
|
---|
484 | if (bkpinfo->manual_tray) {
|
---|
485 | if (strstr(mr_conf->iso_burning_cmd,"growisofs") != NULL) {
|
---|
486 | fatal_error("Unable to use manual CD tray with growisofs");
|
---|
487 | }
|
---|
488 | if (bkpinfo->call_before_iso[0] == '\0') {
|
---|
489 | sprintf(bkpinfo->call_before_iso,
|
---|
490 | "%s %s -o %s/"MONDO_TMPISOS" . 2>> %s",
|
---|
491 | mr_conf->iso_creation_cmd,mondo_mkisofs_sz, bkpinfo->tmpdir, MONDO_LOGFILE);
|
---|
492 | } else {
|
---|
493 | mr_asprintf(&call_before_iso_user, bkpinfo->call_before_iso);
|
---|
494 | sprintf (bkpinfo->call_before_iso,
|
---|
495 | "(%s %s -o %s/"MONDO_TMPISOS" . 2>> %s ; %s )",
|
---|
496 | mr_conf->iso_creation_cmd,mondo_mkisofs_sz, bkpinfo->tmpdir, MONDO_LOGFILE, call_before_iso_user);
|
---|
497 | mr_free(call_before_iso_user);
|
---|
498 | }
|
---|
499 | log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
|
---|
500 | sprintf(bkpinfo->call_make_iso,
|
---|
501 | "%s %s %s dev=%s speed=%d %s/"MONDO_TMPISOS,
|
---|
502 | mr_conf->iso_burning_cmd,
|
---|
503 | extra_cdrom_params,
|
---|
504 | mr_conf->iso_burning_opt,
|
---|
505 | bkpinfo->iso_burning_dev,
|
---|
506 | bkpinfo->writer_speed,
|
---|
507 | bkpinfo->tmpdir);
|
---|
508 | } else {
|
---|
509 | if (bkpinfo->backup_media_type == iso) {
|
---|
510 | sprintf(bkpinfo->call_make_iso,
|
---|
511 | "%s %s . 2>> %s",
|
---|
512 | mr_conf->iso_creation_cmd,
|
---|
513 | mondo_mkisofs_sz,
|
---|
514 | MONDO_LOGFILE);
|
---|
515 | } else {
|
---|
516 | if (strstr(mr_conf->iso_burning_cmd,"growisofs") != NULL) {
|
---|
517 | if (getenv ("SUDO_COMMAND")) {
|
---|
518 | mr_asprintf(&command, "strings %s | grep -c SUDO_COMMAND", mr_conf->iso_burning_cmd);
|
---|
519 | if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
|
---|
520 | fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
|
---|
521 | }
|
---|
522 | mr_free(command);
|
---|
523 | }
|
---|
524 | sprintf(bkpinfo->call_make_iso,
|
---|
525 | "%s %s %s %s -Z %s -speed=%d . 2>> %s",
|
---|
526 | mr_conf->iso_burning_cmd,
|
---|
527 | mondo_mkisofs_sz,
|
---|
528 | extra_cdrom_params,
|
---|
529 | mr_conf->iso_burning_opt,
|
---|
530 | bkpinfo->iso_burning_dev,
|
---|
531 | bkpinfo->writer_speed,
|
---|
532 | MONDO_LOGFILE);
|
---|
533 | } else {
|
---|
534 | sprintf(bkpinfo->call_make_iso,
|
---|
535 | "%s %s . 2>> %s | %s %s %s dev=%s speed=%d -",
|
---|
536 | mr_conf->iso_creation_cmd,
|
---|
537 | mondo_mkisofs_sz,
|
---|
538 | MONDO_LOGFILE,
|
---|
539 | mr_conf->iso_burning_cmd,
|
---|
540 | extra_cdrom_params,
|
---|
541 | mr_conf->iso_burning_opt,
|
---|
542 | bkpinfo->iso_burning_dev,
|
---|
543 | bkpinfo->writer_speed);
|
---|
544 | }
|
---|
545 | mr_free(mondo_mkisofs_sz);
|
---|
546 | mr_free(extra_cdrom_params);
|
---|
547 | }
|
---|
548 | }
|
---|
549 | } // end of CD code
|
---|
550 |
|
---|
551 | if (bkpinfo->backup_media_type == iso) {
|
---|
552 |
|
---|
553 | /* Patch by Conor Daly <conor.daly@met.ie>
|
---|
554 | * 23-june-2004
|
---|
555 | * Break up isodir into iso_mnt and iso_path
|
---|
556 | * These will be used along with iso-dev at restore time
|
---|
557 | * to locate the ISOs where ever they're mounted
|
---|
558 | */
|
---|
559 |
|
---|
560 | log_it("isodir = %s", bkpinfo->isodir);
|
---|
561 | mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1",
|
---|
562 | bkpinfo->isodir);
|
---|
563 | log_it("command = %s", command);
|
---|
564 | mr_asprintf(&iso_dev, call_program_and_get_last_line_of_output(command));
|
---|
565 | mr_free(command);
|
---|
566 | log_it("res of it = %s", iso_dev);
|
---|
567 |
|
---|
568 | fd1 = mr_fopen(MONDORESTORECFG, "a");
|
---|
569 | mr_fprintf(fd1, "iso-dev=%s\n", iso_dev);
|
---|
570 |
|
---|
571 | mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
|
---|
572 | iso_dev);
|
---|
573 | mr_free(iso_dev);
|
---|
574 |
|
---|
575 | log_it("command = %s", command);
|
---|
576 | mr_asprintf(&iso_mnt,call_program_and_get_last_line_of_output(command));
|
---|
577 | mr_free(command);
|
---|
578 |
|
---|
579 | log_it("res of it = %s", iso_mnt);
|
---|
580 | mr_fprintf(fd1, "iso-mnt=%s\n", iso_mnt);
|
---|
581 | log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
|
---|
582 |
|
---|
583 | mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir);
|
---|
584 | if (strlen(iso_tmp) >= strlen(iso_mnt)) {
|
---|
585 | mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt));
|
---|
586 | } else {
|
---|
587 | mr_asprintf(&iso_path, "");
|
---|
588 | }
|
---|
589 | mr_free(iso_tmp);
|
---|
590 | mr_free(iso_mnt);
|
---|
591 |
|
---|
592 | log_it("isodir: %s", iso_path);
|
---|
593 | mr_fprintf(fd1, "isodir=%s\n", iso_path);
|
---|
594 | mr_free(iso_path);
|
---|
595 |
|
---|
596 | log_it("iso-prefix: %s", bkpinfo->prefix);
|
---|
597 | mr_fprintf(fd1, "iso-prefix=%s\n", bkpinfo->prefix);
|
---|
598 |
|
---|
599 | mr_fclose(fd1);
|
---|
600 | } // end of iso code
|
---|
601 |
|
---|
602 | if (bkpinfo->backup_media_type == nfs) {
|
---|
603 | mr_asprintf(&hostname, bkpinfo->nfs_mount);
|
---|
604 | colon = strchr(hostname, ':');
|
---|
605 | if (!colon) {
|
---|
606 | log_it("nfs mount doesn't have a colon in it");
|
---|
607 | retval++;
|
---|
608 | } else {
|
---|
609 | struct hostent *hent;
|
---|
610 |
|
---|
611 | *colon = '\0';
|
---|
612 | hent = gethostbyname(hostname);
|
---|
613 | if (!hent) {
|
---|
614 | log_it("Can't resolve NFS mount (%s): %s", hostname,
|
---|
615 | hstrerror(h_errno));
|
---|
616 | retval++;
|
---|
617 | } else {
|
---|
618 | mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr)
|
---|
619 | *((struct in_addr *) hent->h_addr)),
|
---|
620 | strchr(bkpinfo->nfs_mount, ':'));
|
---|
621 | strcpy(bkpinfo->nfs_mount, ip_address);
|
---|
622 | mr_free(ip_address);
|
---|
623 | }
|
---|
624 | }
|
---|
625 | store_nfs_config();
|
---|
626 | mr_free(hostname);
|
---|
627 | }
|
---|
628 |
|
---|
629 | log_it("Finished processing incoming params");
|
---|
630 | if (retval) {
|
---|
631 | fprintf(stderr, "Type 'man mondoarchive' for help.\n");
|
---|
632 | }
|
---|
633 |
|
---|
634 | if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
|
---|
635 | log_it("tmpdir or scratchdir are blank/missing");
|
---|
636 | retval++;
|
---|
637 | }
|
---|
638 | if (bkpinfo->include_paths[0] == '\0') {
|
---|
639 | // fatal_error ("Why no backup path?");
|
---|
640 | strcpy(bkpinfo->include_paths, "/");
|
---|
641 | }
|
---|
642 | chmod(bkpinfo->scratchdir, 0700);
|
---|
643 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
644 | g_backup_media_string = bkpinfo->backup_media_string;
|
---|
645 | return (retval);
|
---|
646 | }
|
---|
647 |
|
---|
648 |
|
---|
649 | /**
|
---|
650 | * Do some miscellaneous setup tasks to be performed before filling @c bkpinfo.
|
---|
651 | * Seeds the random-number generator, loads important modules, checks the sanity
|
---|
652 | * of the user's Linux distribution, and deletes logfile.
|
---|
653 | * @param bkpinfo The backup information structure. Will be initialized.
|
---|
654 | * @return number of errors (0 for success)
|
---|
655 | */
|
---|
656 | int pre_param_configuration()
|
---|
657 | {
|
---|
658 | int res = 0;
|
---|
659 | char *tmp = NULL;
|
---|
660 |
|
---|
661 | make_hole_for_dir(MNT_CDROM);
|
---|
662 | assert(bkpinfo != NULL);
|
---|
663 | srandom((unsigned long) (time(NULL)));
|
---|
664 | insmod_crucial_modules();
|
---|
665 | if (bkpinfo->disaster_recovery) {
|
---|
666 | if (!does_nonMS_partition_exist()) {
|
---|
667 | fatal_error
|
---|
668 | ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
|
---|
669 | }
|
---|
670 | }
|
---|
671 |
|
---|
672 | asprintf(&tmp,"rm -Rf %s/changed.files*",MINDI_CACHE);
|
---|
673 | run_program_and_log_output(tmp, FALSE);
|
---|
674 | paranoid_free(tmp);
|
---|
675 | res += some_basic_system_sanity_checks();
|
---|
676 | if (res) {
|
---|
677 | log_it("Your distribution did not pass Mondo's sanity test.");
|
---|
678 | }
|
---|
679 | g_current_media_number = 1;
|
---|
680 | bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
|
---|
681 | return (res);
|
---|
682 | }
|
---|
683 |
|
---|
684 | void setup_tmpdir(char *path) {
|
---|
685 |
|
---|
686 | char *tmp = NULL;
|
---|
687 | char *p = NULL;
|
---|
688 |
|
---|
689 | if (bkpinfo->tmpdir != NULL) {
|
---|
690 | /* purging a potential old tmpdir */
|
---|
691 | asprintf(&tmp,"rm -Rf %s",bkpinfo->tmpdir);
|
---|
692 | system(tmp);
|
---|
693 | paranoid_free(tmp);
|
---|
694 | }
|
---|
695 |
|
---|
696 | if (path != NULL) {
|
---|
697 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", path);
|
---|
698 | } else if (getenv("TMPDIR")) {
|
---|
699 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
|
---|
700 | } else if (getenv("TMP")) {
|
---|
701 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
|
---|
702 | } else {
|
---|
703 | asprintf(&tmp, "/tmp/mondo.tmp.XXXXXX");
|
---|
704 | }
|
---|
705 | p = mkdtemp(tmp);
|
---|
706 | if (p == NULL) {
|
---|
707 | log_it("Failed to create global tmp directory %s for Mondo.",tmp);
|
---|
708 | finish(-1);
|
---|
709 | }
|
---|
710 | strcpy(bkpinfo->tmpdir,p);
|
---|
711 | paranoid_free(tmp);
|
---|
712 |
|
---|
713 | //sprintf(bkpinfo->tmpdir, "%s/tmpfs/mondo.tmp.%d", "/tmp", (int) (random() % 32768)); // for mondorestore
|
---|
714 | }
|
---|
715 |
|
---|
716 |
|
---|
717 | /**
|
---|
718 | * Reset all fields of the backup information structure to a sensible default.
|
---|
719 | * @param bkpinfo The @c bkpinfo to reset.
|
---|
720 | */
|
---|
721 | void reset_bkpinfo()
|
---|
722 | {
|
---|
723 | char *tmp = NULL;
|
---|
724 |
|
---|
725 | mr_msg(1, "Hi");
|
---|
726 |
|
---|
727 | assert(bkpinfo != NULL);
|
---|
728 | /* BERLIOS : Useless ?? */
|
---|
729 | memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
|
---|
730 |
|
---|
731 | /* special case for tmpdir as used eveywhere after */
|
---|
732 | setup_tmpdir(NULL);
|
---|
733 |
|
---|
734 | bkpinfo->manual_tray = mr_conf->manual_tray;
|
---|
735 | bkpinfo->internal_tape_block_size = mr_conf->internal_tape_blocksize;
|
---|
736 | mr_asprintf(&tmp,mr_conf->media_device);
|
---|
737 | bkpinfo->media_device = tmp;
|
---|
738 | mr_asprintf(&tmp,mr_conf->iso_burning_dev);
|
---|
739 | bkpinfo->iso_burning_dev = tmp;
|
---|
740 |
|
---|
741 | bkpinfo->media_size = mr_conf->iso_burning_speed;
|
---|
742 | mr_asprintf(&tmp,mr_conf->kernel);
|
---|
743 | bkpinfo->kernel_path = tmp;
|
---|
744 |
|
---|
745 | if (strcmp(mr_conf->boot_loader,"LILO") == 0) {
|
---|
746 | bkpinfo->boot_loader = 'L';
|
---|
747 | } else if (strcmp(mr_conf->boot_loader,"GRUB") == 0) {
|
---|
748 | bkpinfo->boot_loader = 'G';
|
---|
749 | } else if (strcmp(mr_conf->boot_loader,"ELILO") == 0) {
|
---|
750 | bkpinfo->boot_loader = 'E';
|
---|
751 | } else if (strcmp(mr_conf->boot_loader,"RAW") == 0) {
|
---|
752 | bkpinfo->boot_loader = 'R';
|
---|
753 | } else if (strcmp(mr_conf->boot_loader,"DD") == 0) {
|
---|
754 | bkpinfo->boot_loader = 'D';
|
---|
755 | } else if (strcmp(mr_conf->boot_loader,"BOOT0") == 0) {
|
---|
756 | bkpinfo->boot_loader = 'B';
|
---|
757 | } else if (strcmp(mr_conf->boot_loader,"NATIVE") == 0) {
|
---|
758 | bkpinfo->boot_loader = '\0';
|
---|
759 | } else{
|
---|
760 | mr_msg("Boot Loader %s unknown\n",mr_conf->boot_loader);
|
---|
761 | fatal_error("Unknown Boot Loader in conf file");
|
---|
762 | }
|
---|
763 | bkpinfo->boot_device[0] = '\0';
|
---|
764 | bkpinfo->zip_exe[0] = '\0';
|
---|
765 | bkpinfo->zip_suffix[0] = '\0';
|
---|
766 | bkpinfo->restore_path[0] = '\0';
|
---|
767 | bkpinfo->use_lzo = FALSE;
|
---|
768 | bkpinfo->use_gzip = FALSE;
|
---|
769 | bkpinfo->do_not_compress_these[0] = '\0';
|
---|
770 | bkpinfo->verify_data = FALSE;
|
---|
771 | bkpinfo->backup_data = FALSE;
|
---|
772 | bkpinfo->restore_data = FALSE;
|
---|
773 | bkpinfo->disaster_recovery =
|
---|
774 | (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
|
---|
775 | if (bkpinfo->disaster_recovery) {
|
---|
776 | strcpy(bkpinfo->isodir, "/");
|
---|
777 | } else {
|
---|
778 | strcpy(bkpinfo->isodir, "/var/cache/mondo/iso");
|
---|
779 | }
|
---|
780 | mr_asprintf(&tmp,mr_conf->prefix);
|
---|
781 | bkpinfo->prefix = tmp;
|
---|
782 |
|
---|
783 | bkpinfo->scratchdir[0] = '\0';
|
---|
784 | bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
|
---|
785 | bkpinfo->optimal_set_size = 0;
|
---|
786 | bkpinfo->backup_media_type = none;
|
---|
787 | bkpinfo->backup_media_string[0] = '\0';
|
---|
788 | strcpy(bkpinfo->include_paths, "/");
|
---|
789 | bkpinfo->exclude_paths[0] = '\0';
|
---|
790 | bkpinfo->call_before_iso[0] = '\0';
|
---|
791 | bkpinfo->call_make_iso[0] = '\0';
|
---|
792 | bkpinfo->call_after_iso[0] = '\0';
|
---|
793 | bkpinfo->image_devs[0] = '\0';
|
---|
794 | bkpinfo->postnuke_tarball[0] = '\0';
|
---|
795 | bkpinfo->nfs_mount[0] = '\0';
|
---|
796 | bkpinfo->nfs_remote_dir[0] = '\0';
|
---|
797 | bkpinfo->wipe_media_first = FALSE;
|
---|
798 | bkpinfo->differential = FALSE;
|
---|
799 | bkpinfo->writer_speed = mr_conf->iso_burning_speed;
|
---|
800 | bkpinfo->compression_level = 3;
|
---|
801 | }
|
---|
802 |
|
---|
803 |
|
---|
804 | /**
|
---|
805 | * Get the remaining free space (in MB) on @p partition.
|
---|
806 | * @param partition The partition to check free space on (either a device or a mountpoint).
|
---|
807 | * @return The free space on @p partition, in MB.
|
---|
808 | */
|
---|
809 | long free_space_on_given_partition(char *partition)
|
---|
810 | {
|
---|
811 | char *command = NULL;
|
---|
812 | char *out_sz = NULL;
|
---|
813 | long res = 0L;
|
---|
814 |
|
---|
815 | assert_string_is_neither_NULL_nor_zerolength(partition);
|
---|
816 |
|
---|
817 | mr_asprintf(&command, "df -m -P %s &> /dev/null", partition);
|
---|
818 | if (system(command)) {
|
---|
819 | return (-1);
|
---|
820 | } // partition does not exist
|
---|
821 | mr_free(command);
|
---|
822 |
|
---|
823 | mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
|
---|
824 | partition);
|
---|
825 | mr_asprintf(&out_sz, call_program_and_get_last_line_of_output(command));
|
---|
826 | mr_free(command);
|
---|
827 |
|
---|
828 | if (strlen(out_sz) == 0) {
|
---|
829 | return (-1);
|
---|
830 | } // error within df, probably
|
---|
831 | res = atol(out_sz);
|
---|
832 | mr_free(out_sz);
|
---|
833 | return (res);
|
---|
834 | }
|
---|
835 |
|
---|
836 |
|
---|
837 | /**
|
---|
838 | * Check the user's system for sanity. Checks performed:
|
---|
839 | * - make sure user has enough RAM (32mb required, 64mb recommended)
|
---|
840 | * - make sure user has enough free space in @c /
|
---|
841 | * - check kernel for ramdisk support
|
---|
842 | * - make sure afio, cdrecord, bzip2, awk, md5sum, strings, mindi, and buffer exist
|
---|
843 | * - make sure CD-ROM is unmounted
|
---|
844 | * - make sure /etc/modules.conf exists
|
---|
845 | * - make sure user's mountlist is OK by running <tt>mindi --makemountlist</tt>
|
---|
846 | *
|
---|
847 | * @return number of problems with the user's setup (0 for success)
|
---|
848 | */
|
---|
849 | int some_basic_system_sanity_checks()
|
---|
850 | {
|
---|
851 |
|
---|
852 | /*@ buffers ************ */
|
---|
853 | char *tmp = NULL;
|
---|
854 |
|
---|
855 | /*@ int's *************** */
|
---|
856 | int retval = 0;
|
---|
857 | long Lres;
|
---|
858 |
|
---|
859 |
|
---|
860 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
861 | "Checking sanity of your Linux distribution");
|
---|
862 | #ifndef __FreeBSD__
|
---|
863 | if (system("which mkfs.vfat &> /dev/null")
|
---|
864 | && !system("which mkfs.msdos &> /dev/null")) {
|
---|
865 | log_it
|
---|
866 | ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
|
---|
867 | run_program_and_log_output
|
---|
868 | ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
|
---|
869 | }
|
---|
870 | mr_asprintf(&tmp,
|
---|
871 | call_program_and_get_last_line_of_output
|
---|
872 | ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
|
---|
873 | if (atol(tmp) < 35000) {
|
---|
874 | retval++;
|
---|
875 | log_to_screen(_("You must have at least 32MB of RAM to use Mondo."));
|
---|
876 | }
|
---|
877 | if (atol(tmp) < 66000) {
|
---|
878 | log_to_screen
|
---|
879 | (_("WARNING! You have very little RAM. Please upgrade to 64MB or more."));
|
---|
880 | }
|
---|
881 | mr_free(tmp);
|
---|
882 | #endif
|
---|
883 |
|
---|
884 | Lres = free_space_on_given_partition(MONDO_CACHE);
|
---|
885 | log_it("Free space on given partition = %ld MB", Lres);
|
---|
886 |
|
---|
887 | if (Lres < 50) {
|
---|
888 | fatal_error("Your "MONDO_CACHE" partition has <50MB free. Please adjust your partition table to something saner or make "MONDO_CACHE" a symbolic link");
|
---|
889 | }
|
---|
890 |
|
---|
891 | if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
|
---|
892 | retval++;
|
---|
893 | log_to_screen
|
---|
894 | ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
|
---|
895 | fatal_error
|
---|
896 | ("Please use \"su -\", not \"su\" to become root. OK? ...and please don't e-mail the mailing list or me about this. Just read the message. :)");
|
---|
897 | }
|
---|
898 | #ifndef __FreeBSD__
|
---|
899 | if (run_program_and_log_output
|
---|
900 | ("grep ramdisk /proc/devices", FALSE)) {
|
---|
901 | if (!ask_me_yes_or_no
|
---|
902 | (_("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?")))
|
---|
903 | {
|
---|
904 | // retval++;
|
---|
905 | log_to_screen
|
---|
906 | (_("It looks as if your kernel lacks ramdisk and initrd support."));
|
---|
907 | log_to_screen
|
---|
908 | (_("I'll allow you to proceed but FYI, if I'm right, your kernel is broken."));
|
---|
909 | }
|
---|
910 | }
|
---|
911 | #endif
|
---|
912 | retval += whine_if_not_found(mr_conf->iso_creation_cmd);
|
---|
913 | retval += whine_if_not_found(mr_conf->iso_burning_cmd);
|
---|
914 | retval += whine_if_not_found(MKE2FS_OR_NEWFS);
|
---|
915 | retval += whine_if_not_found("bzip2");
|
---|
916 | retval += whine_if_not_found("gzip");
|
---|
917 | retval += whine_if_not_found("awk");
|
---|
918 | retval += whine_if_not_found("md5sum");
|
---|
919 | retval += whine_if_not_found("strings");
|
---|
920 | retval += whine_if_not_found("mindi");
|
---|
921 | retval += whine_if_not_found("buffer");
|
---|
922 |
|
---|
923 | // abort if Windows partition but no ms-sys and parted
|
---|
924 | if (!run_program_and_log_output
|
---|
925 | ("mount | grep -w vfat | grep -vE \"/dev/fd|nexdisk\"", 0)
|
---|
926 | ||
|
---|
927 | !run_program_and_log_output
|
---|
928 | ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) {
|
---|
929 | log_to_screen(_("I think you have a Windows 9x partition."));
|
---|
930 | retval += whine_if_not_found("parted");
|
---|
931 | #ifndef __IA64__
|
---|
932 | /* IA64 always has one vfat partition for EFI even without Windows */
|
---|
933 | // retval +=
|
---|
934 | if (!find_home_of_exe("ms-sys")) {
|
---|
935 | log_to_screen("Please install ms-sys just in case.");
|
---|
936 | }
|
---|
937 | #endif
|
---|
938 | }
|
---|
939 |
|
---|
940 | if (!find_home_of_exe("cmp")) {
|
---|
941 | if (!find_home_of_exe("true")) {
|
---|
942 | whine_if_not_found("cmp");
|
---|
943 | } else {
|
---|
944 | log_to_screen
|
---|
945 | ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
|
---|
946 | if (run_program_and_log_output
|
---|
947 | ("cp -f `which true` /usr/bin/cmp", 0)) {
|
---|
948 | fatal_error("Failed to create dummy 'cmp' file.");
|
---|
949 | }
|
---|
950 | }
|
---|
951 | }
|
---|
952 | run_program_and_log_output
|
---|
953 | ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
|
---|
954 | mr_asprintf(&tmp,
|
---|
955 | call_program_and_get_last_line_of_output
|
---|
956 | ("mount | grep -E \"cdr(om|w)\""));
|
---|
957 | if (strcmp("", tmp)) {
|
---|
958 | if (strstr(tmp, "autofs")) {
|
---|
959 | log_to_screen
|
---|
960 | (_("Your CD-ROM is mounted via autofs. I therefore cannot tell"));
|
---|
961 | log_to_screen
|
---|
962 | (_("if a CD actually is inserted. If a CD is inserted, please"));
|
---|
963 | log_to_screen(_("eject it. Thank you."));
|
---|
964 | log_it
|
---|
965 | ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
|
---|
966 | } else
|
---|
967 | if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
|
---|
968 | retval++;
|
---|
969 | fatal_error
|
---|
970 | ("Your CD-ROM drive is mounted. Please unmount it.");
|
---|
971 | }
|
---|
972 | }
|
---|
973 | mr_free(tmp);
|
---|
974 | #ifndef __FreeBSD__
|
---|
975 | if (!does_file_exist("/etc/modules.conf")) {
|
---|
976 | if (does_file_exist("/etc/conf.modules")) {
|
---|
977 | log_it("Linking /etc/modules.conf to /etc/conf.modules");
|
---|
978 | run_program_and_log_output
|
---|
979 | ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
|
---|
980 | } else if (does_file_exist("/etc/modprobe.d")) {
|
---|
981 | log_it
|
---|
982 | ("Directory /etc/modprobe.d found. mindi will use its contents.");
|
---|
983 | } else if (does_file_exist("/etc/modprobe.conf")) {
|
---|
984 | log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
|
---|
985 | run_program_and_log_output
|
---|
986 | ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
|
---|
987 | } else {
|
---|
988 | retval++;
|
---|
989 | log_to_screen
|
---|
990 | (_("Please find out what happened to /etc/modules.conf"));
|
---|
991 | }
|
---|
992 | }
|
---|
993 | #endif
|
---|
994 |
|
---|
995 | run_program_and_log_output("cat /etc/fstab", 5);
|
---|
996 | #ifdef __FreeBSD__
|
---|
997 | run_program_and_log_output("vinum printconfig", 5);
|
---|
998 | #else
|
---|
999 | run_program_and_log_output("cat /etc/raidtab", 5);
|
---|
1000 | #endif
|
---|
1001 |
|
---|
1002 | if (run_program_and_log_output("mindi -V", 1)) {
|
---|
1003 | log_to_screen(_("Could not ascertain mindi's version number."));
|
---|
1004 | log_to_screen
|
---|
1005 | (_("You have not installed Mondo and/or Mindi properly."));
|
---|
1006 | log_to_screen(_("Please uninstall and reinstall them both."));
|
---|
1007 | fatal_error("Please reinstall Mondo and Mindi.");
|
---|
1008 | }
|
---|
1009 | mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);
|
---|
1010 | if (run_program_and_log_output(tmp, 5)) {
|
---|
1011 | log_to_screen(tmp);
|
---|
1012 | log_to_screen
|
---|
1013 | (_("failed for some reason."));
|
---|
1014 | log_to_screen
|
---|
1015 | (_("Please run that command by hand and examine /var/log/mindi.log"));
|
---|
1016 | log_to_screen
|
---|
1017 | (_("for more information. Perhaps your /etc/fstab file is insane."));
|
---|
1018 | log_to_screen
|
---|
1019 | (_("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see."));
|
---|
1020 | retval++;
|
---|
1021 | }
|
---|
1022 | mr_free(tmp);
|
---|
1023 |
|
---|
1024 | if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1)
|
---|
1025 | && !does_file_exist("/etc/raidtab")) {
|
---|
1026 | log_to_screen
|
---|
1027 | (_("You have RAID partitions but no /etc/raidtab - creating one from "MDSTAT_FILE));
|
---|
1028 | create_raidtab_from_mdstat("/etc/raidtab");
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | if (retval) {
|
---|
1032 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
1033 | } else {
|
---|
1034 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
1035 | }
|
---|
1036 | return (retval);
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | /**
|
---|
1040 | * Retrieve the line containing @p label from the config file.
|
---|
1041 | * @param config_file The file to read from, usually @c /tmp/mondo-restore.cfg.
|
---|
1042 | * @param label What to read from the file.
|
---|
1043 | * @param value Where to put it.
|
---|
1044 | * @return 0 for success, 1 for failure.
|
---|
1045 | */
|
---|
1046 | int read_cfg_var(char *config_file, char *label, char *value)
|
---|
1047 | {
|
---|
1048 | /*@ buffer ****************************************************** */
|
---|
1049 | char *command = NULL;
|
---|
1050 | char *tmp = NULL;
|
---|
1051 |
|
---|
1052 | /*@ end vars *************************************************** */
|
---|
1053 |
|
---|
1054 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
1055 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
1056 |
|
---|
1057 | if (!does_file_exist(config_file)) {
|
---|
1058 | mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
|
---|
1059 | config_file);
|
---|
1060 | log_to_screen(tmp);
|
---|
1061 | mr_free(tmp);
|
---|
1062 | value[0] = '\0';
|
---|
1063 | return (1);
|
---|
1064 | /* } BERLIOS: Useless:
|
---|
1065 | else if (strstr(value, "/dev/") && strstr(value, "t0")
|
---|
1066 | && !strcmp(label, "media-dev")) {
|
---|
1067 | mr_msg(2, "FYI, I shan't read new value for %s - already got %s",
|
---|
1068 | label, value);
|
---|
1069 | return (0);
|
---|
1070 | */ } else {
|
---|
1071 | mr_asprintf(&command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5",
|
---|
1072 | label, config_file);
|
---|
1073 | strcpy(value, call_program_and_get_last_line_of_output(command));
|
---|
1074 | mr_free(command);
|
---|
1075 | if (strlen(value) == 0) {
|
---|
1076 | return (1);
|
---|
1077 | } else {
|
---|
1078 | return (0);
|
---|
1079 | }
|
---|
1080 | }
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 |
|
---|
1084 | /**
|
---|
1085 | * Remount @c supermount if it was unmounted earlier.
|
---|
1086 | */
|
---|
1087 | void remount_supermounts_if_necessary()
|
---|
1088 | {
|
---|
1089 | if (g_remount_cdrom_at_end) {
|
---|
1090 | run_program_and_log_output("mount " MNT_CDROM, FALSE);
|
---|
1091 | }
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | /**
|
---|
1095 | * Unmount @c supermount if it's mounted.
|
---|
1096 | */
|
---|
1097 | void unmount_supermounts_if_necessary()
|
---|
1098 | {
|
---|
1099 | if (run_program_and_log_output
|
---|
1100 | ("mount | grep cdrom | grep super", FALSE) == 0) {
|
---|
1101 | g_remount_cdrom_at_end = TRUE;
|
---|
1102 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
1103 | }
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | /**
|
---|
1107 | * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
|
---|
1108 | */
|
---|
1109 | void mount_boot_if_necessary()
|
---|
1110 | {
|
---|
1111 | char *tmp = NULL;
|
---|
1112 | char *tmp1 = NULL;
|
---|
1113 | char *command = NULL;
|
---|
1114 |
|
---|
1115 | mr_msg(1, "Started sub");
|
---|
1116 | mr_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
|
---|
1117 | g_boot_mountpt[0] = '\0';
|
---|
1118 | mr_msg(4, "Done. Great. Setting command to something");
|
---|
1119 | mr_asprintf(&command,
|
---|
1120 | "grep -v ':' /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
|
---|
1121 | mr_msg(4, "Cool. Command = '%s'", command);
|
---|
1122 | mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
|
---|
1123 | mr_free(command);
|
---|
1124 |
|
---|
1125 | mr_msg(4, "tmp = '%s'", tmp);
|
---|
1126 | if (tmp[0]) {
|
---|
1127 | log_it("/boot is at %s according to /etc/fstab", tmp);
|
---|
1128 | if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) {
|
---|
1129 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
1130 | strcpy(g_boot_mountpt, "/boot");
|
---|
1131 | mr_msg(1, "Mounted /boot");
|
---|
1132 | } else {
|
---|
1133 | log_it("...ignored cos it's a label or uuid :-)");
|
---|
1134 | }
|
---|
1135 | } else {
|
---|
1136 | mr_asprintf(&command, "mount | grep -E '^%s'", tmp);
|
---|
1137 | mr_msg(3, "command = %s", command);
|
---|
1138 | if (run_program_and_log_output(command, 5)) {
|
---|
1139 | strcpy(g_boot_mountpt, tmp);
|
---|
1140 | mr_asprintf(&tmp1,
|
---|
1141 | "%s (your /boot partition) is not mounted. I'll mount it before backing up",
|
---|
1142 | g_boot_mountpt);
|
---|
1143 | log_it(tmp1);
|
---|
1144 | mr_free(tmp1);
|
---|
1145 |
|
---|
1146 | mr_asprintf(&tmp1, "mount %s", g_boot_mountpt);
|
---|
1147 | if (run_program_and_log_output(tmp1, 5)) {
|
---|
1148 | g_boot_mountpt[0] = '\0';
|
---|
1149 | mr_msg(1, "Plan B");
|
---|
1150 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
1151 | strcpy(g_boot_mountpt, "/boot");
|
---|
1152 | mr_msg(1, "Plan B worked");
|
---|
1153 | } else {
|
---|
1154 | mr_msg(1,
|
---|
1155 | "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
|
---|
1156 | }
|
---|
1157 | }
|
---|
1158 | mr_free(tmp1);
|
---|
1159 | }
|
---|
1160 | mr_free(command);
|
---|
1161 | }
|
---|
1162 | }
|
---|
1163 | mr_free(tmp);
|
---|
1164 | mr_msg(1, "Ended sub");
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 |
|
---|
1168 | /**
|
---|
1169 | * If we mounted /boot earlier, unmount it.
|
---|
1170 | */
|
---|
1171 | void unmount_boot_if_necessary()
|
---|
1172 | {
|
---|
1173 | char *tmp;
|
---|
1174 |
|
---|
1175 | mr_msg(3, "starting");
|
---|
1176 | if (g_boot_mountpt[0]) {
|
---|
1177 | mr_asprintf(&tmp, "umount %s", g_boot_mountpt);
|
---|
1178 | if (run_program_and_log_output(tmp, 5)) {
|
---|
1179 | log_it("WARNING - unable to unmount /boot");
|
---|
1180 | }
|
---|
1181 | mr_free(tmp);
|
---|
1182 | }
|
---|
1183 | mr_msg(3, "leaving");
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 |
|
---|
1187 | /**
|
---|
1188 | * Write a line to a configuration file. Writes a line of the form,
|
---|
1189 | * @c label @c value.
|
---|
1190 | * @param config_file The file to write to. Usually @c mondo-restore.cfg.
|
---|
1191 | * @param label What to call this bit of data you're writing.
|
---|
1192 | * @param value The bit of data you're writing.
|
---|
1193 | * @return 0 for success, 1 for failure.
|
---|
1194 | */
|
---|
1195 | int write_cfg_var(char *config_file, char *label, char *value)
|
---|
1196 | {
|
---|
1197 | /*@ buffers ***************************************************** */
|
---|
1198 | char *command = NULL;
|
---|
1199 | char *tempfile = NULL;
|
---|
1200 | char *tmp = NULL;
|
---|
1201 |
|
---|
1202 |
|
---|
1203 | /*@ end vars *************************************************** */
|
---|
1204 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
1205 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
1206 | assert(value != NULL);
|
---|
1207 |
|
---|
1208 | if (!does_file_exist(config_file)) {
|
---|
1209 | mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file",
|
---|
1210 | config_file);
|
---|
1211 | log_to_screen(tmp);
|
---|
1212 | mr_free(tmp);
|
---|
1213 | return (1);
|
---|
1214 | }
|
---|
1215 | mr_asprintf(&tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
|
---|
1216 | if (does_file_exist(config_file)) {
|
---|
1217 | mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s",
|
---|
1218 | label, config_file, tempfile);
|
---|
1219 | paranoid_system(command);
|
---|
1220 | mr_free(command);
|
---|
1221 | }
|
---|
1222 | mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
|
---|
1223 | paranoid_system(command);
|
---|
1224 | mr_free(command);
|
---|
1225 |
|
---|
1226 | mr_asprintf(&command, "mv -f %s %s", tempfile, config_file);
|
---|
1227 | paranoid_system(command);
|
---|
1228 | mr_free(command);
|
---|
1229 | unlink(tempfile);
|
---|
1230 | mr_free(tempfile);
|
---|
1231 | return (0);
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 |
|
---|
1235 | /**
|
---|
1236 | * Allocate or free important globals, depending on @p mal.
|
---|
1237 | * @param mal If TRUE, malloc; if FALSE, free.
|
---|
1238 | */
|
---|
1239 | void do_libmondo_global_strings_thing(int mal)
|
---|
1240 | {
|
---|
1241 | if (mal) {
|
---|
1242 | malloc_string(g_boot_mountpt);
|
---|
1243 | malloc_string(g_tmpfs_mountpt);
|
---|
1244 | malloc_string(g_erase_tmpdir_and_scratchdir);
|
---|
1245 | malloc_string(g_serial_string);
|
---|
1246 | malloc_string(g_magicdev_command);
|
---|
1247 | } else {
|
---|
1248 | mr_free(g_boot_mountpt);
|
---|
1249 | mr_free(g_tmpfs_mountpt);
|
---|
1250 | mr_free(g_erase_tmpdir_and_scratchdir);
|
---|
1251 | mr_free(g_serial_string);
|
---|
1252 | mr_free(g_magicdev_command);
|
---|
1253 | }
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | /**
|
---|
1257 | * Allocate important globals.
|
---|
1258 | * @see do_libmondo_global_strings_thing
|
---|
1259 | */
|
---|
1260 | void malloc_libmondo_global_strings(void)
|
---|
1261 | {
|
---|
1262 | do_libmondo_global_strings_thing(1);
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | /**
|
---|
1266 | * Free important globals.
|
---|
1267 | * @see do_libmondo_global_strings_thing
|
---|
1268 | */
|
---|
1269 | void free_libmondo_global_strings(void)
|
---|
1270 | {
|
---|
1271 | do_libmondo_global_strings_thing(0);
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 |
|
---|
1275 |
|
---|
1276 | /**
|
---|
1277 | * Stop @c magicdev if it's running.
|
---|
1278 | * The command used to start it is saved in @p g_magicdev_command.
|
---|
1279 | */
|
---|
1280 | void stop_magicdev_if_necessary()
|
---|
1281 | {
|
---|
1282 | strcpy(g_magicdev_command,
|
---|
1283 | call_program_and_get_last_line_of_output
|
---|
1284 | ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
|
---|
1285 | if (g_magicdev_command[0]) {
|
---|
1286 | mr_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
|
---|
1287 | paranoid_system("killall magicdev");
|
---|
1288 | }
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 |
|
---|
1292 | /**
|
---|
1293 | * Restart magicdev if it was stopped.
|
---|
1294 | */
|
---|
1295 | void restart_magicdev_if_necessary()
|
---|
1296 | {
|
---|
1297 | char *tmp = NULL;
|
---|
1298 |
|
---|
1299 | if (g_magicdev_command && g_magicdev_command[0]) {
|
---|
1300 | mr_asprintf(&tmp, "%s &", g_magicdev_command);
|
---|
1301 | paranoid_system(tmp);
|
---|
1302 | mr_free(tmp);
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | /* @} - end of utilityGroup */
|
---|