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