source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.c@ 3862

Last change on this file since 3862 was 3854, checked in by Bruno Cornec, 5 months ago

Fix mr_popup_and_get_string proto

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