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

Last change on this file since 3889 was 3889, checked in by Bruno Cornec, 3 months ago

Remove EFI references for ia64

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