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