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