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

Last change on this file since 3905 was 3901, checked in by Bruno Cornec, 9 months ago

mount_media done in what_number_cd_is_this

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