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