[1178] | 1 | /* $Id: libmondo-tools.c 1663 2007-09-27 10:21:18Z bruno $
|
---|
| 2 | misc tools
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * @file
|
---|
| 7 | * Miscellaneous tools that didn't really fit anywhere else.
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #include "my-stuff.h"
|
---|
[1080] | 11 | #include "mr_mem.h"
|
---|
[1123] | 12 | #include "mr_msg.h"
|
---|
[1087] | 13 | #include "mr_file.h"
|
---|
[1549] | 14 | #include "mr_gettext.h"
|
---|
[1592] | 15 | #include "mr_conf.h"
|
---|
[1095] | 16 |
|
---|
[1] | 17 | #include "mondostructures.h"
|
---|
| 18 | #include "libmondo-tools.h"
|
---|
[1178] | 19 | #include "newt-specific-EXT.h"
|
---|
[1] | 20 | #include "libmondo-files-EXT.h"
|
---|
| 21 | #include "libmondo-fork-EXT.h"
|
---|
| 22 | #include "libmondo-raid-EXT.h"
|
---|
| 23 | #include <sys/socket.h>
|
---|
| 24 | #include <netdb.h>
|
---|
[1663] | 25 | #include <stdlib.h>
|
---|
[1] | 26 | #include <netinet/in.h>
|
---|
| 27 | #include <arpa/inet.h>
|
---|
[1377] | 28 | #include <sys/utsname.h>
|
---|
[1] | 29 |
|
---|
| 30 | /*@unused@*/
|
---|
[99] | 31 | //static char cvsid[] = "$Id: libmondo-tools.c 1663 2007-09-27 10:21:18Z bruno $";
|
---|
[1] | 32 |
|
---|
| 33 | extern int g_tape_buffer_size_MB;
|
---|
| 34 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
| 35 | extern char *g_serial_string;
|
---|
| 36 | extern bool g_text_mode;
|
---|
| 37 | extern int g_currentY;
|
---|
| 38 | extern int g_current_media_number;
|
---|
[1344] | 39 | extern char *MONDO_LOGFILE;
|
---|
[1] | 40 |
|
---|
[1592] | 41 | extern struct mr_ar_conf *mr_conf;
|
---|
| 42 |
|
---|
[1663] | 43 | /* Reference to global bkpinfo */
|
---|
| 44 | extern struct s_bkpinfo *bkpinfo;
|
---|
| 45 |
|
---|
[1] | 46 | /**
|
---|
| 47 | * @addtogroup globalGroup
|
---|
| 48 | * @{
|
---|
| 49 | */
|
---|
[128] | 50 | bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
|
---|
| 51 | g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
|
---|
| 52 | bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
|
---|
[1] | 53 | double g_kernel_version;
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
[1178] | 56 | * The place where /boot is mounted. - Used locally only
|
---|
[1] | 57 | */
|
---|
[1178] | 58 | static char *g_boot_mountpt = NULL;
|
---|
[1] | 59 |
|
---|
| 60 | /**
|
---|
| 61 | * The serial string (used to differentiate between backups) of the current backup.
|
---|
| 62 | */
|
---|
[128] | 63 | char *g_serial_string = NULL;
|
---|
[1] | 64 |
|
---|
| 65 | /**
|
---|
| 66 | * The location where tmpfs is mounted, or "" if it's not mounted.
|
---|
| 67 | */
|
---|
[128] | 68 | char *g_tmpfs_mountpt = NULL;
|
---|
| 69 | char *g_magicdev_command = NULL;
|
---|
[1] | 70 |
|
---|
| 71 | /* @} - end of globalGroup */
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | extern pid_t g_buffer_pid;
|
---|
| 75 | extern pid_t g_main_pid;
|
---|
| 76 |
|
---|
| 77 | extern t_bkptype g_backup_media_type;
|
---|
[1178] | 78 | extern char *g_backup_media_string;
|
---|
[1] | 79 |
|
---|
| 80 | extern bool am_I_in_disaster_recovery_mode(void);
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * @addtogroup utilityGroup
|
---|
| 85 | * @{
|
---|
| 86 | */
|
---|
| 87 | /**
|
---|
| 88 | * Assertion handler. Prints a friendly message to the user,
|
---|
| 89 | * offering to ignore all, dump core, break to debugger,
|
---|
| 90 | * exit, or ignore. Intended to be used with an assert() macro.
|
---|
| 91 | *
|
---|
| 92 | * @param file The file in which the assertion triggered.
|
---|
| 93 | * @param function The function (@c __FUNCTION__) in which the assertion triggered.
|
---|
| 94 | * @param line The line number of the assert() statement.
|
---|
| 95 | * @param exp The expression that failed (as a string).
|
---|
| 96 | */
|
---|
[128] | 97 | void _mondo_assert_fail(const char *file,
|
---|
| 98 | const char *function, int line, const char *exp)
|
---|
[1] | 99 | {
|
---|
[128] | 100 | static int ignoring_assertions = 0;
|
---|
| 101 | bool is_valid = TRUE;
|
---|
[1] | 102 |
|
---|
[128] | 103 | log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
|
---|
| 104 | function);
|
---|
| 105 | if (ignoring_assertions) {
|
---|
| 106 | log_it("Well, the user doesn't care...");
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
[1] | 109 | #ifndef _XWIN
|
---|
[128] | 110 | if (!g_text_mode)
|
---|
| 111 | newtSuspend();
|
---|
[1] | 112 | #endif
|
---|
[1178] | 113 | printf(_("ASSERTION FAILED: `%s'\n"), exp);
|
---|
| 114 | printf(_("\tat %s:%d in %s\n\n"), file, line, function);
|
---|
| 115 | printf(_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
|
---|
[128] | 116 | do {
|
---|
| 117 | is_valid = TRUE;
|
---|
| 118 | switch (toupper(getchar())) {
|
---|
| 119 | case 'A': // ignore (A)ll
|
---|
| 120 | ignoring_assertions = 1;
|
---|
| 121 | break;
|
---|
| 122 | case 'B': // a(B)ort
|
---|
| 123 | signal(SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
|
---|
| 124 | raise(SIGABRT);
|
---|
| 125 | break; /* "can't get here" */
|
---|
| 126 | case 'D': // (D)ebug, aka asm("int 3")
|
---|
[1] | 127 | #ifdef __IA32__
|
---|
[128] | 128 | __asm__ __volatile__("int $3"); // break to debugger
|
---|
[1] | 129 | #endif
|
---|
[128] | 130 | break;
|
---|
| 131 | case 'E': // (E)xit
|
---|
| 132 | fatal_error("Failed assertion -- see above for details");
|
---|
| 133 | break; /* "can't get here" */
|
---|
| 134 | case 'I': // (I)gnore
|
---|
| 135 | break;
|
---|
| 136 | /* These next two work as follows:
|
---|
| 137 | the `default' catches the user's invalid choice and says so;
|
---|
| 138 | the '\n' catches the newline on the end and prints the prompt again.
|
---|
| 139 | */
|
---|
| 140 | case '\n':
|
---|
| 141 | printf
|
---|
[1178] | 142 | (_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
|
---|
[128] | 143 | break;
|
---|
| 144 | default:
|
---|
| 145 | is_valid = FALSE;
|
---|
[1178] | 146 | printf(_("Invalid choice.\n"));
|
---|
[128] | 147 | break;
|
---|
| 148 | }
|
---|
| 149 | } while (!is_valid);
|
---|
| 150 |
|
---|
| 151 | if (ignoring_assertions) {
|
---|
| 152 | log_it("Ignoring ALL assertions from now on.");
|
---|
| 153 | } else {
|
---|
| 154 | log_it("Ignoring assertion: %s", exp);
|
---|
[1] | 155 | }
|
---|
| 156 |
|
---|
[128] | 157 | getchar(); // skip \n
|
---|
[1] | 158 |
|
---|
| 159 | #ifndef _XWIN
|
---|
[128] | 160 | if (!g_text_mode)
|
---|
| 161 | newtResume();
|
---|
[1] | 162 | #endif
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /**
|
---|
| 166 | * Clean's up users' KDE desktops.
|
---|
| 167 | * @bug Details about this function are unknown.
|
---|
| 168 | */
|
---|
| 169 | void clean_up_KDE_desktop_if_necessary(void)
|
---|
| 170 | {
|
---|
[128] | 171 | char *tmp;
|
---|
[1] | 172 |
|
---|
[1178] | 173 | mr_asprintf(&tmp,
|
---|
| 174 | "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
|
---|
[1] | 175 | file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
|
---|
[273] | 176 | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
|
---|
[275] | 177 | else { print $0;};}' $file.old > $file ; fi ; done");
|
---|
[128] | 178 | run_program_and_log_output(tmp, 5);
|
---|
[1080] | 179 | mr_free(tmp);
|
---|
[1] | 180 | }
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | /**
|
---|
[1061] | 184 | * Locate mondoarchive's home directory. Searches in /usr/share/mondo,
|
---|
[1] | 185 | * /usr/local/share/mondo, /opt, or if all else fails, search /usr.
|
---|
| 186 | *
|
---|
| 187 | * @param home_sz String to store the home directory ("" if it could not be found).
|
---|
| 188 | * @return 0 for success, nonzero for failure.
|
---|
| 189 | */
|
---|
| 190 | int find_and_store_mondoarchives_home(char *home_sz)
|
---|
| 191 | {
|
---|
[128] | 192 | assert(home_sz != NULL);
|
---|
[424] | 193 | strcpy(home_sz, MONDO_SHARE);
|
---|
[182] | 194 | return (0);
|
---|
[1] | 195 | }
|
---|
| 196 |
|
---|
| 197 |
|
---|
[1377] | 198 | char *get_architecture(void) {
|
---|
[1] | 199 | #ifdef __IA32__
|
---|
[1377] | 200 | # ifdef __X86_64__
|
---|
| 201 | return ("x86_64");
|
---|
| 202 | # else
|
---|
| 203 | return ("i386");
|
---|
| 204 | # endif
|
---|
[1] | 205 | #endif
|
---|
[1178] | 206 | #ifdef __X86_64__
|
---|
| 207 | return ("x86_64");
|
---|
| 208 | #endif
|
---|
[1] | 209 | #ifdef __IA64__
|
---|
[128] | 210 | return ("ia64");
|
---|
[1] | 211 | #endif
|
---|
[128] | 212 | return ("unknown");
|
---|
[1] | 213 | }
|
---|
| 214 |
|
---|
| 215 |
|
---|
[1377] | 216 | char *get_uname_m(void) {
|
---|
| 217 |
|
---|
| 218 | struct utsname utsn;
|
---|
| 219 | char *tmp = NULL;
|
---|
| 220 |
|
---|
| 221 | uname(&utsn);
|
---|
| 222 | mr_asprintf(&tmp, utsn.machine);
|
---|
| 223 | return (tmp);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 |
|
---|
[1178] | 228 | /* BERLIOS: Use uname instead */
|
---|
[1152] | 229 | double get_kernel_version(void)
|
---|
[1] | 230 | {
|
---|
[128] | 231 | char *p, tmp[200];
|
---|
| 232 | double d;
|
---|
[1] | 233 | #ifdef __FreeBSD__
|
---|
[128] | 234 | // JOSH - FIXME :)
|
---|
| 235 | d = 5.2; // :-)
|
---|
[1] | 236 | #else
|
---|
[128] | 237 | strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
|
---|
| 238 | p = strchr(tmp, '.');
|
---|
| 239 | if (p) {
|
---|
| 240 | p = strchr(++p, '.');
|
---|
| 241 | if (p) {
|
---|
| 242 | while (*p) {
|
---|
| 243 | *p = *(p + 1);
|
---|
| 244 | p++;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
[1107] | 248 | // mr_msg(1, "tmp = '%s'", tmp);
|
---|
[128] | 249 | d = atof(tmp);
|
---|
[1] | 250 | #endif
|
---|
[1107] | 251 | mr_msg(1, "g_kernel_version = %f", d);
|
---|
[128] | 252 | return (d);
|
---|
[1] | 253 | }
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 | /**
|
---|
| 257 | * Get the current time.
|
---|
| 258 | * @return number of seconds since the epoch.
|
---|
| 259 | */
|
---|
[1152] | 260 | long get_time(void)
|
---|
[1] | 261 | {
|
---|
[128] | 262 | return (long) time((void *) 0);
|
---|
[1] | 263 | }
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 | /**
|
---|
| 267 | * Initialize a RAID volume structure, setting fields to zero. The
|
---|
| 268 | * actual hard drive is unaffected.
|
---|
| 269 | *
|
---|
| 270 | * @param raidrec The RAID volume structure to initialize.
|
---|
| 271 | * @note This function is system dependent.
|
---|
| 272 | */
|
---|
| 273 | #ifdef __FreeBSD__
|
---|
[128] | 274 | void initialize_raidrec(struct vinum_volume *raidrec)
|
---|
[1] | 275 | {
|
---|
[128] | 276 | int i, j;
|
---|
| 277 | raidrec->volname[0] = '\0';
|
---|
| 278 | raidrec->plexes = 0;
|
---|
| 279 | for (i = 0; i < 9; ++i) {
|
---|
| 280 | raidrec->plex[i].raidlevel = -1;
|
---|
| 281 | raidrec->plex[i].stripesize = 0;
|
---|
| 282 | raidrec->plex[i].subdisks = 0;
|
---|
| 283 | for (j = 0; j < 9; ++j) {
|
---|
| 284 | strcpy(raidrec->plex[i].sd[j].which_device, "");
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
[1] | 287 | }
|
---|
| 288 | #else
|
---|
[128] | 289 | void initialize_raidrec(struct raid_device_record *raidrec)
|
---|
[1] | 290 | {
|
---|
[128] | 291 | assert(raidrec != NULL);
|
---|
| 292 | raidrec->raid_device[0] = '\0';
|
---|
[558] | 293 | raidrec->raid_level = -9;
|
---|
[128] | 294 | raidrec->persistent_superblock = 1;
|
---|
[558] | 295 | raidrec->chunk_size = 64;
|
---|
| 296 | raidrec->parity = -1;
|
---|
[128] | 297 | raidrec->data_disks.entries = 0;
|
---|
| 298 | raidrec->spare_disks.entries = 0;
|
---|
| 299 | raidrec->parity_disks.entries = 0;
|
---|
| 300 | raidrec->failed_disks.entries = 0;
|
---|
| 301 | raidrec->additional_vars.entries = 0;
|
---|
[1] | 302 | }
|
---|
| 303 | #endif
|
---|
| 304 |
|
---|
| 305 |
|
---|
| 306 | /**
|
---|
| 307 | * Insert modules that Mondo requires.
|
---|
[1221] | 308 | * Currently inserts @c msdos, @c vfat, and @c loop for Linux;
|
---|
[1] | 309 | * @c msdosfs and @c ext2fs for FreeBSD.
|
---|
| 310 | */
|
---|
| 311 | void insmod_crucial_modules(void)
|
---|
| 312 | {
|
---|
| 313 | #ifdef __FreeBSD__
|
---|
[128] | 314 | system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
|
---|
| 315 | system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null");
|
---|
[1] | 316 | #else
|
---|
[1221] | 317 | system("modprobe -a msdos vfat loop &> /dev/null");
|
---|
[1] | 318 | #endif
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | /**
|
---|
| 323 | * Finish configuring the backup information structure. Call this function
|
---|
| 324 | * to set the parameters that depend on those that can be given on the command
|
---|
| 325 | * line.
|
---|
| 326 | *
|
---|
| 327 | * @param bkpinfo The backup information structure. Fields modified/used:
|
---|
| 328 | * - Used: @c bkpinfo->backup_data
|
---|
| 329 | * - Used: @c bkpinfo->backup_media_type
|
---|
[1594] | 330 | * - Used: @c bkpinfo->writer_speed
|
---|
[1] | 331 | * - Used: @c bkpinfo->compression_level
|
---|
| 332 | * - Used: @c bkpinfo->include_paths
|
---|
[20] | 333 | * - Used: @c bkpinfo->prefix
|
---|
[1] | 334 | * - Used: @c bkpinfo->isodir
|
---|
[1609] | 335 | * - Used: @c bkpinfo->manual_tray
|
---|
[1] | 336 | * - Used: @c bkpinfo->make_cd_use_lilo
|
---|
| 337 | * - Used: @c bkpinfo->media_device
|
---|
| 338 | * - Used: @c bkpinfo->nfs_mount
|
---|
| 339 | * - Used: @c bkpinfo->nonbootable_backup
|
---|
| 340 | * - Used: @c bkpinfo->scratchdir
|
---|
| 341 | * - Used: @c bkpinfo->tmpdir
|
---|
| 342 | * - Used: @c bkpinfo->use_lzo
|
---|
| 343 | * - Modified: @c bkpinfo->call_before_iso
|
---|
| 344 | * - Modified: @c bkpinfo->call_make_iso
|
---|
| 345 | * - Modified: @c bkpinfo->optimal_set_size
|
---|
| 346 | * - Modified: @c bkpinfo->zip_exe
|
---|
| 347 | * - Modified: @c bkpinfo->zip_suffix
|
---|
| 348 | *
|
---|
| 349 | * @return number of errors, or 0 for success.
|
---|
| 350 | * @note Also creates directories that are specified in the @c bkpinfo structure but
|
---|
| 351 | * do not exist.
|
---|
| 352 | */
|
---|
[1663] | 353 | int post_param_configuration()
|
---|
[1] | 354 | {
|
---|
[1178] | 355 | char *extra_cdrom_params = NULL;
|
---|
| 356 | char *mondo_mkisofs_sz = NULL;
|
---|
| 357 | char *command = NULL;
|
---|
| 358 | char *hostname = NULL;
|
---|
| 359 | char *ip_address = NULL;
|
---|
[128] | 360 | int retval = 0;
|
---|
| 361 | long avm = 0;
|
---|
[1178] | 362 | char *colon = NULL;
|
---|
| 363 | char *tmp = NULL;
|
---|
| 364 | char *call_before_iso_user = NULL;
|
---|
[128] | 365 | int rdsiz_MB;
|
---|
[1178] | 366 | char *iso_dev = NULL;
|
---|
| 367 | char *iso_mnt = NULL;
|
---|
| 368 | char *iso_tmp = NULL;
|
---|
| 369 | char *iso_path = NULL;
|
---|
[1087] | 370 | FILE *fd1 = NULL;
|
---|
[1] | 371 |
|
---|
[128] | 372 | assert(bkpinfo != NULL);
|
---|
| 373 | bkpinfo->optimal_set_size =
|
---|
[686] | 374 | (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
|
---|
[128] | 375 | 1024;
|
---|
[1] | 376 |
|
---|
[1107] | 377 | mr_msg(1, "Foo");
|
---|
[128] | 378 | if (bkpinfo->backup_media_type == tape) {
|
---|
[1107] | 379 | mr_msg(1, "Bar");
|
---|
[1178] | 380 | mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
|
---|
[1107] | 381 | mr_msg(1, "tmp = '%s'", tmp);
|
---|
[128] | 382 | if (run_program_and_log_output(tmp, 3)) {
|
---|
| 383 | fatal_error
|
---|
| 384 | ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
|
---|
| 385 | }
|
---|
[1178] | 386 | mr_free(tmp);
|
---|
[1] | 387 | }
|
---|
[128] | 388 | make_hole_for_dir(bkpinfo->scratchdir);
|
---|
| 389 | if (bkpinfo->backup_media_type == iso)
|
---|
| 390 | make_hole_for_dir(bkpinfo->isodir);
|
---|
[1] | 391 |
|
---|
[128] | 392 | run_program_and_log_output("uname -a", 5);
|
---|
[678] | 393 | run_program_and_log_output("cat /etc/*-release", 5);
|
---|
[128] | 394 | sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
|
---|
[1178] | 395 | mr_asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt);
|
---|
[128] | 396 | paranoid_system(command);
|
---|
[1178] | 397 | mr_free(command);
|
---|
[128] | 398 | rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
|
---|
[1] | 399 | #ifdef __FreeBSD__
|
---|
[1178] | 400 | mr_asprintf(&tmp,
|
---|
[128] | 401 | call_program_and_get_last_line_of_output
|
---|
| 402 | ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
|
---|
| 403 | avm += atol(tmp);
|
---|
[1178] | 404 | mr_free(tmp);
|
---|
| 405 | mr_asprintf(&tmp,
|
---|
[128] | 406 | call_program_and_get_last_line_of_output
|
---|
| 407 | ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
|
---|
| 408 | avm += atol(tmp);
|
---|
[1178] | 409 | mr_free(tmp);
|
---|
| 410 | mr_asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
|
---|
| 411 | g_tmpfs_mountpt);
|
---|
[1] | 412 | #else
|
---|
[1178] | 413 | mr_asprintf(&tmp,
|
---|
[128] | 414 | call_program_and_get_last_line_of_output
|
---|
[911] | 415 | ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1"));
|
---|
[128] | 416 | avm += atol(tmp);
|
---|
[1178] | 417 | mr_free(tmp);
|
---|
| 418 | mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
|
---|
[128] | 419 | g_tmpfs_mountpt, rdsiz_MB, 'm');
|
---|
| 420 | run_program_and_log_output("cat /proc/cpuinfo", 5);
|
---|
[1178] | 421 | /* BERLIOS: rpm is not necessarily there ! */
|
---|
[128] | 422 | run_program_and_log_output
|
---|
| 423 | ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
|
---|
| 424 | 5);
|
---|
[1] | 425 | #endif
|
---|
[128] | 426 | if (avm / 1024 > rdsiz_MB * 3) {
|
---|
| 427 | if (run_program_and_log_output(command, 5)) {
|
---|
| 428 | g_tmpfs_mountpt[0] = '\0';
|
---|
| 429 | log_it("Failed to mount tmpfs");
|
---|
| 430 | } else {
|
---|
| 431 | log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
|
---|
| 432 | }
|
---|
| 433 | } else {
|
---|
| 434 | g_tmpfs_mountpt[0] = '\0';
|
---|
| 435 | log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
|
---|
[1] | 436 | }
|
---|
[1178] | 437 | mr_free(command);
|
---|
[128] | 438 |
|
---|
| 439 | if (bkpinfo->use_lzo) {
|
---|
| 440 | strcpy(bkpinfo->zip_exe, "lzop");
|
---|
| 441 | strcpy(bkpinfo->zip_suffix, "lzo");
|
---|
[998] | 442 | } else if (bkpinfo->use_gzip) {
|
---|
| 443 | strcpy(bkpinfo->zip_exe, "gzip");
|
---|
| 444 | strcpy(bkpinfo->zip_suffix, "gz");
|
---|
[128] | 445 | } else if (bkpinfo->compression_level != 0) {
|
---|
| 446 | strcpy(bkpinfo->zip_exe, "bzip2");
|
---|
| 447 | strcpy(bkpinfo->zip_suffix, "bz2");
|
---|
| 448 | } else {
|
---|
| 449 | bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
|
---|
[1] | 450 | }
|
---|
| 451 |
|
---|
[1592] | 452 | // CD-R or CD-RW or DVD
|
---|
[128] | 453 | if (bkpinfo->backup_media_type == cdrw
|
---|
[1592] | 454 | || bkpinfo->backup_media_type == dvd
|
---|
| 455 | || bkpinfo->backup_media_type == iso
|
---|
| 456 | || bkpinfo->backup_media_type == nfs
|
---|
[128] | 457 | || bkpinfo->backup_media_type == cdr) {
|
---|
[1609] | 458 | if (!bkpinfo->manual_tray) {
|
---|
[1178] | 459 | mr_strcat(extra_cdrom_params, "-waiti ");
|
---|
[128] | 460 | }
|
---|
| 461 | if (bkpinfo->backup_media_type == cdrw) {
|
---|
[1178] | 462 | mr_strcat(extra_cdrom_params, "blank=fast ");
|
---|
[128] | 463 | }
|
---|
| 464 | if (bkpinfo->nonbootable_backup) {
|
---|
[1592] | 465 | mr_asprintf(&mondo_mkisofs_sz, "%s -no-boot", mr_conf->iso_creation_opt);
|
---|
[128] | 466 | } else if
|
---|
[1] | 467 | #ifdef __FreeBSD__
|
---|
[128] | 468 | (TRUE)
|
---|
[1] | 469 | #else
|
---|
[128] | 470 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 471 | #endif
|
---|
| 472 | #ifdef __IA64__
|
---|
| 473 | {
|
---|
[1592] | 474 | mr_asprintf(&mondo_mkisofs_sz, "%s -b images/mindi-boot.2880.img -c boot.cat", mr_conf->iso_creation_opt);
|
---|
[1] | 475 | }
|
---|
[128] | 476 | #else
|
---|
[1] | 477 | {
|
---|
[1592] | 478 | mr_asprintf(&mondo_mkisofs_sz, "%s -b isolinux.bin -c boot.cat", mr_conf->iso_creation_opt);
|
---|
[1] | 479 | }
|
---|
[128] | 480 | #endif
|
---|
[1592] | 481 | else {
|
---|
| 482 | mr_asprintf(&mondo_mkisofs_sz, "%s -b isolinux.bin -c boot.cat", mr_conf->iso_creation_opt);
|
---|
[128] | 483 | }
|
---|
[1609] | 484 | if (bkpinfo->manual_tray) {
|
---|
[1594] | 485 | if (strstr(mr_conf->iso_burning_cmd,"growisofs") != NULL) {
|
---|
[1592] | 486 | fatal_error("Unable to use manual CD tray with growisofs");
|
---|
| 487 | }
|
---|
[163] | 488 | if (bkpinfo->call_before_iso[0] == '\0') {
|
---|
[1592] | 489 | sprintf(bkpinfo->call_before_iso,
|
---|
| 490 | "%s %s -o %s/temporary.iso . 2>> %s",
|
---|
| 491 | mr_conf->iso_creation_cmd,mondo_mkisofs_sz, bkpinfo->tmpdir, MONDO_LOGFILE);
|
---|
[1178] | 492 | } else {
|
---|
| 493 | mr_asprintf(&call_before_iso_user, bkpinfo->call_before_iso);
|
---|
[163] | 494 | sprintf (bkpinfo->call_before_iso,
|
---|
[1592] | 495 | "(%s %s -o %s/temporary.iso . 2>> %s ; %s )",
|
---|
| 496 | mr_conf->iso_creation_cmd,mondo_mkisofs_sz, bkpinfo->tmpdir, MONDO_LOGFILE, call_before_iso_user);
|
---|
[1178] | 497 | mr_free(call_before_iso_user);
|
---|
[163] | 498 | }
|
---|
| 499 | log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
|
---|
[128] | 500 | sprintf(bkpinfo->call_make_iso,
|
---|
[1592] | 501 | "%s %s %s dev=%s speed=%d %s/temporary.iso",
|
---|
[1594] | 502 | mr_conf->iso_burning_cmd,
|
---|
[1592] | 503 | extra_cdrom_params,
|
---|
[1594] | 504 | mr_conf->iso_burning_opt,
|
---|
| 505 | bkpinfo->iso_burning_dev,
|
---|
| 506 | bkpinfo->writer_speed,
|
---|
[1592] | 507 | bkpinfo->tmpdir);
|
---|
[128] | 508 | } else {
|
---|
[1594] | 509 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 510 | sprintf(bkpinfo->call_make_iso,
|
---|
| 511 | "%s %s . 2>> %s",
|
---|
| 512 | mr_conf->iso_creation_cmd,
|
---|
| 513 | mondo_mkisofs_sz,
|
---|
| 514 | MONDO_LOGFILE);
|
---|
| 515 | } else {
|
---|
| 516 | if (strstr(mr_conf->iso_burning_cmd,"growisofs") != NULL) {
|
---|
| 517 | if (getenv ("SUDO_COMMAND")) {
|
---|
| 518 | mr_asprintf(&command, "strings %s | grep -c SUDO_COMMAND", mr_conf->iso_burning_cmd);
|
---|
| 519 | if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
|
---|
| 520 | fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
|
---|
| 521 | }
|
---|
| 522 | mr_free(command);
|
---|
[1592] | 523 | }
|
---|
[1594] | 524 | sprintf(bkpinfo->call_make_iso,
|
---|
| 525 | "%s %s %s %s -Z %s -speed=%d . 2>> %s",
|
---|
| 526 | mr_conf->iso_burning_cmd,
|
---|
| 527 | mondo_mkisofs_sz,
|
---|
| 528 | extra_cdrom_params,
|
---|
| 529 | mr_conf->iso_burning_opt,
|
---|
| 530 | bkpinfo->iso_burning_dev,
|
---|
| 531 | bkpinfo->writer_speed,
|
---|
| 532 | MONDO_LOGFILE);
|
---|
| 533 | } else {
|
---|
| 534 | sprintf(bkpinfo->call_make_iso,
|
---|
| 535 | "%s %s . 2>> %s | %s %s %s dev=%s speed=%d -",
|
---|
| 536 | mr_conf->iso_creation_cmd,
|
---|
| 537 | mondo_mkisofs_sz,
|
---|
| 538 | MONDO_LOGFILE,
|
---|
| 539 | mr_conf->iso_burning_cmd,
|
---|
| 540 | extra_cdrom_params,
|
---|
| 541 | mr_conf->iso_burning_opt,
|
---|
| 542 | bkpinfo->iso_burning_dev,
|
---|
| 543 | bkpinfo->writer_speed);
|
---|
[1592] | 544 | }
|
---|
[1594] | 545 | mr_free(mondo_mkisofs_sz);
|
---|
| 546 | mr_free(extra_cdrom_params);
|
---|
[1592] | 547 | }
|
---|
[128] | 548 | }
|
---|
| 549 | } // end of CD code
|
---|
[1] | 550 |
|
---|
[128] | 551 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 552 |
|
---|
[1] | 553 | /* Patch by Conor Daly <conor.daly@met.ie>
|
---|
| 554 | * 23-june-2004
|
---|
| 555 | * Break up isodir into iso_mnt and iso_path
|
---|
| 556 | * These will be used along with iso-dev at restore time
|
---|
| 557 | * to locate the ISOs where ever they're mounted
|
---|
| 558 | */
|
---|
| 559 |
|
---|
[128] | 560 | log_it("isodir = %s", bkpinfo->isodir);
|
---|
[1178] | 561 | mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1",
|
---|
| 562 | bkpinfo->isodir);
|
---|
[128] | 563 | log_it("command = %s", command);
|
---|
[1178] | 564 | mr_asprintf(&iso_dev, call_program_and_get_last_line_of_output(command));
|
---|
| 565 | mr_free(command);
|
---|
[1087] | 566 | log_it("res of it = %s", iso_dev);
|
---|
[1] | 567 |
|
---|
[1087] | 568 | fd1 = mr_fopen(MONDORESTORECFG, "a");
|
---|
[1158] | 569 | mr_fprintf(fd1, "iso-dev=%s\n", iso_dev);
|
---|
[1087] | 570 |
|
---|
[1178] | 571 | mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
|
---|
| 572 | iso_dev);
|
---|
| 573 | mr_free(iso_dev);
|
---|
| 574 |
|
---|
[128] | 575 | log_it("command = %s", command);
|
---|
[1178] | 576 | mr_asprintf(&iso_mnt,call_program_and_get_last_line_of_output(command));
|
---|
| 577 | mr_free(command);
|
---|
[1087] | 578 |
|
---|
| 579 | log_it("res of it = %s", iso_mnt);
|
---|
[1158] | 580 | mr_fprintf(fd1, "iso-mnt=%s\n", iso_mnt);
|
---|
[128] | 581 | log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
|
---|
[1087] | 582 |
|
---|
[1178] | 583 | mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir);
|
---|
| 584 | if (strlen(iso_tmp) >= strlen(iso_mnt)) {
|
---|
| 585 | mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt));
|
---|
[128] | 586 | } else {
|
---|
[1178] | 587 | mr_asprintf(&iso_path, "");
|
---|
[128] | 588 | }
|
---|
[1178] | 589 | mr_free(iso_tmp);
|
---|
| 590 | mr_free(iso_mnt);
|
---|
| 591 |
|
---|
[128] | 592 | log_it("isodir: %s", iso_path);
|
---|
[1158] | 593 | mr_fprintf(fd1, "isodir=%s\n", iso_path);
|
---|
[1178] | 594 | mr_free(iso_path);
|
---|
[1087] | 595 |
|
---|
[148] | 596 | log_it("iso-prefix: %s", bkpinfo->prefix);
|
---|
[1158] | 597 | mr_fprintf(fd1, "iso-prefix=%s\n", bkpinfo->prefix);
|
---|
[1] | 598 |
|
---|
[1095] | 599 | mr_fclose(fd1);
|
---|
[128] | 600 | } // end of iso code
|
---|
[1] | 601 |
|
---|
[128] | 602 | if (bkpinfo->backup_media_type == nfs) {
|
---|
[1178] | 603 | mr_asprintf(&hostname, bkpinfo->nfs_mount);
|
---|
[128] | 604 | colon = strchr(hostname, ':');
|
---|
| 605 | if (!colon) {
|
---|
| 606 | log_it("nfs mount doesn't have a colon in it");
|
---|
| 607 | retval++;
|
---|
| 608 | } else {
|
---|
| 609 | struct hostent *hent;
|
---|
[1] | 610 |
|
---|
[128] | 611 | *colon = '\0';
|
---|
| 612 | hent = gethostbyname(hostname);
|
---|
| 613 | if (!hent) {
|
---|
| 614 | log_it("Can't resolve NFS mount (%s): %s", hostname,
|
---|
| 615 | hstrerror(h_errno));
|
---|
| 616 | retval++;
|
---|
| 617 | } else {
|
---|
[1178] | 618 | mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr)
|
---|
| 619 | *((struct in_addr *) hent->h_addr)),
|
---|
| 620 | strchr(bkpinfo->nfs_mount, ':'));
|
---|
[128] | 621 | strcpy(bkpinfo->nfs_mount, ip_address);
|
---|
[1178] | 622 | mr_free(ip_address);
|
---|
[128] | 623 | }
|
---|
| 624 | }
|
---|
[1663] | 625 | store_nfs_config();
|
---|
[1178] | 626 | mr_free(hostname);
|
---|
[128] | 627 | }
|
---|
[1] | 628 |
|
---|
[128] | 629 | log_it("Finished processing incoming params");
|
---|
| 630 | if (retval) {
|
---|
| 631 | fprintf(stderr, "Type 'man mondoarchive' for help.\n");
|
---|
| 632 | }
|
---|
[1178] | 633 |
|
---|
[128] | 634 | if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
|
---|
| 635 | log_it("tmpdir or scratchdir are blank/missing");
|
---|
| 636 | retval++;
|
---|
| 637 | }
|
---|
| 638 | if (bkpinfo->include_paths[0] == '\0') {
|
---|
| 639 | // fatal_error ("Why no backup path?");
|
---|
| 640 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 641 | }
|
---|
| 642 | chmod(bkpinfo->scratchdir, 0700);
|
---|
| 643 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
[1178] | 644 | g_backup_media_string = bkpinfo->backup_media_string;
|
---|
[128] | 645 | return (retval);
|
---|
[1] | 646 | }
|
---|
| 647 |
|
---|
| 648 |
|
---|
| 649 | /**
|
---|
| 650 | * Do some miscellaneous setup tasks to be performed before filling @c bkpinfo.
|
---|
| 651 | * Seeds the random-number generator, loads important modules, checks the sanity
|
---|
| 652 | * of the user's Linux distribution, and deletes logfile.
|
---|
| 653 | * @param bkpinfo The backup information structure. Will be initialized.
|
---|
| 654 | * @return number of errors (0 for success)
|
---|
| 655 | */
|
---|
[1663] | 656 | int pre_param_configuration()
|
---|
[1] | 657 | {
|
---|
[128] | 658 | int res = 0;
|
---|
[1663] | 659 | char *tmp = NULL;
|
---|
[1] | 660 |
|
---|
[128] | 661 | make_hole_for_dir(MNT_CDROM);
|
---|
| 662 | assert(bkpinfo != NULL);
|
---|
| 663 | srandom((unsigned long) (time(NULL)));
|
---|
| 664 | insmod_crucial_modules();
|
---|
| 665 | if (bkpinfo->disaster_recovery) {
|
---|
| 666 | if (!does_nonMS_partition_exist()) {
|
---|
| 667 | fatal_error
|
---|
| 668 | ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
|
---|
| 669 | }
|
---|
| 670 | }
|
---|
[1] | 671 |
|
---|
[1663] | 672 | asprintf(&tmp,"rm -Rf %s/changed.files*",MINDI_CACHE);
|
---|
| 673 | run_program_and_log_output(tmp, FALSE);
|
---|
| 674 | paranoid_free(tmp);
|
---|
[128] | 675 | res += some_basic_system_sanity_checks();
|
---|
| 676 | if (res) {
|
---|
| 677 | log_it("Your distribution did not pass Mondo's sanity test.");
|
---|
| 678 | }
|
---|
| 679 | g_current_media_number = 1;
|
---|
| 680 | bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
|
---|
| 681 | return (res);
|
---|
[1] | 682 | }
|
---|
| 683 |
|
---|
[1663] | 684 | void setup_tmpdir(char *path) {
|
---|
| 685 |
|
---|
| 686 | char *tmp = NULL;
|
---|
| 687 | char *p = NULL;
|
---|
[1] | 688 |
|
---|
[1663] | 689 | if (bkpinfo->tmpdir != NULL) {
|
---|
| 690 | /* purging a potential old tmpdir */
|
---|
| 691 | asprintf(&tmp,"rm -Rf %s",bkpinfo->tmpdir);
|
---|
| 692 | system(tmp);
|
---|
| 693 | paranoid_free(tmp);
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 | if (path != NULL) {
|
---|
| 697 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", path);
|
---|
| 698 | } else if (getenv("TMPDIR")) {
|
---|
| 699 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
|
---|
| 700 | } else if (getenv("TMP")) {
|
---|
| 701 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
|
---|
| 702 | } else {
|
---|
| 703 | asprintf(&tmp, "/tmp/mondo.tmp.XXXXXX");
|
---|
| 704 | }
|
---|
| 705 | p = mkdtemp(tmp);
|
---|
| 706 | if (p == NULL) {
|
---|
| 707 | log_it("Failed to create global tmp directory %s for Mondo.",tmp);
|
---|
| 708 | finish(-1);
|
---|
| 709 | }
|
---|
| 710 | strcpy(bkpinfo->tmpdir,p);
|
---|
| 711 | paranoid_free(tmp);
|
---|
[1] | 712 |
|
---|
[1663] | 713 | //sprintf(bkpinfo->tmpdir, "%s/tmpfs/mondo.tmp.%d", "/tmp", (int) (random() % 32768)); // for mondorestore
|
---|
| 714 | }
|
---|
[1] | 715 |
|
---|
[1663] | 716 |
|
---|
[1] | 717 | /**
|
---|
| 718 | * Reset all fields of the backup information structure to a sensible default.
|
---|
| 719 | * @param bkpinfo The @c bkpinfo to reset.
|
---|
| 720 | */
|
---|
[1663] | 721 | void reset_bkpinfo()
|
---|
[1] | 722 | {
|
---|
[1594] | 723 | char *tmp = NULL;
|
---|
| 724 |
|
---|
[1107] | 725 | mr_msg(1, "Hi");
|
---|
[1178] | 726 |
|
---|
[128] | 727 | assert(bkpinfo != NULL);
|
---|
[1178] | 728 | /* BERLIOS : Useless ?? */
|
---|
[128] | 729 | memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
|
---|
[1178] | 730 |
|
---|
[1663] | 731 | /* special case for tmpdir as used eveywhere after */
|
---|
| 732 | setup_tmpdir(NULL);
|
---|
| 733 |
|
---|
[1609] | 734 | bkpinfo->manual_tray = mr_conf->manual_tray;
|
---|
[1638] | 735 | bkpinfo->internal_tape_block_size = mr_conf->internal_tape_blocksize;
|
---|
[1594] | 736 | mr_asprintf(&tmp,mr_conf->media_device);
|
---|
| 737 | bkpinfo->media_device = tmp;
|
---|
| 738 | mr_asprintf(&tmp,mr_conf->iso_burning_dev);
|
---|
| 739 | bkpinfo->iso_burning_dev = tmp;
|
---|
| 740 |
|
---|
| 741 | bkpinfo->media_size = mr_conf->iso_burning_speed;
|
---|
[128] | 742 | bkpinfo->boot_loader = '\0';
|
---|
| 743 | bkpinfo->boot_device[0] = '\0';
|
---|
| 744 | bkpinfo->zip_exe[0] = '\0';
|
---|
| 745 | bkpinfo->zip_suffix[0] = '\0';
|
---|
| 746 | bkpinfo->restore_path[0] = '\0';
|
---|
| 747 | bkpinfo->use_lzo = FALSE;
|
---|
[998] | 748 | bkpinfo->use_gzip = FALSE;
|
---|
[128] | 749 | bkpinfo->do_not_compress_these[0] = '\0';
|
---|
| 750 | bkpinfo->verify_data = FALSE;
|
---|
| 751 | bkpinfo->backup_data = FALSE;
|
---|
| 752 | bkpinfo->restore_data = FALSE;
|
---|
| 753 | bkpinfo->disaster_recovery =
|
---|
| 754 | (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
|
---|
| 755 | if (bkpinfo->disaster_recovery) {
|
---|
| 756 | strcpy(bkpinfo->isodir, "/");
|
---|
| 757 | } else {
|
---|
[1178] | 758 | strcpy(bkpinfo->isodir, "/var/cache/mondo/iso");
|
---|
[128] | 759 | }
|
---|
[1628] | 760 | mr_asprintf(&tmp,mr_conf->prefix);
|
---|
| 761 | bkpinfo->prefix = tmp;
|
---|
[1] | 762 |
|
---|
[128] | 763 | bkpinfo->scratchdir[0] = '\0';
|
---|
| 764 | bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
|
---|
| 765 | bkpinfo->optimal_set_size = 0;
|
---|
| 766 | bkpinfo->backup_media_type = none;
|
---|
[1178] | 767 | bkpinfo->backup_media_string[0] = '\0';
|
---|
[128] | 768 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 769 | bkpinfo->exclude_paths[0] = '\0';
|
---|
| 770 | bkpinfo->call_before_iso[0] = '\0';
|
---|
| 771 | bkpinfo->call_make_iso[0] = '\0';
|
---|
| 772 | bkpinfo->call_after_iso[0] = '\0';
|
---|
| 773 | bkpinfo->image_devs[0] = '\0';
|
---|
| 774 | bkpinfo->postnuke_tarball[0] = '\0';
|
---|
| 775 | bkpinfo->kernel_path[0] = '\0';
|
---|
| 776 | bkpinfo->nfs_mount[0] = '\0';
|
---|
| 777 | bkpinfo->nfs_remote_dir[0] = '\0';
|
---|
| 778 | bkpinfo->wipe_media_first = FALSE;
|
---|
| 779 | bkpinfo->differential = FALSE;
|
---|
[1594] | 780 | bkpinfo->writer_speed = mr_conf->iso_burning_speed;
|
---|
[128] | 781 | bkpinfo->compression_level = 3;
|
---|
[1] | 782 | }
|
---|
| 783 |
|
---|
| 784 |
|
---|
| 785 | /**
|
---|
| 786 | * Get the remaining free space (in MB) on @p partition.
|
---|
| 787 | * @param partition The partition to check free space on (either a device or a mountpoint).
|
---|
| 788 | * @return The free space on @p partition, in MB.
|
---|
| 789 | */
|
---|
[128] | 790 | long free_space_on_given_partition(char *partition)
|
---|
[1] | 791 | {
|
---|
[1178] | 792 | char *command = NULL;
|
---|
| 793 | char *out_sz = NULL;
|
---|
| 794 | long res = 0L;
|
---|
[1] | 795 |
|
---|
[128] | 796 | assert_string_is_neither_NULL_nor_zerolength(partition);
|
---|
[1] | 797 |
|
---|
[1178] | 798 | mr_asprintf(&command, "df -m -P %s &> /dev/null", partition);
|
---|
[128] | 799 | if (system(command)) {
|
---|
| 800 | return (-1);
|
---|
| 801 | } // partition does not exist
|
---|
[1178] | 802 | mr_free(command);
|
---|
| 803 |
|
---|
| 804 | mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
|
---|
[128] | 805 | partition);
|
---|
[1178] | 806 | mr_asprintf(&out_sz, call_program_and_get_last_line_of_output(command));
|
---|
| 807 | mr_free(command);
|
---|
| 808 |
|
---|
[128] | 809 | if (strlen(out_sz) == 0) {
|
---|
| 810 | return (-1);
|
---|
| 811 | } // error within df, probably
|
---|
| 812 | res = atol(out_sz);
|
---|
[1178] | 813 | mr_free(out_sz);
|
---|
[128] | 814 | return (res);
|
---|
[1] | 815 | }
|
---|
| 816 |
|
---|
| 817 |
|
---|
| 818 | /**
|
---|
| 819 | * Check the user's system for sanity. Checks performed:
|
---|
| 820 | * - make sure user has enough RAM (32mb required, 64mb recommended)
|
---|
| 821 | * - make sure user has enough free space in @c /
|
---|
| 822 | * - check kernel for ramdisk support
|
---|
[1592] | 823 | * - make sure afio, cdrecord, bzip2, awk, md5sum, strings, mindi, and buffer exist
|
---|
[1] | 824 | * - make sure CD-ROM is unmounted
|
---|
| 825 | * - make sure /etc/modules.conf exists
|
---|
| 826 | * - make sure user's mountlist is OK by running <tt>mindi --makemountlist</tt>
|
---|
| 827 | *
|
---|
| 828 | * @return number of problems with the user's setup (0 for success)
|
---|
| 829 | */
|
---|
[128] | 830 | int some_basic_system_sanity_checks()
|
---|
[1] | 831 | {
|
---|
| 832 |
|
---|
[128] | 833 | /*@ buffers ************ */
|
---|
[1178] | 834 | char *tmp = NULL;
|
---|
[1] | 835 |
|
---|
[128] | 836 | /*@ int's *************** */
|
---|
| 837 | int retval = 0;
|
---|
| 838 | long Lres;
|
---|
[1] | 839 |
|
---|
| 840 |
|
---|
[1178] | 841 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 842 | "Checking sanity of your Linux distribution");
|
---|
[1] | 843 | #ifndef __FreeBSD__
|
---|
[128] | 844 | if (system("which mkfs.vfat &> /dev/null")
|
---|
| 845 | && !system("which mkfs.msdos &> /dev/null")) {
|
---|
| 846 | log_it
|
---|
| 847 | ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
|
---|
| 848 | run_program_and_log_output
|
---|
| 849 | ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
|
---|
| 850 | }
|
---|
[1178] | 851 | mr_asprintf(&tmp,
|
---|
[128] | 852 | call_program_and_get_last_line_of_output
|
---|
| 853 | ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
|
---|
| 854 | if (atol(tmp) < 35000) {
|
---|
| 855 | retval++;
|
---|
[1178] | 856 | log_to_screen(_("You must have at least 32MB of RAM to use Mondo."));
|
---|
[128] | 857 | }
|
---|
| 858 | if (atol(tmp) < 66000) {
|
---|
| 859 | log_to_screen
|
---|
[1178] | 860 | (_("WARNING! You have very little RAM. Please upgrade to 64MB or more."));
|
---|
[128] | 861 | }
|
---|
[1178] | 862 | mr_free(tmp);
|
---|
[1] | 863 | #endif
|
---|
| 864 |
|
---|
[1438] | 865 | Lres = free_space_on_given_partition(MONDO_CACHE);
|
---|
[128] | 866 | log_it("Free space on given partition = %ld MB", Lres);
|
---|
[1] | 867 |
|
---|
[128] | 868 | if (Lres < 50) {
|
---|
[1438] | 869 | fatal_error("Your "MONDO_CACHE" partition has <50MB free. Please adjust your partition table to something saner or make "MONDO_CACHE" a symbolic link");
|
---|
[128] | 870 | }
|
---|
[1] | 871 |
|
---|
[128] | 872 | if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
|
---|
| 873 | retval++;
|
---|
| 874 | log_to_screen
|
---|
| 875 | ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
|
---|
| 876 | fatal_error
|
---|
| 877 | ("Please use \"su -\", not \"su\" to become root. OK? ...and please don't e-mail the mailing list or me about this. Just read the message. :)");
|
---|
| 878 | }
|
---|
[1] | 879 | #ifndef __FreeBSD__
|
---|
[128] | 880 | if (run_program_and_log_output
|
---|
[273] | 881 | ("grep ramdisk /proc/devices", FALSE)) {
|
---|
[128] | 882 | if (!ask_me_yes_or_no
|
---|
[1178] | 883 | (_("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?")))
|
---|
[128] | 884 | {
|
---|
| 885 | // retval++;
|
---|
| 886 | log_to_screen
|
---|
[1178] | 887 | (_("It looks as if your kernel lacks ramdisk and initrd support."));
|
---|
[128] | 888 | log_to_screen
|
---|
[1178] | 889 | (_("I'll allow you to proceed but FYI, if I'm right, your kernel is broken."));
|
---|
[128] | 890 | }
|
---|
| 891 | }
|
---|
[1] | 892 | #endif
|
---|
[1594] | 893 | retval += whine_if_not_found(mr_conf->iso_creation_cmd);
|
---|
| 894 | retval += whine_if_not_found(mr_conf->iso_burning_cmd);
|
---|
[128] | 895 | retval += whine_if_not_found(MKE2FS_OR_NEWFS);
|
---|
| 896 | retval += whine_if_not_found("bzip2");
|
---|
[998] | 897 | retval += whine_if_not_found("gzip");
|
---|
[128] | 898 | retval += whine_if_not_found("awk");
|
---|
| 899 | retval += whine_if_not_found("md5sum");
|
---|
| 900 | retval += whine_if_not_found("strings");
|
---|
| 901 | retval += whine_if_not_found("mindi");
|
---|
| 902 | retval += whine_if_not_found("buffer");
|
---|
[1] | 903 |
|
---|
[128] | 904 | // abort if Windows partition but no ms-sys and parted
|
---|
| 905 | if (!run_program_and_log_output
|
---|
[680] | 906 | ("mount | grep -w vfat | grep -vE \"/dev/fd|nexdisk\"", 0)
|
---|
[128] | 907 | ||
|
---|
| 908 | !run_program_and_log_output
|
---|
[680] | 909 | ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) {
|
---|
[1178] | 910 | log_to_screen(_("I think you have a Windows 9x partition."));
|
---|
[128] | 911 | retval += whine_if_not_found("parted");
|
---|
[1] | 912 | #ifndef __IA64__
|
---|
[128] | 913 | /* IA64 always has one vfat partition for EFI even without Windows */
|
---|
| 914 | // retval +=
|
---|
| 915 | if (!find_home_of_exe("ms-sys")) {
|
---|
[541] | 916 | log_to_screen("Please install ms-sys just in case.");
|
---|
[128] | 917 | }
|
---|
| 918 | #endif
|
---|
[1] | 919 | }
|
---|
| 920 |
|
---|
[128] | 921 | if (!find_home_of_exe("cmp")) {
|
---|
| 922 | if (!find_home_of_exe("true")) {
|
---|
| 923 | whine_if_not_found("cmp");
|
---|
| 924 | } else {
|
---|
| 925 | log_to_screen
|
---|
[541] | 926 | ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
|
---|
[128] | 927 | if (run_program_and_log_output
|
---|
| 928 | ("cp -f `which true` /usr/bin/cmp", 0)) {
|
---|
| 929 | fatal_error("Failed to create dummy 'cmp' file.");
|
---|
| 930 | }
|
---|
| 931 | }
|
---|
[1] | 932 | }
|
---|
[128] | 933 | run_program_and_log_output
|
---|
| 934 | ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
|
---|
[1178] | 935 | mr_asprintf(&tmp,
|
---|
[128] | 936 | call_program_and_get_last_line_of_output
|
---|
| 937 | ("mount | grep -E \"cdr(om|w)\""));
|
---|
| 938 | if (strcmp("", tmp)) {
|
---|
| 939 | if (strstr(tmp, "autofs")) {
|
---|
| 940 | log_to_screen
|
---|
[1178] | 941 | (_("Your CD-ROM is mounted via autofs. I therefore cannot tell"));
|
---|
[128] | 942 | log_to_screen
|
---|
[1178] | 943 | (_("if a CD actually is inserted. If a CD is inserted, please"));
|
---|
| 944 | log_to_screen(_("eject it. Thank you."));
|
---|
[128] | 945 | log_it
|
---|
| 946 | ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
|
---|
| 947 | } else
|
---|
| 948 | if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
|
---|
| 949 | retval++;
|
---|
| 950 | fatal_error
|
---|
| 951 | ("Your CD-ROM drive is mounted. Please unmount it.");
|
---|
| 952 | }
|
---|
| 953 | }
|
---|
[1178] | 954 | mr_free(tmp);
|
---|
[1] | 955 | #ifndef __FreeBSD__
|
---|
[128] | 956 | if (!does_file_exist("/etc/modules.conf")) {
|
---|
| 957 | if (does_file_exist("/etc/conf.modules")) {
|
---|
| 958 | log_it("Linking /etc/modules.conf to /etc/conf.modules");
|
---|
| 959 | run_program_and_log_output
|
---|
| 960 | ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
|
---|
| 961 | } else if (does_file_exist("/etc/modprobe.d")) {
|
---|
| 962 | log_it
|
---|
| 963 | ("Directory /etc/modprobe.d found. mindi will use its contents.");
|
---|
| 964 | } else if (does_file_exist("/etc/modprobe.conf")) {
|
---|
| 965 | log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
|
---|
| 966 | run_program_and_log_output
|
---|
| 967 | ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
|
---|
| 968 | } else {
|
---|
| 969 | retval++;
|
---|
| 970 | log_to_screen
|
---|
[1178] | 971 | (_("Please find out what happened to /etc/modules.conf"));
|
---|
[128] | 972 | }
|
---|
[1] | 973 | }
|
---|
| 974 | #endif
|
---|
| 975 |
|
---|
[128] | 976 | run_program_and_log_output("cat /etc/fstab", 5);
|
---|
[1] | 977 | #ifdef __FreeBSD__
|
---|
[128] | 978 | run_program_and_log_output("vinum printconfig", 5);
|
---|
[1] | 979 | #else
|
---|
[128] | 980 | run_program_and_log_output("cat /etc/raidtab", 5);
|
---|
[1] | 981 | #endif
|
---|
| 982 |
|
---|
[128] | 983 | if (run_program_and_log_output("mindi -V", 1)) {
|
---|
[1178] | 984 | log_to_screen(_("Could not ascertain mindi's version number."));
|
---|
[128] | 985 | log_to_screen
|
---|
[1178] | 986 | (_("You have not installed Mondo and/or Mindi properly."));
|
---|
| 987 | log_to_screen(_("Please uninstall and reinstall them both."));
|
---|
[128] | 988 | fatal_error("Please reinstall Mondo and Mindi.");
|
---|
| 989 | }
|
---|
[1663] | 990 | mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);
|
---|
| 991 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 992 | log_to_screen(tmp);
|
---|
[128] | 993 | log_to_screen
|
---|
[1663] | 994 | (_("failed for some reason."));
|
---|
[128] | 995 | log_to_screen
|
---|
[1178] | 996 | (_("Please run that command by hand and examine /var/log/mindi.log"));
|
---|
[128] | 997 | log_to_screen
|
---|
[1178] | 998 | (_("for more information. Perhaps your /etc/fstab file is insane."));
|
---|
[128] | 999 | log_to_screen
|
---|
[1178] | 1000 | (_("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see."));
|
---|
[128] | 1001 | retval++;
|
---|
| 1002 | }
|
---|
[1663] | 1003 | mr_free(tmp);
|
---|
[1] | 1004 |
|
---|
[196] | 1005 | if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1)
|
---|
[128] | 1006 | && !does_file_exist("/etc/raidtab")) {
|
---|
| 1007 | log_to_screen
|
---|
[1252] | 1008 | (_("You have RAID partitions but no /etc/raidtab - creating one from "MDSTAT_FILE));
|
---|
[558] | 1009 | create_raidtab_from_mdstat("/etc/raidtab");
|
---|
[128] | 1010 | }
|
---|
| 1011 |
|
---|
| 1012 | if (retval) {
|
---|
[1178] | 1013 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
[128] | 1014 | } else {
|
---|
[1178] | 1015 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 1016 | }
|
---|
| 1017 | return (retval);
|
---|
[1] | 1018 | }
|
---|
| 1019 |
|
---|
| 1020 | /**
|
---|
| 1021 | * Retrieve the line containing @p label from the config file.
|
---|
| 1022 | * @param config_file The file to read from, usually @c /tmp/mondo-restore.cfg.
|
---|
| 1023 | * @param label What to read from the file.
|
---|
| 1024 | * @param value Where to put it.
|
---|
| 1025 | * @return 0 for success, 1 for failure.
|
---|
| 1026 | */
|
---|
[128] | 1027 | int read_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1028 | {
|
---|
[128] | 1029 | /*@ buffer ****************************************************** */
|
---|
[1178] | 1030 | char *command = NULL;
|
---|
| 1031 | char *tmp = NULL;
|
---|
[1] | 1032 |
|
---|
[128] | 1033 | /*@ end vars *************************************************** */
|
---|
[1] | 1034 |
|
---|
[128] | 1035 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1036 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
[1178] | 1037 |
|
---|
[128] | 1038 | if (!does_file_exist(config_file)) {
|
---|
[1178] | 1039 | mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
|
---|
| 1040 | config_file);
|
---|
[128] | 1041 | log_to_screen(tmp);
|
---|
[1178] | 1042 | mr_free(tmp);
|
---|
[128] | 1043 | value[0] = '\0';
|
---|
| 1044 | return (1);
|
---|
[1178] | 1045 | /* } BERLIOS: Useless:
|
---|
| 1046 | else if (strstr(value, "/dev/") && strstr(value, "t0")
|
---|
[128] | 1047 | && !strcmp(label, "media-dev")) {
|
---|
[1107] | 1048 | mr_msg(2, "FYI, I shan't read new value for %s - already got %s",
|
---|
[128] | 1049 | label, value);
|
---|
| 1050 | return (0);
|
---|
[1178] | 1051 | */ } else {
|
---|
| 1052 | mr_asprintf(&command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5",
|
---|
[148] | 1053 | label, config_file);
|
---|
[128] | 1054 | strcpy(value, call_program_and_get_last_line_of_output(command));
|
---|
[1178] | 1055 | mr_free(command);
|
---|
[128] | 1056 | if (strlen(value) == 0) {
|
---|
| 1057 | return (1);
|
---|
| 1058 | } else {
|
---|
| 1059 | return (0);
|
---|
| 1060 | }
|
---|
[1] | 1061 | }
|
---|
| 1062 | }
|
---|
| 1063 |
|
---|
| 1064 |
|
---|
| 1065 | /**
|
---|
| 1066 | * Remount @c supermount if it was unmounted earlier.
|
---|
| 1067 | */
|
---|
| 1068 | void remount_supermounts_if_necessary()
|
---|
| 1069 | {
|
---|
[128] | 1070 | if (g_remount_cdrom_at_end) {
|
---|
| 1071 | run_program_and_log_output("mount " MNT_CDROM, FALSE);
|
---|
| 1072 | }
|
---|
[1] | 1073 | }
|
---|
| 1074 |
|
---|
| 1075 | /**
|
---|
| 1076 | * Unmount @c supermount if it's mounted.
|
---|
| 1077 | */
|
---|
| 1078 | void unmount_supermounts_if_necessary()
|
---|
| 1079 | {
|
---|
[128] | 1080 | if (run_program_and_log_output
|
---|
| 1081 | ("mount | grep cdrom | grep super", FALSE) == 0) {
|
---|
| 1082 | g_remount_cdrom_at_end = TRUE;
|
---|
| 1083 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 1084 | }
|
---|
[1] | 1085 | }
|
---|
| 1086 |
|
---|
| 1087 | /**
|
---|
| 1088 | * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
|
---|
| 1089 | */
|
---|
| 1090 | void mount_boot_if_necessary()
|
---|
| 1091 | {
|
---|
[1178] | 1092 | char *tmp = NULL;
|
---|
| 1093 | char *tmp1 = NULL;
|
---|
| 1094 | char *command = NULL;
|
---|
[1] | 1095 |
|
---|
[1107] | 1096 | mr_msg(1, "Started sub");
|
---|
| 1097 | mr_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
|
---|
[128] | 1098 | g_boot_mountpt[0] = '\0';
|
---|
[1178] | 1099 | mr_msg(4, "Done. Great. Setting command to something");
|
---|
| 1100 | mr_asprintf(&command,
|
---|
| 1101 | "grep -v ':' /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
|
---|
[1107] | 1102 | mr_msg(4, "Cool. Command = '%s'", command);
|
---|
[1178] | 1103 | mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 1104 | mr_free(command);
|
---|
| 1105 |
|
---|
[1107] | 1106 | mr_msg(4, "tmp = '%s'", tmp);
|
---|
[128] | 1107 | if (tmp[0]) {
|
---|
| 1108 | log_it("/boot is at %s according to /etc/fstab", tmp);
|
---|
[1373] | 1109 | if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) {
|
---|
[128] | 1110 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
| 1111 | strcpy(g_boot_mountpt, "/boot");
|
---|
[1107] | 1112 | mr_msg(1, "Mounted /boot");
|
---|
[128] | 1113 | } else {
|
---|
[1373] | 1114 | log_it("...ignored cos it's a label or uuid :-)");
|
---|
[128] | 1115 | }
|
---|
| 1116 | } else {
|
---|
[1178] | 1117 | mr_asprintf(&command, "mount | grep -E '^%s'", tmp);
|
---|
[1107] | 1118 | mr_msg(3, "command = %s", command);
|
---|
[128] | 1119 | if (run_program_and_log_output(command, 5)) {
|
---|
| 1120 | strcpy(g_boot_mountpt, tmp);
|
---|
[1178] | 1121 | mr_asprintf(&tmp1,
|
---|
[128] | 1122 | "%s (your /boot partition) is not mounted. I'll mount it before backing up",
|
---|
| 1123 | g_boot_mountpt);
|
---|
[1178] | 1124 | log_it(tmp1);
|
---|
| 1125 | mr_free(tmp1);
|
---|
| 1126 |
|
---|
| 1127 | mr_asprintf(&tmp1, "mount %s", g_boot_mountpt);
|
---|
| 1128 | if (run_program_and_log_output(tmp1, 5)) {
|
---|
[128] | 1129 | g_boot_mountpt[0] = '\0';
|
---|
[1107] | 1130 | mr_msg(1, "Plan B");
|
---|
[128] | 1131 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
| 1132 | strcpy(g_boot_mountpt, "/boot");
|
---|
[1107] | 1133 | mr_msg(1, "Plan B worked");
|
---|
[128] | 1134 | } else {
|
---|
[1107] | 1135 | mr_msg(1,
|
---|
[128] | 1136 | "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
|
---|
| 1137 | }
|
---|
| 1138 | }
|
---|
[1178] | 1139 | mr_free(tmp1);
|
---|
[128] | 1140 | }
|
---|
[1178] | 1141 | mr_free(command);
|
---|
[128] | 1142 | }
|
---|
[1] | 1143 | }
|
---|
[1178] | 1144 | mr_free(tmp);
|
---|
[1107] | 1145 | mr_msg(1, "Ended sub");
|
---|
[1] | 1146 | }
|
---|
| 1147 |
|
---|
| 1148 |
|
---|
| 1149 | /**
|
---|
| 1150 | * If we mounted /boot earlier, unmount it.
|
---|
| 1151 | */
|
---|
| 1152 | void unmount_boot_if_necessary()
|
---|
| 1153 | {
|
---|
[1178] | 1154 | char *tmp;
|
---|
[1] | 1155 |
|
---|
[1107] | 1156 | mr_msg(3, "starting");
|
---|
[128] | 1157 | if (g_boot_mountpt[0]) {
|
---|
[1178] | 1158 | mr_asprintf(&tmp, "umount %s", g_boot_mountpt);
|
---|
[128] | 1159 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1160 | log_it("WARNING - unable to unmount /boot");
|
---|
| 1161 | }
|
---|
[1178] | 1162 | mr_free(tmp);
|
---|
[128] | 1163 | }
|
---|
[1107] | 1164 | mr_msg(3, "leaving");
|
---|
[1] | 1165 | }
|
---|
| 1166 |
|
---|
| 1167 |
|
---|
| 1168 | /**
|
---|
| 1169 | * Write a line to a configuration file. Writes a line of the form,
|
---|
| 1170 | * @c label @c value.
|
---|
| 1171 | * @param config_file The file to write to. Usually @c mondo-restore.cfg.
|
---|
| 1172 | * @param label What to call this bit of data you're writing.
|
---|
| 1173 | * @param value The bit of data you're writing.
|
---|
| 1174 | * @return 0 for success, 1 for failure.
|
---|
| 1175 | */
|
---|
[128] | 1176 | int write_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1177 | {
|
---|
[128] | 1178 | /*@ buffers ***************************************************** */
|
---|
[1178] | 1179 | char *command = NULL;
|
---|
| 1180 | char *tempfile = NULL;
|
---|
| 1181 | char *tmp = NULL;
|
---|
[1] | 1182 |
|
---|
| 1183 |
|
---|
[128] | 1184 | /*@ end vars *************************************************** */
|
---|
| 1185 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1186 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
| 1187 | assert(value != NULL);
|
---|
[1178] | 1188 |
|
---|
[128] | 1189 | if (!does_file_exist(config_file)) {
|
---|
[1178] | 1190 | mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file",
|
---|
| 1191 | config_file);
|
---|
[128] | 1192 | log_to_screen(tmp);
|
---|
[1178] | 1193 | mr_free(tmp);
|
---|
[128] | 1194 | return (1);
|
---|
| 1195 | }
|
---|
[1663] | 1196 | mr_asprintf(&tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
|
---|
[128] | 1197 | if (does_file_exist(config_file)) {
|
---|
[1178] | 1198 | mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s",
|
---|
[148] | 1199 | label, config_file, tempfile);
|
---|
[128] | 1200 | paranoid_system(command);
|
---|
[1178] | 1201 | mr_free(command);
|
---|
[128] | 1202 | }
|
---|
[1178] | 1203 | mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
|
---|
[128] | 1204 | paranoid_system(command);
|
---|
[1178] | 1205 | mr_free(command);
|
---|
| 1206 |
|
---|
| 1207 | mr_asprintf(&command, "mv -f %s %s", tempfile, config_file);
|
---|
[128] | 1208 | paranoid_system(command);
|
---|
[1178] | 1209 | mr_free(command);
|
---|
[128] | 1210 | unlink(tempfile);
|
---|
[1178] | 1211 | mr_free(tempfile);
|
---|
[128] | 1212 | return (0);
|
---|
[1] | 1213 | }
|
---|
| 1214 |
|
---|
[541] | 1215 |
|
---|
[1] | 1216 | /**
|
---|
| 1217 | * Allocate or free important globals, depending on @p mal.
|
---|
| 1218 | * @param mal If TRUE, malloc; if FALSE, free.
|
---|
| 1219 | */
|
---|
| 1220 | void do_libmondo_global_strings_thing(int mal)
|
---|
| 1221 | {
|
---|
[128] | 1222 | if (mal) {
|
---|
| 1223 | malloc_string(g_boot_mountpt);
|
---|
| 1224 | malloc_string(g_tmpfs_mountpt);
|
---|
| 1225 | malloc_string(g_erase_tmpdir_and_scratchdir);
|
---|
| 1226 | malloc_string(g_serial_string);
|
---|
| 1227 | malloc_string(g_magicdev_command);
|
---|
| 1228 | } else {
|
---|
[1080] | 1229 | mr_free(g_boot_mountpt);
|
---|
| 1230 | mr_free(g_tmpfs_mountpt);
|
---|
| 1231 | mr_free(g_erase_tmpdir_and_scratchdir);
|
---|
| 1232 | mr_free(g_serial_string);
|
---|
| 1233 | mr_free(g_magicdev_command);
|
---|
[128] | 1234 | }
|
---|
[1] | 1235 | }
|
---|
| 1236 |
|
---|
| 1237 | /**
|
---|
| 1238 | * Allocate important globals.
|
---|
| 1239 | * @see do_libmondo_global_strings_thing
|
---|
| 1240 | */
|
---|
| 1241 | void malloc_libmondo_global_strings(void)
|
---|
| 1242 | {
|
---|
[128] | 1243 | do_libmondo_global_strings_thing(1);
|
---|
[1] | 1244 | }
|
---|
| 1245 |
|
---|
| 1246 | /**
|
---|
| 1247 | * Free important globals.
|
---|
| 1248 | * @see do_libmondo_global_strings_thing
|
---|
| 1249 | */
|
---|
| 1250 | void free_libmondo_global_strings(void)
|
---|
| 1251 | {
|
---|
[128] | 1252 | do_libmondo_global_strings_thing(0);
|
---|
[1] | 1253 | }
|
---|
| 1254 |
|
---|
| 1255 |
|
---|
| 1256 |
|
---|
| 1257 | /**
|
---|
| 1258 | * Stop @c magicdev if it's running.
|
---|
| 1259 | * The command used to start it is saved in @p g_magicdev_command.
|
---|
| 1260 | */
|
---|
| 1261 | void stop_magicdev_if_necessary()
|
---|
| 1262 | {
|
---|
[128] | 1263 | strcpy(g_magicdev_command,
|
---|
| 1264 | call_program_and_get_last_line_of_output
|
---|
| 1265 | ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
|
---|
| 1266 | if (g_magicdev_command[0]) {
|
---|
[1107] | 1267 | mr_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
|
---|
[128] | 1268 | paranoid_system("killall magicdev");
|
---|
| 1269 | }
|
---|
[1] | 1270 | }
|
---|
| 1271 |
|
---|
| 1272 |
|
---|
| 1273 | /**
|
---|
| 1274 | * Restart magicdev if it was stopped.
|
---|
| 1275 | */
|
---|
| 1276 | void restart_magicdev_if_necessary()
|
---|
| 1277 | {
|
---|
[1178] | 1278 | char *tmp = NULL;
|
---|
[128] | 1279 |
|
---|
| 1280 | if (g_magicdev_command && g_magicdev_command[0]) {
|
---|
[1178] | 1281 | mr_asprintf(&tmp, "%s &", g_magicdev_command);
|
---|
[128] | 1282 | paranoid_system(tmp);
|
---|
[1178] | 1283 | mr_free(tmp);
|
---|
[128] | 1284 | }
|
---|
[1] | 1285 | }
|
---|
| 1286 |
|
---|
| 1287 | /* @} - end of utilityGroup */
|
---|