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