source: MondoRescue/branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c@ 3383

Last change on this file since 3383 was 3383, checked in by Bruno Cornec, 9 years ago
  • Fix mindi-get-perl-modules to get all modules in dependency as well (pb with Expoerter module missing during UEFI tests)
  • Property svn:keywords set to Id
File size: 73.5 KB
RevLine 
[1]1/***************************************************************************
[2029]2$Id: mondo-rstr-tools.c 3383 2015-05-12 00:16:38Z bruno $
[1242]3***************************************************************************/
[1]4
5#include <pthread.h>
[1846]6#include <linux/fd.h>
[1930]7#include "my-stuff.h"
[2211]8#include "mr_mem.h"
[3193]9#include "mr_str.h"
[1]10#include "../common/mondostructures.h"
11#include "../common/libmondo.h"
12#include "mr-externs.h"
13#include "mondo-rstr-tools.h"
14
[2029]15/**
16 * The biggielist stub (appended to the directory where all.tar.gz was unpacked).
17 */
18#define BIGGIELIST_TXT_STUB "tmp/biggielist.txt"
19
20/**
21 * The filelist stub (appended to the directory where all.tar.gz was unpacked).
22 */
23#define FILELIST_FULL_STUB "tmp/filelist.full.gz"
24
25/**
26 * The mountlist stub (appended to the directory where all.tar.gz was unpacked).
27 */
28#define MOUNTLIST_FNAME_STUB "tmp/mountlist.txt"
29
30/**
[3271]31 * The mondorestore.cfg stub (appended to the directory where all.tar.gz was unpacked).
[2029]32 */
[3271]33#define MONDO_CFG_FILE_STUB "tmp/mondorestore.cfg"
[2029]34/**
35 * The i-want-my-lvm stub
36 */
37#define IWANTMYLVM_STUB "tmp/i-want-my-lvm"
38
[128]39extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
[1]40extern bool g_I_have_just_nuked;
[2030]41/*
[1]42extern char *g_tmpfs_mountpt;
[2030]43*/
[3158]44
45/**
46 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
47 */
48char *g_isodir_device;
49
50
51/**
52 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
53 */
54char *g_isodir_format;
55
[1]56extern long g_current_progress, g_maximum_progress;
[128]57extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;
[1242]58 // biggielist.txt is the list of big files stored on the
59 // backup media set in question
[128]60extern char *g_filelist_full; // filelist.full.gz is the list of all regular files
[1242]61 // (excluding big files) stored on the backup media set
[128]62extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the
[1242]63 // user chooses them
[128]64extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
[1242]65 // were archived as images, not just /dev entries
66 // ... e.g. NTFS, BeOS partitions
[128]67extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
[1242]68 // restore only these
[3292]69extern char *g_mondo_cfg_file; // where mondorestore.cfg (the config file) is stored
[128]70extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
71extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo
[1]72
73extern t_bkptype g_backup_media_type;
74
75extern int g_partition_table_locked_up;
[1316]76extern char *MONDO_LOGFILE;
[1]77
[1645]78/* Reference to global bkpinfo */
79extern struct s_bkpinfo *bkpinfo;
80
[949]81/* Should we use or not extended attributes and acl when restoring */
82char *g_getfattr = NULL;
83char *g_getfacl = NULL;
84
[1850]85extern void kill_anything_like_this(char *str);
[1968]86extern int skip_obdr(void);
[2682]87extern int mount_media();
[2022]88extern int set_tape_block_size_with_mt(long internal_tape_block_size);
[1850]89
[1]90/**
[1242]91* @addtogroup restoreUtilityGroup
92* @{
93*/
[1]94/**
[1242]95* Free the malloc()s for the filename variables.
96*/
[1967]97void free_MR_global_filenames(void)
[1]98{
[1242]99paranoid_free(g_biggielist_txt);
100paranoid_free(g_filelist_full);
101paranoid_free(g_filelist_imagedevs);
102paranoid_free(g_imagedevs_restthese);
103paranoid_free(g_mondo_cfg_file);
104paranoid_free(g_mountlist_fname);
105paranoid_free(g_mondo_home);
[2030]106/*
[1242]107paranoid_free(g_tmpfs_mountpt);
[2030]108*/
[1242]109paranoid_free(g_isodir_device);
110paranoid_free(g_isodir_format);
[1]111
112}
113
114
115
116/**
[1242]117* Ask the user which imagedevs from the list contained in @p infname should
118* actually be restored.
119* @param infname The file containing a list of all imagedevs.
120* @param outfname The location of the output file containing the imagedevs the user wanted to restore.
121* @ingroup restoreUtilityGroup
122*/
[3193]123void ask_about_these_imagedevs(char *infname, char *outfname) {
124
[1242]125FILE *fin;
126FILE *fout;
[3193]127char *incoming = NULL;
128char *question = NULL;
[1]129
[1242]130assert_string_is_neither_NULL_nor_zerolength(infname);
131assert_string_is_neither_NULL_nor_zerolength(outfname);
[1]132
[1242]133if (!(fin = fopen(infname, "r"))) {
[3076]134 fatal_error("Cannot openin infname");
[1242]135}
136if (!(fout = fopen(outfname, "w"))) {
[3076]137 fatal_error("Cannot openin outfname");
[1242]138}
[3193]139for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) {
140 mr_strip_spaces(incoming);
[1]141
[3076]142 if (incoming[0] == '\0') {
[3193]143 mr_free(incoming);
[3076]144 continue;
145 }
[1]146
[3193]147 mr_asprintf(question, "Should I restore the image of %s ?", incoming);
148
149 if (ask_me_yes_or_no(question)) {
150 fprintf(fout, "%s\n", incoming);
[3076]151 }
[3193]152 mr_free(incoming);
[1242]153}
[3193]154mr_free(incoming);
155mr_free(question);
[1242]156paranoid_fclose(fout);
157paranoid_fclose(fin);
[1]158}
159
160/**************************************************************************
[1242]161*ASK_ABOUT_THESE_IMAGEDEVS *
162**************************************************************************/
[1]163
164
165
166
167
168
169
170
171/**
[3271]172* Extract @c mondorestore.cfg and @c mountlist.txt from @p ramdisk_fname.
[1242]173* @param bkpinfo The backup information structure. @c tmpdir is the only field used.
174* @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
175* @param output_cfg_file Where to put the configuration file extracted.
176* @param output_mountlist_file Where to put the mountlist file extracted.
177* @return 0 for success, nonzero for failure.
178* @ingroup restoreUtilityGroup
179*/
[1]180
181/**
[3271]182* Keep trying to get mondorestore.cfg from the archive, until the user gives up.
[1242]183*/
[1645]184void get_cfg_file_from_archive_or_bust()
[1]185{
[1645]186while (get_cfg_file_from_archive()) {
[3263]187 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) {
188 fatal_error("Could not find config file/archives. Aborting.");
189 }
190 interactively_obtain_media_parameters_from_user(FALSE);
191 }
[1]192}
193
194
195/**
[1242]196* Determine whether @p list_fname contains a line containing @p f.
197* @param f The line to search for.
198* @param list_fname The file to search in.
199* @param preamble Ignore this beginning part of @p f ("" to disable).
200* @return TRUE if it's in the list, FALSE if it's not.
201*/
[128]202bool is_file_in_list(char *f, char *list_fname, char *preamble)
[1]203{
204
[3193]205char *command = NULL;
206char *file = NULL;
207char *tmp = NULL;
[1242]208int res;
[1]209
[1242]210assert_string_is_neither_NULL_nor_zerolength(f);
211assert_string_is_neither_NULL_nor_zerolength(list_fname);
212assert(preamble != NULL);
[1]213
[1242]214if (strncmp(preamble, f, strlen(preamble)) == 0) {
[3193]215 mr_asprintf(file, "%s", f + strlen(preamble));
[1242]216} else {
[3193]217 mr_asprintf(file, "%s", f);
[1]218}
[1242]219if (file[0] == '/' && file[1] == '/') {
[3193]220 tmp = file;
221
222 mr_asprintf(file, "%s", tmp + 1);
223 mr_free(tmp);
[1242]224}
[3193]225log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
226mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname);
227mr_free(file);
228
[1242]229res = run_program_and_log_output(command, FALSE);
[3193]230mr_free(command);
[1242]231if (res) {
[3193]232 return (FALSE);
[1242]233} else {
[3193]234 return (TRUE);
[1242]235}
236}
[128]237
[1]238/**************************************************************************
[1242]239*END_IS_FILE_IN_LIST *
240**************************************************************************/
[1]241
[3158]242/**
243 * Get information about the location of ISO images from the user.
244 * @param isodir_device Where to put the device (e.g. /dev/hda4) the user enters.
245 * @param isodir_format Where to put the format (e.g. ext2) the user enters.
246 * @param nuke_me_please Whether we're planning on nuking or not.
247 * @return TRUE if OK was pressed, FALSE otherwise.
248 */
249bool
250get_isodir_info(char *isodir_device, char *isodir_format,
251 struct s_bkpinfo *bkpinfo, bool nuke_me_please)
252{
[1]253
[3158]254 bool HDD = FALSE;
255 /** initialize ********************************************************/
[1]256
[3158]257 assert(isodir_device != NULL);
258 assert(isodir_format != NULL);
259 assert(bkpinfo->isodir != NULL);
260
261 log_it("bkpinfo->isodir = %s", bkpinfo->isodir);
262 isodir_format[0] = '\0';
263 if (isodir_device[0] == '\0') {
264 strcpy(isodir_device, "/dev/");
265 }
266 if (bkpinfo->isodir[0] == '\0') {
267 strcpy(bkpinfo->isodir, "/");
268 }
[3278]269 // TODO: Are we shure it does what it's expected to do here ?
270 if (does_file_exist("/tmp/NETFS-SERVER-MOUNT")) {
[3158]271 strcpy(isodir_device, last_line_of_file("/tmp/NETFS-SERVER-MOUNT"));
272 strcpy(isodir_format, "netfs");
[3278]273 strcpy(bkpinfo->isodir, last_line_of_file("/tmp/ISO-DIR"));
[3158]274 }
275 if (nuke_me_please) {
276 return (TRUE);
277 }
278
[3278]279 if (popup_and_get_string("ISO Mode - device", "On what device do the ISO files live?", isodir_device, MAX_STR_LEN / 4)) {
280 if (popup_and_get_string ("ISO Mode - format", "What is the disk format of the device? (Hit ENTER if you don't know.)", isodir_format, 16)) {
[3158]281 if (popup_with_buttons("Are you restoring from an external hard drive ?", "Yes", "No")) {
282 HDD = TRUE;
283 }
[3278]284 if (popup_and_get_string ("ISO Mode - path", "At what path on this device can the ISO files be found ?", bkpinfo->isodir, MAX_STR_LEN / 4)) {
[3158]285 strip_spaces(isodir_device);
286 strip_spaces(isodir_format);
287 strip_spaces(bkpinfo->isodir);
288 log_it("isodir_device = %s - isodir_format = %s - bkpinfo->isodir = %s", isodir_device, isodir_format, bkpinfo->isodir);
289 if (HDD) {
290 /* We need an additional param */
[3185]291 mr_asprintf(bkpinfo->subdir, "%s", bkpinfo->isodir);
[3158]292 strcpy(bkpinfo->isodir, "/tmp/isodir");
293 log_it("Now bkpinfo->isodir = %s and subdir = ", bkpinfo->isodir, bkpinfo->subdir);
294 }
295 return (TRUE);
296 }
297 }
298 }
299 return (FALSE);
300}
301
302
[1]303/**
[1242]304* Set up an ISO backup.
305* @param bkpinfo The backup information structure. Fields used:
306* - @c bkpinfo->backup_media_type
307* - @c bkpinfo->disaster_recovery
308* - @c bkpinfo->isodir
309* @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
310* @return 0 for success, nonzero for failure.
311*/
[3193]312int iso_fiddly_bits(bool nuke_me_please) {
313
[2211]314char *mount_isodir_command = NULL;
[3193]315char *command = NULL;
[2242]316char *mds = NULL;
[1242]317int retval = 0, i;
[1]318
[1242]319g_ISO_restore_mode = TRUE;
320read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
321if (bkpinfo->disaster_recovery) {
[3278]322 /* Don't let this clobber an existing bkpinfo->isodir */
[2211]323 if (!bkpinfo->isodir[0]) {
324 strcpy(bkpinfo->isodir, "/tmp/isodir");
325 }
[3193]326 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
[2211]327 run_program_and_log_output(command, 5);
[3193]328 mr_free(command);
[2211]329 log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
[1242]330}
[1]331
[3158]332if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo, nuke_me_please)) {
[2211]333 return (1);
[1242]334}
[2878]335paranoid_system("umount -d " MNT_CDROM " 2> /dev/null"); /* just in case */
[1]336
[1242]337if (is_this_device_mounted(g_isodir_device)) {
[2211]338 log_to_screen("WARNING - isodir is already mounted");
[1242]339} else {
[3185]340 mr_asprintf(mount_isodir_command, "mount %s", g_isodir_device);
[2211]341 if (strlen(g_isodir_format) > 1) {
342 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format);
343 }
[3193]344
[2211]345 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir);
[3193]346 run_program_and_log_output("df -m -P", FALSE);
347 log_msg(1, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command);
[2211]348 if (run_program_and_log_output(mount_isodir_command, FALSE)) {
349 popup_and_OK
350 ("Cannot mount the device where the ISO files are stored.");
351 return (1);
352 }
353 paranoid_free(mount_isodir_command);
354 log_to_screen
[1242]355 ("I have mounted the device where the ISO files are stored.");
356}
357if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[1736]358 mount_media();
[1242]359}
[1736]360i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */
[2242]361mds = media_descriptor_string(bkpinfo->backup_media_type);
362mr_free(mds);
363
[3193]364log_msg(1, "%s #%d has been mounted via loopback mount", mds, i);
[1242]365if (i < 0) {
[3193]366 popup_and_OK("Cannot find ISO images in the directory you specified.");
367 retval = 1;
[1242]368}
[3193]369log_msg(2, "bkpinfo->isodir is now %s", bkpinfo->isodir);
[1242]370return (retval);
371}
[1]372
373
374
375
376/**
[1242]377* Kill all Petris processes.
378*/
[1850]379void kill_petris(void) {
[1852]380 kill_anything_like_this("petris");
[1]381}
[128]382
[1]383/**************************************************************************
[1242]384*END_KILL_PETRIS *
385**************************************************************************/
[1]386
387
388/**
[1843]389 * Mount @p device at @p mpt as @p format.
390 * @param device The device (/dev entry) to mount.
391 * @param mpt The directory to mount it on.
392 * @param format The filesystem type of @p device.
393 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
394 * @return 0 for success, nonzero for failure.
395 */
[1771]396int mount_device(char *device, char *mpt, char *format, bool writeable)
397{
398int res = 0;
399
400/** malloc **/
[3193]401char *tmp = NULL;
402char *command = NULL;
403char *mountdir = NULL;
404char *mountpoint = NULL;
[2211]405char *additional_parameters = NULL;
[1771]406
407assert_string_is_neither_NULL_nor_zerolength(device);
408assert_string_is_neither_NULL_nor_zerolength(mpt);
409assert(format != NULL);
410
[1843]411 if (!strcmp(mpt, "/1")) {
[3193]412 mr_asprintf(mountpoint, "/");
[1843]413 log_msg(3, "Mommm! SME is being a dildo!");
414 } else {
[3193]415 mr_asprintf(mountpoint, "%s", mpt);
[1843]416 }
[1771]417
[1843]418 if (!strcmp(mountpoint, "lvm")) {
419 return (0);
420 }
421 if (!strcmp(mountpoint, "image")) {
422 return (0);
423 }
[3193]424 mr_asprintf(tmp, "Mounting device %s ", device);
[1843]425 log_msg(1, tmp);
[1937]426 /* Deal with additional params only if not /proc or /sys */
[3185]427 mr_asprintf(additional_parameters, "");
[1937]428 if (strcmp(format, "proc") && strcmp(format, "sys")) {
429 if (writeable) {
[2211]430 mr_strcat(additional_parameters, "-o rw");
[1937]431 } else {
[2211]432 mr_strcat(additional_parameters, "-o ro");
[1937]433 }
434 if (find_home_of_exe("setfattr")) {
[2211]435 mr_strcat(additional_parameters, ",user_xattr");
[1937]436 }
437 if (find_home_of_exe("setfacl")) {
[2211]438 mr_strcat(additional_parameters, ",acl");
[1937]439 }
[1843]440 }
[1771]441
442 if (!strcmp(mountpoint, "swap")) {
[3193]443 mr_asprintf(command, "swapon %s", device);
444 mr_asprintf(mountdir, "swap");
[1771]445 } else {
[1843]446 if (!strcmp(mountpoint, "/")) {
[3193]447 mr_asprintf(mountdir, "%s", MNT_RESTORING);
[1843]448 } else {
[3193]449 mr_asprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
[1843]450 }
[3193]451 mr_asprintf(command, "mkdir -p %s", mountdir);
[1843]452 run_program_and_log_output(command, FALSE);
[3193]453 mr_free(command);
454
455 mr_asprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE);
[1843]456 log_msg(2, "command='%s'", command);
457 }
[3193]458 mr_free(additional_parameters);
[1843]459
460 res = run_program_and_log_output(command, TRUE);
461 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
462 log_msg(1, "Re-trying without the fancy extra parameters");
[3193]463 mr_free(command);
464 mr_asprintf(command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE);
[1771]465 res = run_program_and_log_output(command, TRUE);
[1843]466 }
467 if (res) {
[3193]468 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir);
[1843]469 log_msg(1, "command was '%s'", command);
470 if (!strcmp(mountpoint, "swap")) {
471 log_to_screen(tmp);
[1771]472 } else {
[1843]473 log_msg(2, "Retrying w/o the '-t' switch");
[3193]474 mr_free(command);
475 mr_asprintf(command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE);
[1843]476 log_msg(2, "2nd command = '%s'", command);
477 res = run_program_and_log_output(command, TRUE);
478 if (res == 0) {
479 log_msg(1,
480 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
481 } else {
482 log_to_screen(tmp);
483 }
[1771]484 }
485 }
486
[1843]487 if (res && !strcmp(mountpoint, "swap")) {
488 log_msg(2, "That's ok. It's just a swap partition.");
489 log_msg(2, "Non-fatal error. Returning 0.");
490 res = 0;
491 }
492
[3193]493mr_free(tmp);
494mr_free(command);
495mr_free(mountdir);
496mr_free(mountpoint);
[1771]497
[3193]498return (res);
[1771]499}
500/**************************************************************************
[1843]501 *END_MOUNT_DEVICE *
[1771]502**************************************************************************/
503
504
505/**
[1843]506 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
507 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
508 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
509 * @return The number of errors encountered (0 for success).
510 */
[3193]511int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable)
[1]512{
[1242]513int retval = 0, lino, res;
[3193]514char *tmp = NULL;
[2211]515char *these_failed = NULL;
516struct mountlist_itself *mountlist = NULL;
[1]517
[1242]518assert(p_external_copy_of_mountlist != NULL);
519mountlist = malloc(sizeof(struct mountlist_itself));
520memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
521 sizeof(struct mountlist_itself));
[1843]522 sort_mountlist_by_mountpoint(mountlist, 0);
[1]523
524
[1843]525 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices ");
[3193]526 open_progress_form("Mounting devices", "I am now mounting all the drives.", "This should not take long.", "", mountlist->entries);
[128]527
[3185]528 mr_asprintf(these_failed, "");
[1843]529 for (lino = 0; lino < mountlist->entries; lino++) {
530 if (!strcmp(mountlist->el[lino].device, "/proc")) {
[3193]531 log_msg(1, "Again with the /proc - why is this in your mountlist?");
[1843]532 } else if (is_this_device_mounted(mountlist->el[lino].device)) {
[3193]533 log_to_screen("%s is already mounted", mountlist->el[lino].device);
[1843]534 } else if (strcmp(mountlist->el[lino].mountpoint, "none")
[1242]535 && strcmp(mountlist->el[lino].mountpoint, "lvm")
536 && strcmp(mountlist->el[lino].mountpoint, "raid")
537 && strcmp(mountlist->el[lino].mountpoint, "image")) {
[3193]538 mr_asprintf(tmp, "Mounting %s", mountlist->el[lino].device);
[1843]539 update_progress_form(tmp);
[3193]540 mr_free(tmp);
541 res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable);
[1843]542 retval += res;
543 if (res) {
[2211]544 mr_strcat(these_failed, "%s ",mountlist->el[lino].device);
[1843]545 }
546 }
547 g_current_progress++;
[1]548 }
[1843]549 close_progress_form();
550 if (retval) {
551 if (g_partition_table_locked_up > 0) {
[3193]552 log_to_screen("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
553 log_to_screen("lock up the partition table. You might have to reboot and use Interactive Mode to");
554 log_to_screen("format and restore *without* partitioning first. Sorry for the inconvenience.");
[1843]555 }
[3193]556 mr_asprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
[1843]557
558 if (!ask_me_yes_or_no(tmp)) {
559 retval = 0;
[3193]560 log_to_screen("Continuing, although some device(s) failed to be mounted");
[1843]561 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
562 } else {
563 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[3193]564 log_to_screen("Unable to mount some or all of your partitions.");
[1843]565 }
[3193]566 mr_free(tmp);
[1843]567 } else {
568 log_to_screen("All partitions were mounted OK.");
569 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
570 }
[2211]571 paranoid_free(these_failed);
572
[1937]573 /* Also mounting under MNT_RESTORING special FS */
574 (void)mount_device("/proc","/proc","proc",TRUE);
575 (void)mount_device("/sys","/sys","sysfs",TRUE);
[3193]576 run_program_and_log_output("df -m -P", 3);
[1843]577 paranoid_free(mountlist);
578 return (retval);
[1242]579}
580/**************************************************************************
581*END_MOUNT_ALL_DEVICES *
582**************************************************************************/
[1]583
584
585/**
[1242]586* Fix some miscellaneous things in the filesystem so the system will come
587* up correctly on the first boot.
588*/
[3301]589void protect_against_braindead_sysadmins() {
590
591run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", FALSE);
592run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", FALSE);
[1242]593if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
[3301]594 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", FALSE);
[1]595}
[3301]596run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run/console", FALSE);
597run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null", FALSE);
598run_program_and_log_output("cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done", TRUE);
599run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", TRUE);
600run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", TRUE);
[1242]601}
[128]602
[1]603/**************************************************************************
[1242]604*END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
605**************************************************************************/
[1]606
607
608
609
610/**
[1242]611* Fill out @p bkpinfo based on @p cfg_file.
[3271]612* @param cfg_file The mondorestore.cfg file to read into @p bkpinfo.
[1242]613* @param bkpinfo The backup information structure to fill out with information
614* from @p cfg_file.
615* @return 0 for success, nonzero for failure.
616*/
[1645]617int read_cfg_file_into_bkpinfo(char *cfgf)
[1]618{
[1242]619/** add mallocs **/
[3193]620char value[MAX_STR_LEN];
621char *tmp1 = NULL;
[1242]622char *envtmp1 = NULL;
623char *envtmp2 = NULL;
624char *command = NULL;
[3193]625char iso_mnt[MAX_STR_LEN];
626char iso_path[MAX_STR_LEN];
[1242]627char *old_isodir = NULL;
[3193]628char *cfg_file = NULL;
[1242]629t_bkptype media_specified_by_user;
[1]630
631// assert_string_is_neither_NULL_nor_zerolength(cfg_file);
[1242]632assert(bkpinfo != NULL);
[3193]633assert(cfgf != NULL);
[3158]634log_it("Entering read_cfg_file_into_bkpinfo");
[1]635
[1242]636if (!cfgf) {
[3211]637 mr_asprintf(cfg_file, "%s", g_mondo_cfg_file);
[1242]638} else {
[3211]639 mr_asprintf(cfg_file, "%s", cfgf);
[1242]640}
[1]641
[1242]642media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
[1]643
[1242]644if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
[3193]645 if (!strcmp(value, "cdstream")) {
646 bkpinfo->backup_media_type = cdstream;
647 } else if (!strcmp(value, "cdr")) {
648 bkpinfo->backup_media_type = cdr;
649 } else if (!strcmp(value, "cdrw")) {
650 bkpinfo->backup_media_type = cdrw;
651 } else if (!strcmp(value, "dvd")) {
652 bkpinfo->backup_media_type = dvd;
653 } else if (!strcmp(value, "usb")) {
654 bkpinfo->backup_media_type = usb;
655 bkpinfo->please_dont_eject = TRUE;
656 } else if (!strcmp(value, "iso")) {
657 bkpinfo->backup_media_type = iso;
658 if (am_I_in_disaster_recovery_mode()) {
659 /* Check to see if CD is already mounted before mounting it... */
660 if (!is_this_device_mounted("/dev/cdrom")) {
661 log_msg(2, "NB: CDROM device not mounted, mounting...");
662 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
663 }
664 if (does_file_exist(MNT_CDROM"/archives/filelist.0")) {
665 bkpinfo->backup_media_type = cdr;
666 run_program_and_log_output("umount -d "MNT_CDROM, 1);
667 log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
668 }
[128]669 }
[3193]670 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
[1242]671 strcpy(bkpinfo->prefix,value);
[3193]672 } else {
[1242]673 strcpy(bkpinfo->prefix,STD_PREFIX);
[949]674 }
[3193]675 log_it("Setting Prefix to %s", bkpinfo->prefix);
676 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
677 /* Stay compatible with previous versions by allowing nfs as an entry here */
678 bkpinfo->backup_media_type = netfs;
679 bkpinfo->please_dont_eject = TRUE;
680 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) {
681 mr_asprintf(bkpinfo->netfs_proto,"%s", value);
682 } else {
683 /* For compatibility, force protocol in old nfs case to be transparent */
684 mr_asprintf(bkpinfo->netfs_proto, "nfs");
685 }
686 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) {
687 mr_asprintf(bkpinfo->netfs_user,"%s", value);
688 }
689 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
690 strcpy(bkpinfo->prefix,value);
691 } else {
692 strcpy(bkpinfo->prefix,STD_PREFIX);
693 }
694 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) {
695 /* We need to override prefix value in PXE mode as it's
696 * already done in start-netfs */
697 envtmp1 = getenv("imgname");
698 if (envtmp1 == NULL) {
699 fatal_error("no imgname variable in environment");
700 }
701 strcpy(bkpinfo->prefix,envtmp1);
702 }
703 } else if (!strcmp(value, "tape")) {
704 bkpinfo->backup_media_type = tape;
705 } else if (!strcmp(value, "udev")) {
706 bkpinfo->backup_media_type = udev;
707 } else {
708 fatal_error("UNKNOWN bkp-media-type");
[949]709 }
[1242]710} else {
[3193]711 fatal_error("backup-media-type not specified!");
[1242]712}
[3193]713
[1242]714if (bkpinfo->disaster_recovery) {
[1736]715 if (bkpinfo->backup_media_type == cdstream) {
716 sprintf(bkpinfo->media_device, "/dev/cdrom");
[3150]717 bkpinfo->media_size = 650; /* good guess */
[1736]718 } else if (bkpinfo->backup_media_type == usb) {
[2127]719 envtmp1 = getenv("MRUSBDEV");
720 if (envtmp1 == NULL) {
721 if (read_cfg_var(cfg_file, "usb-dev", value)) {
722 fatal_error("Cannot get USB device name from cfg file");
723 }
724 } else {
725 strcpy(value,envtmp1);
[1736]726 }
[1741]727 sprintf(bkpinfo->media_device, "%s1", value);
[3193]728 log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
729 } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
[1736]730 if (read_cfg_var(cfg_file, "media-dev", value)) {
731 fatal_error("Cannot get tape device name from cfg file");
732 }
733 strcpy(bkpinfo->media_device, value);
734 read_cfg_var(cfg_file, "media-size", value);
[3150]735 bkpinfo->media_size = atol(value);
[3193]736 log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
[1736]737 } else {
738 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */
[3150]739 bkpinfo->media_size = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
[3158]740 log_msg(2, "Backup medium is similar to CD-R[W]");
[1]741 }
[1242]742} else {
[3193]743 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
[1242]744}
[128]745
[1242]746read_cfg_var(cfg_file, "use-star", value);
747if (strstr(value, "yes")) {
[1948]748 bkpinfo->use_star = TRUE;
749 log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
[1242]750}
751
[1948]752read_cfg_var(cfg_file, "obdr", value);
753if (strstr(value, "TRUE")) {
754 bkpinfo->use_obdr = TRUE;
755 log_msg(1, "OBDR mode activated");
756}
757
[1242]758read_cfg_var(cfg_file, "acl", value);
759if (strstr(value, "TRUE")) {
[3185]760 mr_asprintf(g_getfacl,"setfacl");
[1948]761 log_msg(1, "We will restore ACLs");
762 if (! find_home_of_exe("setfacl")) {
763 log_msg(1, "Unable to restore ACLs as no setfacl found");
764 }
[1242]765}
766read_cfg_var(cfg_file, "xattr", value);
767if (strstr(value, "TRUE")) {
[3185]768 mr_asprintf(g_getfattr,"setfattr");
[1948]769 log_msg(1, "We will restore XATTRs");
770 if (! find_home_of_exe("setfattr")) {
771 log_msg(1, "Unable to restore XATTRs as no setfattr found");
772 }
[1242]773}
774
775if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
[3193]776 bkpinfo->internal_tape_block_size = atol(value);
[1242]777} else {
[3193]778 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
[1242]779}
[3193]780log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size);
[1242]781
[3193]782read_cfg_var(cfg_file, "use-lzma", value);
783if (strstr(value, "yes")) {
784 bkpinfo->use_lzma = TRUE;
785 bkpinfo->use_lzo = FALSE;
786 bkpinfo->use_gzip = FALSE;
787 strcpy(bkpinfo->zip_exe, "lzma");
788 strcpy(bkpinfo->zip_suffix, "lzma");
789}
790
[1242]791read_cfg_var(cfg_file, "use-lzo", value);
792if (strstr(value, "yes")) {
[3193]793 bkpinfo->use_lzma = FALSE;
794 bkpinfo->use_lzo = TRUE;
795 bkpinfo->use_gzip = FALSE;
796 strcpy(bkpinfo->zip_exe, "lzop");
797 strcpy(bkpinfo->zip_suffix, "lzo");
798}
799
[1242]800read_cfg_var(cfg_file, "use-gzip", value);
801if (strstr(value, "yes")) {
[3193]802 bkpinfo->use_lzma = FALSE;
[1242]803 bkpinfo->use_lzo = FALSE;
804 bkpinfo->use_gzip = TRUE;
805 strcpy(bkpinfo->zip_exe, "gzip");
806 strcpy(bkpinfo->zip_suffix, "gz");
807}
[3193]808
809read_cfg_var(cfg_file, "use-comp", value);
810if (strstr(value, "yes")) {
811 bkpinfo->use_lzma = FALSE;
812 bkpinfo->use_lzo = FALSE;
813 bkpinfo->use_gzip = FALSE;
814 strcpy(bkpinfo->zip_exe, "bzip2");
815 strcpy(bkpinfo->zip_suffix, "bz2");
[1242]816}
[1]817
[1242]818value[0] = '\0';
819read_cfg_var(cfg_file, "differential", value);
820if (!strcmp(value, "yes") || !strcmp(value, "1")) {
[3193]821 bkpinfo->differential = TRUE;
[1242]822}
823log_msg(2, "differential var = '%s'", value);
824if (bkpinfo->differential) {
[3193]825 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
[1242]826} else {
[3193]827 log_msg(2, "This is a regular (full) backup");
[1242]828}
829
[3211]830read_cfg_var(cfg_file, "please-dont-eject", value);
[3193]831if (value[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) {
[3158]832 bkpinfo->please_dont_eject = TRUE;
833 log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
[1242]834}
835
[2380]836if (bkpinfo->backup_media_type == netfs) {
[1736]837 if (!cfgf) {
[3193]838 if (bkpinfo->netfs_mount) {
839 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
840 }
[3207]841 if (bkpinfo->netfs_remote_dir != NULL) {
[3193]842 log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir);
843 }
844 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
[1736]845 } else {
[3211]846 read_cfg_var(cfg_file, "netfs-server-mount", value);
[3193]847 mr_free(bkpinfo->netfs_mount);
848 mr_asprintf(bkpinfo->netfs_mount, "%s", value);
[3278]849 if (bkpinfo->netfs_mount != NULL) {
850 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
851 }
[3193]852
[3278]853 read_cfg_var(cfg_file, "iso-dir", value);
[3193]854 mr_free(bkpinfo->netfs_remote_dir);
855 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value);
856 if (bkpinfo->netfs_remote_dir != NULL) {
857 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
858 }
[3278]859
[3193]860 if (bkpinfo->netfs_proto != NULL) {
861 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
862 }
863 if (bkpinfo->netfs_user != NULL) {
[2847]864 log_msg(2, "netfs_user is %s", bkpinfo->netfs_user);
865 }
[1]866 }
[3193]867 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) {
[1968]868 /* We need to override values in PXE mode as it's
[2380]869 * already done in start-netfs */
870 envtmp1 = getenv("netfsmount");
[1736]871 if (envtmp1 == NULL) {
[2380]872 fatal_error("no netfsmount variable in environment");
[1736]873 }
874 envtmp2 = getenv("dirimg");
875 if (envtmp2 == NULL) {
876 fatal_error("no dirimg variable in environment");
877 }
[3193]878 mr_free(bkpinfo->netfs_mount);
879 mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1);
880
881 mr_free(bkpinfo->netfs_remote_dir);
882 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2);
[1]883 }
[1242]884} else if (bkpinfo->backup_media_type == iso) {
[1736]885 /* Patch by Conor Daly 23-june-2004
886 * to correctly mount iso-dev and set a sensible
887 * isodir in disaster recovery mode
888 */
[3193]889 mr_asprintf(old_isodir, "%s", bkpinfo->isodir);
[3211]890 read_cfg_var(cfg_file, "iso-mnt", iso_mnt);
[3278]891 read_cfg_var(cfg_file, "iso-dir", iso_path);
[1736]892 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
893 if (!bkpinfo->isodir[0]) {
[1242]894 strcpy(bkpinfo->isodir, old_isodir);
[128]895 }
[3158]896 if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) {
[1736]897 if (strcmp(old_isodir, bkpinfo->isodir)) {
[3193]898 log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir );
[1736]899 strcpy(bkpinfo->isodir, old_isodir);
900 }
901 }
[3211]902 mr_free(old_isodir);
903
[3158]904 if (g_isodir_device[0] == '\0') {
905 /* We don't want to loose our conf made earlier in iso_fiddly_bits
906 * so go here only if job not done already */
[3211]907 read_cfg_var(cfg_file, "iso-dev", g_isodir_device);
[3158]908 }
909
910 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
[3193]911
[1736]912 if (bkpinfo->disaster_recovery) {
913 if (is_this_device_mounted(g_isodir_device)) {
914 log_msg(2, "NB: isodir is already mounted");
915 /* Find out where it's mounted */
[3193]916 mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);
[1736]917 log_it("command = %s", command);
[3193]918 log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
[3194]919 sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
[3193]920 mr_free(command);
[1736]921 } else {
[3194]922 sprintf(iso_mnt, "/tmp/isodir");
[3193]923 mr_asprintf(tmp1, "mkdir -p %s", iso_mnt);
924 run_program_and_log_output(tmp1, 5);
925 mr_free(tmp1);
926
927 mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt);
928 if (run_program_and_log_output(tmp1, 3)) {
929 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
[1736]930 bkpinfo->backup_media_type = cdr;
931 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */
932 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
933 if (mount_media()) {
[3193]934 mr_free(tmp1);
935 fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well.");
[1736]936 } else {
[3193]937 log_msg(1, "You backed up to disk, then burned some CDs.");
[1736]938 }
[128]939 }
[3193]940 mr_free(tmp1);
[128]941 }
[1736]942 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
[3193]943 /* except when already done in iso_fiddly_bits */
[3158]944 if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) {
[1736]945 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
946 }
[1]947 }
[1242]948}
[3211]949mr_free(cfg_file);
[1]950
[1242]951if (media_specified_by_user != none) {
[1736]952 if (g_restoring_live_from_cd) {
953 if (bkpinfo->backup_media_type != media_specified_by_user) {
[3158]954 log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
[1736]955 interactively_obtain_media_parameters_from_user(FALSE);
956 media_specified_by_user = bkpinfo->backup_media_type;
957 get_cfg_file_from_archive();
958 }
[128]959 }
[1736]960 bkpinfo->backup_media_type = media_specified_by_user;
[1242]961}
962g_backup_media_type = bkpinfo->backup_media_type;
963return (0);
[1]964
965}
[128]966
[1]967/**************************************************************************
[1242]968*END_READ_CFG_FILE_INTO_BKPINFO *
969**************************************************************************/
[1]970
971
972
[128]973
[1]974/**
[1843]975 * Allow the user to edit the filelist and biggielist.
976 * The filelist is unlinked after it is read.
977 * @param bkpinfo The backup information structure. Fields used:
978 * - @c bkpinfo->backup_media_type
979 * - @c bkpinfo->isodir
980 * - @c bkpinfo->media_device
981 * - @c bkpinfo->tmpdir
982 * @return The filelist structure containing the information read from disk.
983 */
[1]984struct
[1645]985s_node *process_filelist_and_biggielist()
[1]986{
[1242]987struct s_node *filelist;
[1]988
[3193]989char *command = NULL;
[1242]990char *tmp;
[3076]991char *q;
[1242]992int res = 0;
993pid_t pid;
[2049]994bool extract_mountlist_stub = FALSE;
[1]995
[1242]996assert(bkpinfo != NULL);
997malloc_string(tmp);
[1]998
[2049]999/* If those files already exist, do not overwrite them later on */
1000if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
1001 extract_mountlist_stub = FALSE;
1002} else {
1003 extract_mountlist_stub = TRUE;
1004}
1005
[1242]1006if (does_file_exist(g_filelist_full)
1007&& does_file_exist(g_biggielist_txt)) {
[1987]1008 log_msg(1, "%s exists", g_filelist_full);
1009 log_msg(1, "%s exists", g_biggielist_txt);
1010 log_msg(2,
[1242]1011 "Filelist and biggielist already recovered from media. Yay!");
1012} else {
[3116]1013 if (getcwd(tmp, MAX_STR_LEN) == NULL) {
1014 // FIXME
1015 }
[3076]1016 if (chdir(bkpinfo->tmpdir)) {
1017 // FIXME
1018 }
[1987]1019 log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
1020 log_to_screen("Extracting filelist and biggielist from media...");
1021 unlink("/tmp/filelist.full");
[2029]1022 unlink(FILELIST_FULL_STUB);
[1987]1023 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[3193]1024 mr_asprintf(command, "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
[1987]1025 log_msg(1, "tarcommand = %s", command);
1026 run_program_and_log_output(command, 1);
[3193]1027 mr_free(command);
1028
[2029]1029 if (!does_file_exist(FILELIST_FULL_STUB)) {
1030 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1031 log_msg(2, "pre-2.2.4 compatible mode on");
[3193]1032 mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
[2029]1033 log_msg(1, "tarcommand = %s", command);
1034 run_program_and_log_output(command, 1);
[3193]1035 mr_free(command);
[2029]1036 }
[1987]1037 } else {
[3193]1038 log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
[1987]1039 insist_on_this_cd_number(1);
1040 log_msg(2, "Back from iotcn");
1041 run_program_and_log_output("mount", 1);
[3193]1042 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
[1]1043
[1987]1044 log_msg(1, "tarcommand = %s", command);
1045 run_program_and_log_output(command, 1);
[3193]1046 mr_free(command);
1047
[2029]1048 if (!does_file_exist(FILELIST_FULL_STUB)) {
1049 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1050 log_msg(2, "pre-2.2.4 compatible mode on");
[3193]1051 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
[2029]1052
1053 log_msg(1, "tarcommand = %s", command);
1054 run_program_and_log_output(command, 1);
[3193]1055 mr_free(command);
[2029]1056 }
[1987]1057 if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
[3193]1058 fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
[1987]1059 }
1060 if (!does_file_exist(FILELIST_FULL_STUB)) {
[3193]1061 fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB);
[1987]1062 }
[128]1063 }
[3193]1064 mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file);
[1987]1065 run_program_and_log_output(command, FALSE);
[3193]1066 mr_free(command);
[1]1067
[3193]1068 mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
[1987]1069 log_msg(1, "command = %s", command);
1070 paranoid_system(command);
[3193]1071 mr_free(command);
1072
1073 mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
[1987]1074 log_msg(1, "command = %s", command);
1075 paranoid_system(command);
[3193]1076 mr_free(command);
[1987]1077 }
[1242]1078
[1987]1079 if (am_I_in_disaster_recovery_mode()
1080 &&
[2049]1081 /* If it was there, do not overwrite it */
1082 (extract_mountlist_stub)
1083 &&
[1987]1084 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
1085 {
[3193]1086 mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
1087 paranoid_system(command);
1088 mr_free(command);
[1987]1089 }
[1]1090
[3076]1091 if (chdir(tmp)) {
1092 // FIXME
1093 }
[2049]1094
[1987]1095 if (!does_file_exist(g_biggielist_txt)) {
1096 log_msg(1, "Warning - %s not found", g_biggielist_txt);
1097 }
1098 if (!does_file_exist(g_filelist_full)) {
1099 log_msg(1, "Warning - %s does not exist", g_filelist_full);
1100 }
[1]1101
[1987]1102 log_msg(2, "Forking");
1103 pid = fork();
1104 switch (pid) {
1105 case -1:
1106 fatal_error("Forking error");
1107 break;
[1]1108
[1987]1109 case 0:
1110 log_to_screen("Pre-processing filelist");
1111 if (!does_file_exist(g_biggielist_txt)) {
[3193]1112 mr_asprintf(command, "echo -n > %s", g_biggielist_txt);
[128]1113 paranoid_system(command);
[3193]1114 mr_free(command);
[128]1115 }
[3193]1116 mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs);
[128]1117 paranoid_system(command);
[3193]1118 mr_free(command);
[128]1119 exit(0);
1120 break;
1121
1122 default:
[541]1123 open_evalcall_form("Pre-processing filelist");
[128]1124 while (!waitpid(pid, (int *) 0, WNOHANG)) {
1125 usleep(100000);
1126 update_evalcall_form(0);
1127 }
[1]1128 }
[128]1129 close_evalcall_form();
[1]1130
[128]1131 log_msg(3, "loading filelist");
1132 filelist = load_filelist(g_filelist_full);
1133 log_msg(3, "deleting original filelist");
1134 unlink(g_filelist_full);
1135 if (g_text_mode) {
[3076]1136 q = NULL;
1137 while (q == NULL) {
1138 printf("Restore which directory? --> ");
[3193]1139 mr_getline(q, stdin);
[3076]1140 }
[3193]1141 toggle_path_selection(filelist, q, TRUE);
1142 if (strlen(q) == 0) {
[128]1143 res = 1;
1144 } else {
1145 res = 0;
1146 }
[3193]1147 mr_free(q);
[128]1148 } else {
1149 res = edit_filelist(filelist);
[1]1150 }
[128]1151 if (res) {
1152 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
1153 free_filelist(filelist);
1154 return (NULL);
1155 }
1156 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
1157 close_evalcall_form();
[1]1158
[128]1159 // NB: It's not necessary to add g_biggielist_txt to the filelist.full
1160 // file. The filelist.full file already contains the filename of EVERY
1161 // file backed up - regular and biggie files.
[1]1162
[128]1163 // However, we do want to make sure the imagedevs selected by the user
1164 // are flagged for restoring.
1165 if (length_of_file(g_imagedevs_restthese) > 2) {
1166 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
1167 TRUE);
1168 }
[1]1169
[128]1170 paranoid_free(tmp);
1171 return (filelist);
1172}
[1]1173
1174/**************************************************************************
1175 *END_ PROCESS_FILELIST_AND_BIGGIELIST *
1176 **************************************************************************/
1177
1178
1179
1180
1181/**
1182 * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
1183 * The backup filename is the filename of the original with ".pristine" added.
1184 * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
1185 * @param filename The filename (absolute path) within @p path_root.
1186 * @return 0 for success, nonzero for failure.
1187 */
[128]1188int backup_crucial_file(char *path_root, char *filename)
[1]1189{
[3193]1190 char *tmp = NULL;
1191 char *command = NULL;
[128]1192 int res;
[1]1193
[128]1194 assert(path_root != NULL);
1195 assert_string_is_neither_NULL_nor_zerolength(filename);
1196
[3193]1197 mr_asprintf(tmp, "%s/%s", path_root, filename);
1198 mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp);
1199 mr_free(tmp);
[128]1200
1201 res = run_program_and_log_output(command, 5);
[3193]1202 mr_free(command);
[128]1203 return (res);
[1]1204}
1205
[2094]1206void offer_to_make_initrd() {
[1]1207
[2094]1208if (bkpinfo->restore_mode != nuke) {
[2110]1209 if (ask_me_yes_or_no
1210 ("You will now be able to re-generate your initrd.\nThis is especially useful if you changed of hardware configuration, cloned, made P2V, used multipath...\nDo you need to do it ?")) {
[2136]1211 log_msg(1,"Launching shell for manual initrd recreation");
[2758]1212 if (does_file_exist(MNT_RESTORING"/etc/arch-release")) {
1213 popup_and_OK("You'll now be chrooted under your future / partition.\nEdit /etc/mkinitcpio.conf if needed and rebuild your initrd with the kernel preset name e.g.\nmkinitcpio -p kernel26\nThen type exit to finish.\n");
1214 } else {
[3157]1215 popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your init(rd|ramfs) with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nor initramfs, dracut, ... Then type exit to finish.");
[2758]1216 }
[2110]1217 mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd...");
1218 if (!g_text_mode) {
1219 newtSuspend();
1220 }
[3076]1221 paranoid_system("chroot " MNT_RESTORING);
[2110]1222 if (!g_text_mode) {
1223 newtResume();
1224 }
1225 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1226 } else {
[2094]1227 return;
1228 }
1229} else {
1230 log_to_screen("Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1231 log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1232}
1233}
1234
1235
[1]1236/**
1237 * Install the user's boot loader in the MBR.
1238 * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
1239 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1240 * @return 0 for success, nonzero for failure.
1241 */
[128]1242int run_boot_loader(bool offer_to_hack_scripts)
[1]1243{
[128]1244 int res;
1245 int retval = 0;
[1]1246
1247 /** malloc *******/
[3193]1248 char *device = NULL;
1249 char *name = NULL;
[1845]1250 char *cmd = NULL;
[1]1251
[128]1252 malloc_string(device);
1253 malloc_string(name);
[1845]1254
1255 /* In order to have a working bootloader, we need to have all devices
1256 * ready in the chroot. If they are not there (udev) then copy them from
1257 * the current /dev location
1258 */
[3185]1259 mr_asprintf(cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
[1845]1260 run_program_and_log_output(cmd, 3);
[1873]1261 paranoid_free(cmd);
[1845]1262
[128]1263 backup_crucial_file(MNT_RESTORING, "/etc/fstab");
[2095]1264 backup_crucial_file(MNT_RESTORING, "/boot/grub/menu.lst");
[2449]1265 backup_crucial_file(MNT_RESTORING, "/boot/grub/grub.cfg");
[2944]1266 backup_crucial_file(MNT_RESTORING, "/boot/grub2/grub.cfg");
[128]1267 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1268 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
[1845]1269 backup_crucial_file(MNT_RESTORING, "/boot/grub/device.map");
[2944]1270 backup_crucial_file(MNT_RESTORING, "/boot/grub2/device.map");
[1845]1271 backup_crucial_file(MNT_RESTORING, "/etc/mtab");
[128]1272 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1273 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
[3193]1274 log_msg(2, "run_boot_loader: device='%s', name='%s'", device, name);
1275 sync();
[2094]1276
1277 offer_to_make_initrd();
[128]1278 if (!strcmp(name, "LILO")) {
1279 res = run_lilo(offer_to_hack_scripts);
1280 } else if (!strcmp(name, "ELILO")) {
1281 res = run_elilo(offer_to_hack_scripts);
1282 } else if (!strcmp(name, "GRUB")) {
1283 res = run_grub(offer_to_hack_scripts, device);
1284 } else if (!strcmp(name, "RAW")) {
1285 res = run_raw_mbr(offer_to_hack_scripts, device);
1286 }
[1]1287#ifdef __FreeBSD__
[128]1288 else if (!strcmp(name, "BOOT0")) {
[3185]1289 mr_asprintf(tmp, "boot0cfg -B %s", device);
[128]1290 res = run_program_and_log_output(tmp, FALSE);
[1873]1291 paranoid_free(tmp);
[128]1292 } else {
[3185]1293 mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
[128]1294 if (!system(tmp)) {
[3193]1295 mr_free(tmp);
[3185]1296 mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
[128]1297 res = run_program_and_log_output(tmp, 3);
1298 } else {
[3193]1299 log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
[128]1300 }
[3193]1301 mr_free(tmp);
[128]1302 }
[1]1303#else
[128]1304 else {
1305 log_to_screen
[541]1306 ("Unable to determine type of boot loader. Defaulting to LILO.");
[128]1307 res = run_lilo(offer_to_hack_scripts);
1308 }
[1]1309#endif
[128]1310 retval += res;
1311 if (res) {
[541]1312 log_to_screen("Your boot loader returned an error");
[128]1313 } else {
[541]1314 log_to_screen("Your boot loader ran OK");
[128]1315 }
1316 paranoid_free(device);
1317 paranoid_free(name);
1318 return (retval);
[1]1319}
[128]1320
[1]1321/**************************************************************************
1322 *END_ RUN_BOOT_LOADER *
1323 **************************************************************************/
1324
1325
1326
1327/**
1328 * Attempt to find the user's editor.
1329 * @return The editor found ("vi" if none could be found).
1330 * @note The returned string points to static storage that will be overwritten with each call.
1331 */
[3193]1332char *find_my_editor(void) {
1333
[128]1334 static char output[MAX_STR_LEN];
1335 if (find_home_of_exe("pico")) {
1336 strcpy(output, "pico");
1337 } else if (find_home_of_exe("nano")) {
1338 strcpy(output, "nano");
1339 } else if (find_home_of_exe("e3em")) {
1340 strcpy(output, "e3em");
1341 } else if (find_home_of_exe("e3vi")) {
1342 strcpy(output, "e3vi");
1343 } else {
1344 strcpy(output, "vi");
1345 }
1346 if (!find_home_of_exe(output)) {
1347 log_msg(2, " (find_my_editor) --- warning - %s not found", output);
1348 }
1349 return (output);
[1]1350}
1351
1352
1353/**
1354 * Install GRUB on @p bd.
1355 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1356 * @param bd The boot device where GRUB is installed.
1357 * @return 0 for success, nonzero for failure.
1358 */
[128]1359int run_grub(bool offer_to_run_stabgrub, char *bd)
[1]1360{
1361 /** malloc **/
[3193]1362 char *command = NULL;
1363 char *boot_device = NULL;
1364 char *tmp = NULL;
1365 char *editor = NULL;
[1]1366
[3193]1367 bool done;
[2950]1368 int res = 0; /* FALSE */
1369 bool mntlistchg = FALSE;
1370 FILE *fin = NULL;
[1]1371
[128]1372 malloc_string(boot_device);
[3193]1373
[128]1374 assert_string_is_neither_NULL_nor_zerolength(bd);
1375 strcpy(boot_device, bd);
1376
[3297]1377 if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
[128]1378 /* interactive mode */
[3297]1379 mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab, mtab, device.map and menu.lst/grub.cfg, and running GRUB...");
[2950]1380 /* Did we changed the mountlist ? If yes, then force editing conf files */
1381 if ((fin = fopen(MONDO_MNTLISTCHG, "r")) != NULL) {
1382 mntlistchg = TRUE;
1383 }
[128]1384 for (done = FALSE; !done;) {
[3297]1385 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/sda", boot_device, MAX_STR_LEN / 4);
[2950]1386 /* Only try to adapt grub here first if the mountlist wasn't changed before */
1387 if (! mntlistchg) {
[3193]1388 mr_asprintf(command, "stabgrub-me %s", boot_device);
[2950]1389 res = run_program_and_log_output(command, 1);
[3193]1390 mr_free(command);
[2950]1391 }
[3193]1392
1393 if ((res) || (mntlistchg)) {
[2950]1394 if (res) {
1395 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
1396 } else {
1397 popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
1398 }
[2904]1399 if (!g_text_mode) {
1400 newtSuspend();
1401 }
[3193]1402 mr_asprintf(editor, "%s", find_my_editor());
1403 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
[2904]1404 paranoid_system(tmp);
[3193]1405 mr_free(tmp);
1406
1407 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
[2904]1408 paranoid_system(tmp);
[3193]1409 mr_free(tmp);
1410
[2904]1411 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
[3193]1412 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
[2904]1413 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
[3193]1414 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
[2944]1415 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
[3193]1416 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
[2904]1417 }
1418 paranoid_system(tmp);
[3193]1419 mr_free(tmp);
1420
[2944]1421 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
[3193]1422 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
[2944]1423 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
[3193]1424 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
1425 }
[2904]1426 paranoid_system(tmp);
[3193]1427 mr_free(tmp);
1428 mr_free(editor);
1429
[2904]1430 if (!g_text_mode) {
1431 newtResume();
1432 }
[3193]1433 mr_asprintf(command, "stabgrub-me %s", boot_device);
[2904]1434 res = run_program_and_log_output(command, 1);
[3193]1435 mr_free(command);
1436
[2904]1437 if (res) {
[3193]1438 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
[2904]1439 newtSuspend();
[3076]1440 paranoid_system("chroot " MNT_RESTORING);
[2904]1441 newtResume();
1442 } else {
1443 popup_and_OK("GRUB is now installed correctly");
1444 done = TRUE;
1445 }
[128]1446 } else {
1447 done = TRUE;
1448 }
1449 }
[3193]1450 } else {
[128]1451 /* nuke mode */
[3193]1452 if (!run_program_and_log_output("which grub-MR", FALSE)) {
1453 log_msg(1, "Yay! grub-MR found...");
[3297]1454 mr_asprintf(command, "grub-MR %s /"MOUNTLIST_FNAME_STUB, boot_device);
[3193]1455 log_msg(1, "command = %s", command);
1456 } else {
[3297]1457 // Or grub2-install
[3193]1458 mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device);
1459 log_msg(1, "WARNING - grub-MR not found; using grub-install");
1460 }
1461 mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... ");
[2227]1462 log_it("%s",command);
[128]1463 res = run_program_and_log_output(command, 1);
[3193]1464 mr_free(command);
1465
[128]1466 if (res) {
[3299]1467 popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
[128]1468 newtSuspend();
[3076]1469 paranoid_system("chroot " MNT_RESTORING);
[128]1470 newtResume();
1471 }
[1]1472 }
[128]1473 if (res) {
[541]1474 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]1475 log_to_screen
[1315]1476 ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
[128]1477 log_msg(1, "Type:-");
1478 log_msg(1, " mount-me");
1479 log_msg(1, " chroot " MNT_RESTORING);
1480 log_msg(1, " mount /boot");
1481 log_msg(1, " grub-install '(hd0)'");
1482 log_msg(1, " exit");
1483 log_msg(1, " unmount-me");
1484 log_msg(1,
1485 "If you're really stuck, please e-mail the mailing list.");
1486 } else {
[541]1487 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]1488 }
1489 paranoid_free(boot_device);
[1]1490
[128]1491 return (res);
[1]1492}
[128]1493
[1]1494/**************************************************************************
1495 *END_RUN_GRUB *
1496 **************************************************************************/
1497
1498
1499/**
1500 * Install ELILO on the user's boot drive (determined by elilo.conf).
1501 * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
1502 * @return 0 for success, nonzero for failure.
1503 */
[128]1504int run_elilo(bool offer_to_run_stabelilo)
[1]1505{
1506 /** malloc **/
[3193]1507 char *command = NULL;
1508 char *tmp = NULL;
1509 char *editor = NULL;
[1]1510
[128]1511 int res;
1512 int done;
[1]1513
[128]1514 if (offer_to_run_stabelilo
[2094]1515 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
[1]1516
[128]1517 /* interactive mode */
1518 {
1519 mvaddstr_and_log_it(g_currentY,
1520 0,
[541]1521 "Modifying fstab and elilo.conf... ");
[3193]1522 mr_asprintf(command, "stabelilo-me");
[128]1523 res = run_program_and_log_output(command, 3);
[3193]1524 mr_free(command);
1525
[128]1526 if (res) {
1527 popup_and_OK
[541]1528 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
[128]1529 for (done = FALSE; !done;) {
1530 if (!g_text_mode) {
1531 newtSuspend();
1532 }
[3193]1533 mr_asprintf(editor, "%s", find_my_editor());
1534
1535 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
[128]1536 paranoid_system(tmp);
[3193]1537 mr_free(tmp);
1538
1539 mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
[128]1540 paranoid_system(tmp);
[3193]1541 mr_free(tmp);
1542 mr_free(editor);
1543
[128]1544 if (!g_text_mode) {
1545 newtResume();
1546 }
[1]1547// newtCls();
[541]1548 if (ask_me_yes_or_no("Edit them again?")) {
[128]1549 continue;
1550 }
1551 done = TRUE;
1552 }
1553 } else {
[541]1554 log_to_screen("elilo.conf and fstab were modified OK");
[1]1555 }
[128]1556 } else
1557 /* nuke mode */
[1]1558 {
[128]1559 res = TRUE;
[1]1560 }
[128]1561 return (res);
1562}
[1]1563
1564/**************************************************************************
1565 *END_RUN_ELILO *
1566 **************************************************************************/
1567
1568
1569/**
1570 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1571 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1572 * @return 0 for success, nonzero for failure.
1573 */
[128]1574int run_lilo(bool offer_to_run_stablilo)
[1]1575{
1576 /** malloc **/
[3193]1577 char *command = NULL;
1578 char *tmp = NULL;
1579 char *editor = NULL;
[1]1580
[128]1581 int res;
1582 int done;
1583 bool run_lilo_M = FALSE;
[1]1584
[128]1585 if (!run_program_and_log_output
1586 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1587 run_lilo_M = TRUE;
1588 }
[1]1589
[128]1590 if (offer_to_run_stablilo
[2094]1591 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
[1]1592
[128]1593 /* interactive mode */
1594 {
1595 mvaddstr_and_log_it(g_currentY,
1596 0,
[541]1597 "Modifying fstab and lilo.conf, and running LILO... ");
[3193]1598 mr_asprintf(command, "stablilo-me");
[128]1599 res = run_program_and_log_output(command, 3);
[3193]1600 mr_free(command);
1601
[128]1602 if (res) {
1603 popup_and_OK
[541]1604 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
[128]1605 for (done = FALSE; !done;) {
1606 if (!g_text_mode) {
1607 newtSuspend();
1608 }
[3193]1609 mr_asprintf(editor, "%s", find_my_editor());
1610
1611 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
[128]1612 paranoid_system(tmp);
[3193]1613 mr_free(tmp);
1614
1615 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
[128]1616 paranoid_system(tmp);
[3193]1617 mr_free(tmp);
1618 mr_free(editor);
1619
[128]1620 if (!g_text_mode) {
1621 newtResume();
1622 }
[1]1623// newtCls();
[541]1624 if (ask_me_yes_or_no("Edit them again?")) {
[128]1625 continue;
1626 }
1627 res =
1628 run_program_and_log_output("chroot " MNT_RESTORING
1629 " lilo -L", 3);
1630 if (res) {
1631 res =
1632 run_program_and_log_output("chroot " MNT_RESTORING
1633 " lilo", 3);
1634 }
1635 if (res) {
1636 done =
1637 ask_me_yes_or_no
[541]1638 ("LILO failed. Re-edit system files?");
[128]1639 } else {
1640 done = TRUE;
1641 }
1642 }
1643 } else {
[541]1644 log_to_screen("lilo.conf and fstab were modified OK");
[1]1645 }
[128]1646 } else
1647 /* nuke mode */
1648 {
1649 mvaddstr_and_log_it(g_currentY,
1650 0,
[541]1651 "Running LILO... ");
[128]1652 res =
1653 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1654 3);
1655 if (res) {
1656 res =
1657 run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1658 3);
[1]1659 }
[128]1660 if (res) {
[541]1661 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]1662 log_to_screen
[541]1663 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
[128]1664 } else {
[541]1665 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]1666 }
[1]1667 }
[128]1668 if (run_lilo_M) {
1669 run_program_and_log_output("chroot " MNT_RESTORING
1670 " lilo -M /dev/hda", 3);
1671 run_program_and_log_output("chroot " MNT_RESTORING
1672 " lilo -M /dev/sda", 3);
[1]1673 }
[128]1674 return (res);
1675}
[1]1676
1677/**************************************************************************
1678 *END_RUN_LILO *
1679 **************************************************************************/
1680
1681
1682/**
1683 * Install a raw MBR onto @p bd.
1684 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1685 * @param bd The device to copy the stored MBR to.
1686 * @return 0 for success, nonzero for failure.
1687 */
[128]1688int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
[1]1689{
1690 /** malloc **/
[3193]1691 char *command = NULL;
1692 char *boot_device = NULL;
1693 char *tmp = NULL;
[128]1694 char *editor;
1695 int res;
1696 int done;
[1]1697
[128]1698 malloc_string(boot_device);
1699 assert_string_is_neither_NULL_nor_zerolength(bd);
[1]1700
[128]1701 strcpy(boot_device, bd);
[1]1702
[128]1703 if (offer_to_hack_scripts
[3193]1704 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
[128]1705 /* interactive mode */
[3383]1706 mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab and restoring MBR... ");
[128]1707 for (done = FALSE; !done;) {
1708 if (!run_program_and_log_output("which vi", FALSE)) {
[541]1709 popup_and_OK("You will now edit fstab");
[128]1710 if (!g_text_mode) {
1711 newtSuspend();
1712 }
[3193]1713 mr_asprintf(editor, "%s", find_my_editor());
1714 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1715 mr_free(editor);
1716
[128]1717 paranoid_system(tmp);
[3193]1718 mr_free(tmp);
[128]1719 if (!g_text_mode) {
1720 newtResume();
1721 }
1722 }
[3193]1723 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4);
1724 mr_asprintf(command, "stabraw-me %s", boot_device);
[128]1725 res = run_program_and_log_output(command, 3);
[3193]1726 mr_free(command);
1727
[128]1728 if (res) {
[541]1729 done = ask_me_yes_or_no("Modifications failed. Re-try?");
[128]1730 } else {
1731 done = TRUE;
1732 }
1733 }
[3193]1734 } else {
[128]1735 /* nuke mode */
[3297]1736 mr_asprintf(command, "raw-MR %s /"MOUNTLIST_FNAME_STUB, boot_device);
[3193]1737 log_msg(2, "run_raw_mbr() --- command='%s'", command);
1738
[3383]1739 mvaddstr_and_log_it(g_currentY, 0, "Restoring MBR... ");
[128]1740 res = run_program_and_log_output(command, 3);
[3193]1741 mr_free(command);
[1]1742 }
[128]1743 if (res) {
[541]1744 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[3383]1745 log_to_screen("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
[128]1746 } else {
[541]1747 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]1748 }
1749 paranoid_free(boot_device);
1750 return (res);
[1]1751}
[128]1752
[1]1753/**************************************************************************
1754 *END_RUN_RAW_MBR *
1755 **************************************************************************/
1756
1757
1758
1759/**
1760 * malloc() and set sensible defaults for the mondorestore filename variables.
1761 * @param bkpinfo The backup information structure. Fields used:
1762 * - @c bkpinfo->tmpdir
1763 * - @c bkpinfo->disaster_recovery
1764 */
[1645]1765void setup_MR_global_filenames()
[1]1766{
[128]1767 char *temppath;
[1]1768
[128]1769 assert(bkpinfo != NULL);
[1]1770
[128]1771 malloc_string(g_biggielist_txt);
1772 malloc_string(g_filelist_full);
1773 malloc_string(g_filelist_imagedevs);
1774 malloc_string(g_imagedevs_restthese);
1775 malloc_string(g_mondo_cfg_file);
1776 malloc_string(g_mountlist_fname);
1777 malloc_string(g_mondo_home);
1778 malloc_string(g_isodir_device);
1779 malloc_string(g_isodir_format);
[1]1780
[128]1781 temppath = bkpinfo->tmpdir;
[1]1782
[128]1783 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
1784 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
1785 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
[1]1786// sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
[128]1787 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
1788 temppath);
1789 if (bkpinfo->disaster_recovery) {
1790 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
1791 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
1792 } else {
1793 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
[3297]1794 sprintf(g_mountlist_fname, "%s/%s", temppath, MOUNTLIST_FNAME_STUB);
[128]1795 }
[1]1796}
[128]1797
[1]1798/**************************************************************************
1799 *END_SET_GLOBAL_FILENAME *
1800 **************************************************************************/
1801
1802
1803/**
1804 * Copy @p input_file (containing the result of a compare) to @p output_file,
1805 * deleting spurious "changes" along the way.
1806 * @param output_file The output file to write with spurious changes removed.
1807 * @param input_file The input file, a list of changed files created by a compare.
1808 */
[128]1809void streamline_changes_file(char *output_file, char *input_file)
[1]1810{
[128]1811 FILE *fin;
1812 FILE *fout;
[3193]1813 char *incoming = NULL;
[1]1814
[128]1815 assert_string_is_neither_NULL_nor_zerolength(output_file);
1816 assert_string_is_neither_NULL_nor_zerolength(input_file);
1817
1818 if (!(fin = fopen(input_file, "r"))) {
1819 log_OS_error(input_file);
1820 return;
1821 }
1822 if (!(fout = fopen(output_file, "w"))) {
1823 fatal_error("cannot open output_file");
1824 }
[3193]1825 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
[128]1826 if (strncmp(incoming, "etc/adjtime", 11)
1827 && strncmp(incoming, "etc/mtab", 8)
1828 && strncmp(incoming, "tmp/", 4)
1829 && strncmp(incoming, "boot/map", 8)
1830 && !strstr(incoming, "incheckentry")
1831 && strncmp(incoming, "etc/mail/statistics", 19)
1832 && strncmp(incoming, "var/", 4))
1833 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
[3193]1834 mr_free(incoming);
[128]1835 }
[3193]1836 mr_free(incoming);
[128]1837 paranoid_fclose(fout);
1838 paranoid_fclose(fin);
[1]1839}
[128]1840
[1]1841/**************************************************************************
1842 *END_STREAMLINE_CHANGES_FILE *
1843 **************************************************************************/
1844
1845
1846/**
1847 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
1848 */
[128]1849void twenty_seconds_til_yikes()
[1]1850{
[128]1851 int i;
1852 /* MALLOC * */
[3193]1853 char *tmp = NULL;
[1]1854
[128]1855 if (does_file_exist("/tmp/NOPAUSE")) {
1856 return;
1857 }
[541]1858 open_progress_form("CAUTION",
1859 "Be advised: I am about to ERASE your hard disk(s)!",
1860 "You may press Ctrl+Alt+Del to abort safely.",
[128]1861 "", 20);
1862 for (i = 0; i < 20; i++) {
1863 g_current_progress = i;
[3193]1864 mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i);
[128]1865 update_progress_form(tmp);
[3193]1866 mr_free(tmp);
[128]1867 sleep(1);
1868 }
1869 close_progress_form();
[1]1870}
[128]1871
[1]1872/**************************************************************************
1873 *END_TWENTY_SECONDS_TIL_YIKES *
1874 **************************************************************************/
1875
1876
1877/**
1878 * Unmount all devices in @p p_external_copy_of_mountlist.
1879 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
1880 * @return 0 for success, nonzero for failure.
1881 */
[128]1882int unmount_all_devices(struct mountlist_itself
1883 *p_external_copy_of_mountlist)
[1]1884{
[128]1885 struct mountlist_itself *mountlist;
1886 int retval = 0, lino, res = 0, i;
[3193]1887 char *command = NULL;
[2211]1888 char *tmp = NULL;
[1]1889
[128]1890 assert(p_external_copy_of_mountlist != NULL);
[1]1891
[128]1892 mountlist = malloc(sizeof(struct mountlist_itself));
[3301]1893 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
[128]1894 sort_mountlist_by_mountpoint(mountlist, 0);
[1]1895
[3193]1896 run_program_and_log_output("df -m -P", 3);
[541]1897 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
[3301]1898 open_progress_form("Unmounting devices", "Unmounting all devices that were mounted,", "in preparation for the post-restoration reboot.", "", mountlist->entries);
[3076]1899 if (chdir("/")) {
1900 // FIXME
1901 }
[3301]1902 for (i = 0; i < 10 && run_program_and_log_output("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++) {
[128]1903 sleep(1);
1904 log_msg(2, "Waiting for buffer() to finish");
1905 }
[1]1906
[3193]1907 sync();
[1]1908
[3185]1909 mr_asprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
[1322]1910 if (run_program_and_log_output(tmp, FALSE)) {
[3301]1911 log_msg(1, "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)");
[1]1912 }
[2211]1913 paranoid_free(tmp);
[128]1914 if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
[3301]1915 run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5);
[1]1916 }
[1971]1917
1918 /* Unmounting the local /proc and /sys first */
[3193]1919 run_program_and_log_output("umount -d " MNT_RESTORING "/proc",3);
1920 run_program_and_log_output("umount -d " MNT_RESTORING "/sys",3);
[1971]1921
[128]1922 for (lino = mountlist->entries - 1; lino >= 0; lino--) {
1923 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
1924 continue;
1925 }
[3185]1926 mr_asprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
[128]1927 update_progress_form(tmp);
[2211]1928
[128]1929 if (is_this_device_mounted(mountlist->el[lino].device)) {
1930 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
[3193]1931 mr_asprintf(command, "swapoff %s", mountlist->el[lino].device);
[128]1932 } else {
1933 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
[3193]1934 mr_asprintf(command, "umount -d %s/", MNT_RESTORING);
[128]1935 log_msg(3,
1936 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
1937 } else {
[3193]1938 mr_asprintf(command, "umount -d " MNT_RESTORING "%s", mountlist->el[lino].mountpoint);
[2144]1939
1940 /* To support latest Ubuntu where /var is a separate FS
1941 * Cf: http://linux.derkeiler.com/Mailing-Lists/Ubuntu/2007-04/msg01319.html
1942 * we need to create some dirs under the real / before unmounting it */
1943 if (!strcmp(mountlist->el[lino].mountpoint, "/")) {
1944 run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/lock", FALSE);
1945 run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run", FALSE);
1946 }
[128]1947 }
1948 }
1949 log_msg(10, "The 'umount' command is '%s'", command);
1950 res = run_program_and_log_output(command, 3);
[3193]1951 mr_free(command);
[128]1952 } else {
[2211]1953 mr_strcat(tmp, "...not mounted anyway :-) OK");
[128]1954 res = 0;
1955 }
1956 g_current_progress++;
1957 if (res) {
[2211]1958 mr_strcat(tmp, "...Failed");
[128]1959 retval++;
1960 log_to_screen(tmp);
1961 } else {
1962 log_msg(2, tmp);
1963 }
[2211]1964 paranoid_free(tmp);
[128]1965 }
1966 close_progress_form();
1967 if (retval) {
[541]1968 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]1969 } else {
[541]1970 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]1971 }
1972 if (retval) {
[541]1973 log_to_screen("Unable to unmount some of your partitions.");
[128]1974 } else {
[541]1975 log_to_screen("All partitions were unmounted OK.");
[128]1976 }
1977 free(mountlist);
1978 return (retval);
[1]1979}
[128]1980
[1]1981/**************************************************************************
1982 *END_UNMOUNT_ALL_DEVICES *
1983 **************************************************************************/
1984
1985/**
[3271]1986 * Extract mondorestore.cfg and the mountlist from the tape inserted
[1]1987 * to the ./tmp/ directory.
1988 * @param dev The tape device to read from.
1989 * @return 0 for success, nonzero for failure.
1990 */
[128]1991int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
[1]1992{
[3193]1993 char *command = NULL;
[128]1994 int res = 0;
[1]1995
[1968]1996 if (bkpinfo->use_obdr) {
1997 skip_obdr();
[1990]1998 } else {
1999 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
2000 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
[1968]2001 }
[1990]2002
[3193]2003 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
[128]2004 log_msg(2, "command = '%s'", command);
2005 res = run_program_and_log_output(command, -1);
[3193]2006 mr_free(command);
2007
[2029]2008 if (res != 0) {
2009 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2010 res = 0;
2011 } else {
2012 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
2013 log_msg(2, "pre-2.2.4 compatible mode on");
[3194]2014 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
[2029]2015 log_msg(2, "command = '%s'", command);
2016 res = run_program_and_log_output(command, -1);
[3193]2017 mr_free(command);
[2029]2018 if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {
2019 res = 0;
2020 }
2021 }
[128]2022 }
2023 paranoid_free(command);
2024 return (res);
[1]2025}
2026
[128]2027
[1]2028/**
2029 * Get the configuration file from the floppy, tape, or CD.
2030 * @param bkpinfo The backup information structure. Fields used:
2031 * - @c bkpinfo->backup_media_type
2032 * - @c bkpinfo->media_device
2033 * - @c bkpinfo->tmpdir
2034 * @return 0 for success, nonzero for failure.
2035 */
[1645]2036int get_cfg_file_from_archive()
[1]2037{
[128]2038 int retval = 0;
2039
[1]2040 /** malloc *****/
[3193]2041 char *command = NULL;
2042 char *cfg_file = NULL;
2043 char *tmp = NULL;
2044 char *mountpt = NULL;
2045 char *mountlist_file = NULL;
[2206]2046 bool extract_mountlist_stub = FALSE;
2047 bool extract_i_want_my_lvm = FALSE;
[1]2048
[128]2049 bool try_plan_B;
2050
2051 assert(bkpinfo != NULL);
2052 log_msg(2, "gcffa --- starting");
[541]2053 log_to_screen("I'm thinking...");
[3193]2054 mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
[3076]2055 if (chdir(bkpinfo->tmpdir)) {
2056 // FIXME
2057 }
[3193]2058 mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB);
[128]2059 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
[3193]2060 mr_free(cfg_file);
2061
[128]2062 unlink(FILELIST_FULL_STUB);
2063 unlink(BIGGIELIST_TXT_STUB);
[3194]2064 mr_asprintf(command, "mkdir -p %s", mountpt);
[128]2065 run_program_and_log_output(command, FALSE);
[3193]2066 mr_free(command);
[128]2067
[3193]2068 mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2069 mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
[128]2070 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
[3193]2071 mr_free(mountpt);
[128]2072
2073 if (!does_file_exist(cfg_file)) {
2074 log_msg(2, "gcffa --- we don't have cfg file yet.");
2075 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2076 try_plan_B = TRUE;
2077 } else {
[1736]2078 log_msg(2, "gcffa --- calling mount_media now :)");
2079 if (!mount_media()) {
[3263]2080 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B");
[128]2081 try_plan_B = FALSE;
2082 } else {
2083 try_plan_B = TRUE;
2084 }
[1645]2085 if (what_number_cd_is_this() > 1) {
2086 insist_on_this_cd_number((g_current_media_number = 1));
[128]2087 }
2088 }
2089 if (try_plan_B) {
2090 log_msg(2, "gcffa --- OK, switching to Plan B");
[3076]2091 if (chdir(bkpinfo->tmpdir)) {
2092 // FIXME
2093 }
[128]2094 run_program_and_log_output("mkdir -p tmp", FALSE);
[1]2095
[128]2096 if (strlen(bkpinfo->media_device) == 0) {
2097 strcpy(bkpinfo->media_device, "/dev/st0");
2098 log_msg(2, "media_device is blank; assuming %s");
2099 }
[3193]2100 mr_asprintf(tmp, "%s", bkpinfo->media_device);
[128]2101 if (extract_cfg_file_and_mountlist_from_tape_dev
2102 (bkpinfo->media_device)) {
2103 strcpy(bkpinfo->media_device, "/dev/st0");
2104 if (extract_cfg_file_and_mountlist_from_tape_dev
2105 (bkpinfo->media_device)) {
2106 strcpy(bkpinfo->media_device, "/dev/osst0");
2107 if (extract_cfg_file_and_mountlist_from_tape_dev
2108 (bkpinfo->media_device)) {
2109 strcpy(bkpinfo->media_device, "/dev/ht0");
2110 if (extract_cfg_file_and_mountlist_from_tape_dev
2111 (bkpinfo->media_device)) {
2112 log_msg(3,
2113 "I tried lots of devices but none worked.");
2114 strcpy(bkpinfo->media_device, tmp);
2115 }
2116 }
2117 }
2118 }
[3193]2119 mr_free(tmp);
[1]2120
[3271]2121 if (!does_file_exist("tmp/mondorestore.cfg")) {
[1885]2122 log_to_screen("Cannot find config info on media");
[128]2123 return (1);
2124 }
2125 } else {
[2049]2126 if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
2127 extract_mountlist_stub = FALSE;
2128 } else {
2129 extract_mountlist_stub = TRUE;
2130 }
2131 if (does_file_exist("/"IWANTMYLVM_STUB)) {
2132 extract_i_want_my_lvm = FALSE;
2133 } else {
2134 extract_i_want_my_lvm = TRUE;
2135 }
2136
[3263]2137 log_msg(2, "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
[3193]2138 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
[128]2139 run_program_and_log_output(command, TRUE);
[3193]2140 mr_free(command);
2141
[128]2142 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
[2029]2143 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
2144 log_msg(2, "pre-2.2.4 compatible mode on");
[3193]2145 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
[2029]2146 run_program_and_log_output(command, TRUE);
[3193]2147 mr_free(command);
[2029]2148 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2149 fatal_error
2150 ("Please reinsert the disk/CD and try again.");
2151 }
[128]2152 }
[1]2153 }
[128]2154 }
2155 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2156 log_msg(1, "gcffa --- great! We've got the config file");
[3193]2157 mr_asprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB);
2158 mr_asprintf(command, "cp -f %s %s", tmp, cfg_file);
[2227]2159 log_it("%s",command);
[3263]2160 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
[128]2161 log_msg(1,
2162 "... but an error occurred when I tried to move it to %s",
2163 cfg_file);
2164 } else {
2165 log_msg(1, "... and I moved it successfully to %s", cfg_file);
2166 }
[3193]2167 mr_free(command);
2168
2169 mr_asprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file);
[2227]2170 log_it("%s",command);
[2049]2171 if (extract_mountlist_stub) {
[3263]2172 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
[2049]2173 log_msg(1, "Failed to get mountlist");
[128]2174 } else {
[2049]2175 log_msg(1, "Got mountlist too");
[3193]2176 mr_free(command);
2177 mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
[2049]2178 if (run_program_and_log_output(command, 1)) {
2179 log_msg(1, "Failed to copy mountlist to /tmp");
2180 } else {
2181 log_msg(1, "Copied mountlist to /tmp as well OK");
[3193]2182 mr_free(command);
2183 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
[2049]2184 run_program_and_log_output(command, 1);
2185 }
[128]2186 }
2187 }
[3193]2188 mr_free(command);
2189 mr_free(tmp);
[128]2190 }
[3193]2191
[2878]2192 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
[128]2193 if (!does_file_exist(cfg_file)) {
[2227]2194 log_it("%s",cfg_file);
[128]2195 log_msg(1, "%s not found", cfg_file);
[3263]2196 log_to_screen("Oh dear. Unable to recover configuration file from boot disk");
[128]2197 return (1);
2198 }
[1]2199
[3271]2200 log_to_screen("Recovered mondorestore.cfg");
[128]2201 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
[541]2202 log_to_screen("...but not mountlist.txt - a pity, really...");
[3263]2203 } else {
[2049]2204 /* Is this code really useful ??? */
2205 if (extract_mountlist_stub) {
[3193]2206 mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
[2049]2207 run_program_and_log_output(command, FALSE);
[3193]2208 mr_free(command);
[2049]2209 }
[128]2210 }
[1]2211
[3193]2212 mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
2213 mr_free(cfg_file);
2214
[128]2215 run_program_and_log_output(command, FALSE);
[3193]2216 mr_free(command);
2217
[2049]2218 if (extract_mountlist_stub) {
[3193]2219 mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
[2049]2220 run_program_and_log_output(command, FALSE);
[3193]2221 mr_free(command);
[2049]2222 }
[3193]2223 mr_free(mountlist_file);
2224
2225 mr_asprintf(command, "cp -f etc/raidtab /etc/");
[128]2226 run_program_and_log_output(command, FALSE);
[3193]2227 mr_free(command);
2228
[2049]2229 if (extract_i_want_my_lvm) {
[3193]2230 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
[2049]2231 run_program_and_log_output(command, FALSE);
[3193]2232 mr_free(command);
[2049]2233 }
[128]2234 g_backup_media_type = bkpinfo->backup_media_type;
2235 return (retval);
[1]2236}
2237
2238/**************************************************************************
2239 *END_GET_CFG_FILE_FROM_ARCHIVE *
2240 **************************************************************************/
2241
2242/* @} - end restoreUtilityGroup */
2243
[2982]2244void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage)
[1]2245{
[558]2246 struct raidlist_itself *raidlist;
[2982]2247 int unfinished_mdstat_devices = 9999;
2248 int i = 0;
[3193]2249 char *screen_message = NULL;
[1]2250
[558]2251 raidlist = malloc(sizeof(struct raidlist_itself));
[128]2252
2253 assert(wait_for_percentage <= 100);
[2230]2254 log_it("wait_until_software_raids_are_prepped");
[128]2255 while (unfinished_mdstat_devices > 0) {
[558]2256 // FIXME: Prefix '/dev/' should really be dynamic!
[2982]2257 if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
[558]2258 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
2259 log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
[128]2260 return;
[1]2261 }
[2982]2262 for (unfinished_mdstat_devices = 0; i <= raidlist->entries; i++) {
[558]2263 if (raidlist->el[i].progress < wait_for_percentage) {
[128]2264 unfinished_mdstat_devices++;
[704]2265 if (raidlist->el[i].progress == -1) // delayed while another partition inits
2266 {
2267 continue;
2268 }
[558]2269 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
[3193]2270 mr_asprintf(screen_message, "Sync'ing %s", raidlist->el[i].raid_device);
[128]2271 open_evalcall_form(screen_message);
[3193]2272 mr_free(screen_message);
2273
[558]2274 while (raidlist->el[i].progress < wait_for_percentage) {
2275 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
2276 update_evalcall_form(raidlist->el[i].progress);
[128]2277 sleep(2);
[558]2278 // FIXME: Prefix '/dev/' should really be dynamic!
[2982]2279 if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
[128]2280 break;
2281 }
2282 }
2283 close_evalcall_form();
2284 }
[1]2285 }
[128]2286 }
[558]2287 paranoid_free(raidlist);
[3194]2288}
Note: See TracBrowser for help on using the repository browser.