| 1 | /***************************************************************************
|
|---|
| 2 | * $Id: mondoarchive.c 1770 2007-11-06 10:01:53Z bruno $
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * @file
|
|---|
| 8 | * The main file for mondoarchive.
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /************************* #include statements *************************/
|
|---|
| 12 | #include <pthread.h>
|
|---|
| 13 | #include <stdio.h>
|
|---|
| 14 | #include <stdlib.h>
|
|---|
| 15 | #include <sys/types.h>
|
|---|
| 16 | #include <sys/stat.h>
|
|---|
| 17 | #include <unistd.h>
|
|---|
| 18 | #include <locale.h>
|
|---|
| 19 |
|
|---|
| 20 | #include "mr_gettext.h"
|
|---|
| 21 | #include "mondoarchive.h"
|
|---|
| 22 | #include "mr_mem.h"
|
|---|
| 23 | #include "mr_str.h"
|
|---|
| 24 | #include "mr_msg.h"
|
|---|
| 25 | #include "mr_file.h"
|
|---|
| 26 | #include "mr_err.h"
|
|---|
| 27 | #include "mr_conf.h"
|
|---|
| 28 |
|
|---|
| 29 | #include "my-stuff.h"
|
|---|
| 30 | #include "mondostructures.h"
|
|---|
| 31 | #include "libmondo.h"
|
|---|
| 32 | #include "mondo-cli-EXT.h"
|
|---|
| 33 |
|
|---|
| 34 | // for CVS
|
|---|
| 35 | //static char cvsid[] = "$Id: mondoarchive.c 1770 2007-11-06 10:01:53Z bruno $";
|
|---|
| 36 |
|
|---|
| 37 | /************************* external variables *************************/
|
|---|
| 38 | extern void set_signals(int);
|
|---|
| 39 | extern int g_current_media_number;
|
|---|
| 40 | extern void register_pid(pid_t, char *);
|
|---|
| 41 | extern int g_currentY;
|
|---|
| 42 | extern bool g_text_mode;
|
|---|
| 43 | extern char *g_boot_mountpt;
|
|---|
| 44 | extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
|
|---|
| 45 | extern char *g_tmpfs_mountpt;
|
|---|
| 46 | extern char *g_cdrw_drive_is_here;
|
|---|
| 47 | extern double g_kernel_version;
|
|---|
| 48 | extern char *g_magicdev_command;
|
|---|
| 49 | extern t_bkptype g_backup_media_type;
|
|---|
| 50 |
|
|---|
| 51 | extern char *get_uname_m(void);
|
|---|
| 52 |
|
|---|
| 53 | static char *g_cdrom_drive_is_here = NULL;
|
|---|
| 54 | static char *g_dvd_drive_is_here = NULL;
|
|---|
| 55 |
|
|---|
| 56 | struct mr_ar_conf *mr_conf = NULL;
|
|---|
| 57 |
|
|---|
| 58 | /***************** global vars ******************/
|
|---|
| 59 | long diffs;
|
|---|
| 60 |
|
|---|
| 61 | /****************** subroutines used only here ******************/
|
|---|
| 62 |
|
|---|
| 63 | /* Reference to global bkpinfo */
|
|---|
| 64 | struct s_bkpinfo *bkpinfo;
|
|---|
| 65 |
|
|---|
| 66 | /****************** subroutines used only by main.c ******************/
|
|---|
| 67 |
|
|---|
| 68 | /**
|
|---|
| 69 | * Print a "don't panic" message to the log and a message about the logfile to the screen.
|
|---|
| 70 | */
|
|---|
| 71 | static void welcome_to_mondoarchive(void)
|
|---|
| 72 | {
|
|---|
| 73 | char *tmp = NULL;
|
|---|
| 74 |
|
|---|
| 75 | mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
|
|---|
| 76 | mr_msg(0, "running %s binaries", get_architecture());
|
|---|
| 77 | tmp = get_uname_m();
|
|---|
| 78 | mr_msg(0, "running on %s architecture", tmp);
|
|---|
| 79 | mr_free(tmp);
|
|---|
| 80 | mr_msg(0, "-----------------------------------------------------------");
|
|---|
| 81 | mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
|
|---|
| 82 | mr_msg(0, "some error messages. Please read them carefully before you");
|
|---|
| 83 | mr_msg(0, "decide to break out in a cold sweat. Despite (or perhaps");
|
|---|
| 84 | mr_msg(0, "because of) the wealth of messages. some users are inclined");
|
|---|
| 85 | mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
|
|---|
| 86 | mr_msg(0, "chances are it's detailed here. More than likely there's a");
|
|---|
| 87 | mr_msg(0, "message at the very end of this log that will tell you what");
|
|---|
| 88 | mr_msg(0, "is wrong. Please read it! -Devteam");
|
|---|
| 89 | mr_msg(0, "-----------------------------------------------------------");
|
|---|
| 90 |
|
|---|
| 91 | mr_msg(0, "Zero...");
|
|---|
| 92 | mr_msg(1, "One...");
|
|---|
| 93 | mr_msg(2, "Two...");
|
|---|
| 94 | mr_msg(3, "Three...");
|
|---|
| 95 | mr_msg(4, "Four...");
|
|---|
| 96 | mr_msg(5, "Five...");
|
|---|
| 97 | mr_msg(6, "Six...");
|
|---|
| 98 | mr_msg(7, "Seven...");
|
|---|
| 99 | mr_msg(8, "Eight...");
|
|---|
| 100 | printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | /**
|
|---|
| 104 | * Do whatever is necessary to insure a successful backup on the Linux distribution
|
|---|
| 105 | * of the day.
|
|---|
| 106 | */
|
|---|
| 107 | static void distro_specific_kludges_at_start_of_mondoarchive(void)
|
|---|
| 108 | {
|
|---|
| 109 | mr_msg(2, "Unmounting old ramdisks if necessary");
|
|---|
| 110 | stop_magicdev_if_necessary(); // for RH+Gnome users
|
|---|
| 111 | run_program_and_log_output
|
|---|
| 112 | ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
|
|---|
| 113 | unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
|
|---|
| 114 | mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
|
|---|
| 115 | clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
|
|---|
| 121 | */
|
|---|
| 122 | static void distro_specific_kludges_at_end_of_mondoarchive(void)
|
|---|
| 123 | {
|
|---|
| 124 | mr_msg(2, "Restarting magicdev if necessary");
|
|---|
| 125 | sync();
|
|---|
| 126 | restart_magicdev_if_necessary(); // for RH+Gnome users
|
|---|
| 127 |
|
|---|
| 128 | mr_msg(2, "Restarting supermounts if necessary");
|
|---|
| 129 | sync();
|
|---|
| 130 | remount_supermounts_if_necessary(); // for Mandrake users
|
|---|
| 131 |
|
|---|
| 132 | mr_msg(2, "Unmounting /boot if necessary");
|
|---|
| 133 | sync();
|
|---|
| 134 | unmount_boot_if_necessary(); // for Gentoo users
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /* reset/empty the mr_ar_conf structure from mondo's conf file */
|
|---|
| 138 | static void mr_ar_reset_conf(struct mr_ar_conf *mr_cnf) {
|
|---|
| 139 |
|
|---|
| 140 | /* This should correspond to the default conf file */
|
|---|
| 141 | /* Especially for boolean values */
|
|---|
| 142 | mr_cnf->iso_creation_cmd = NULL;
|
|---|
| 143 | mr_cnf->iso_creation_opt = NULL;
|
|---|
| 144 | mr_cnf->iso_burning_cmd = NULL;
|
|---|
| 145 | mr_cnf->iso_burning_opt = NULL;
|
|---|
| 146 | mr_cnf->iso_burning_dev = NULL;
|
|---|
| 147 | mr_cnf->iso_burning_speed = 0;
|
|---|
| 148 | mr_cnf->media_size = 0;
|
|---|
| 149 | mr_cnf->media_device = NULL;
|
|---|
| 150 | mr_cnf->iso_burning_dev = NULL;
|
|---|
| 151 | mr_cnf->manual_tray = FALSE;
|
|---|
| 152 | mr_cnf->log_level = 0;
|
|---|
| 153 | mr_cnf->prefix = NULL;
|
|---|
| 154 | mr_cnf->external_tape_blocksize = 0;
|
|---|
| 155 | mr_cnf->internal_tape_blocksize = 0;
|
|---|
| 156 | mr_cnf->kernel = NULL;
|
|---|
| 157 | mr_cnf->additional_modules = NULL;
|
|---|
| 158 | mr_cnf->boot_loader = NULL;
|
|---|
| 159 | mr_cnf->differential = FALSE;
|
|---|
| 160 | mr_cnf->compression_tool = NULL;
|
|---|
| 161 | mr_cnf->compression_level = 0;
|
|---|
| 162 | mr_cnf->exclude_paths = NULL;
|
|---|
| 163 | mr_cnf->include_paths = NULL;
|
|---|
| 164 | mr_cnf->ui_mode = NULL;
|
|---|
| 165 | mr_cnf->automatic_restore = FALSE;
|
|---|
| 166 | mr_cnf->scratch_dir = NULL;
|
|---|
| 167 | mr_cnf->tmp_dir = NULL;
|
|---|
| 168 | mr_cnf->images_dir = NULL;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | /* fill the mr_ar_conf structure from mindi's conf file */
|
|---|
| 172 | static void mr_ar_store_conf_mindi(struct mr_ar_conf *mr_cnf) {
|
|---|
| 173 |
|
|---|
| 174 | char *p = NULL;
|
|---|
| 175 |
|
|---|
| 176 | p = mr_conf_sread("mr_iso_creation_cmd");
|
|---|
| 177 | if (p != NULL) {
|
|---|
| 178 | mr_cnf->iso_creation_cmd = p;
|
|---|
| 179 | }
|
|---|
| 180 | p = mr_conf_sread("mr_iso_creation_opt");
|
|---|
| 181 | if (p != NULL) {
|
|---|
| 182 | mr_cnf->iso_creation_opt = p;
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | /* create the mr_ar_conf structure from mondo's conf file */
|
|---|
| 187 | static void mr_ar_store_conf(struct mr_ar_conf *mr_cnf) {
|
|---|
| 188 |
|
|---|
| 189 | char *p = NULL;
|
|---|
| 190 |
|
|---|
| 191 | p = mr_conf_sread("mondo_iso_burning_cmd");
|
|---|
| 192 | if (p != NULL) {
|
|---|
| 193 | mr_cnf->iso_burning_cmd = p;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | p = mr_conf_sread("mondo_iso_burning_opt");
|
|---|
| 197 | if (p != NULL) {
|
|---|
| 198 | mr_cnf->iso_burning_opt = p;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | p = mr_conf_sread("mondo_iso_burning_dev");
|
|---|
| 202 | if (p != NULL) {
|
|---|
| 203 | mr_cnf->iso_burning_dev = p;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | p = mr_conf_iread("mondo_iso_burning_speed");
|
|---|
| 207 | if (p != NULL ) {
|
|---|
| 208 | mr_cnf->iso_burning_speed = atoi(p);
|
|---|
| 209 | mr_free(p);
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | p = mr_conf_iread("mondo_media_size");
|
|---|
| 213 | if (p != NULL ) {
|
|---|
| 214 | mr_cnf->media_size = atoi(p);
|
|---|
| 215 | mr_free(p);
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | p = mr_conf_sread("mondo_media_device");
|
|---|
| 219 | if (p != NULL) {
|
|---|
| 220 | mr_cnf->media_device = p;
|
|---|
| 221 | }
|
|---|
| 222 | /* If no specific device name for the burning command (a la ATAPI:0,0,0),
|
|---|
| 223 | * then use the normal device name (a la /dev/hda) */
|
|---|
| 224 | if ((mr_cnf->iso_burning_dev == NULL) && (mr_cnf->media_device != NULL)) {
|
|---|
| 225 | mr_asprintf(&p, mr_cnf->media_device);
|
|---|
| 226 | mr_cnf->iso_burning_dev = p;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | p = mr_conf_bread("mondo_manual_tray");
|
|---|
| 230 | if (p != NULL) {
|
|---|
| 231 | mr_cnf->manual_tray = mr_atob(p);
|
|---|
| 232 | mr_free(p);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | p = mr_conf_iread("mondo_log_level");
|
|---|
| 236 | if (p != NULL) {
|
|---|
| 237 | mr_cnf->log_level = atoi(p);
|
|---|
| 238 | mr_free(p);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | p = mr_conf_sread("mondo_prefix");
|
|---|
| 242 | if (p != NULL) {
|
|---|
| 243 | mr_cnf->prefix = p;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | p = mr_conf_iread("mondo_external_tape_blocksize");
|
|---|
| 247 | if (p != NULL) {
|
|---|
| 248 | mr_cnf->external_tape_blocksize = atoi(p);
|
|---|
| 249 | mr_free(p);
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | p = mr_conf_iread("mondo_internal_tape_blocksize");
|
|---|
| 253 | if (p != NULL) {
|
|---|
| 254 | mr_cnf->internal_tape_blocksize = atoi(p);
|
|---|
| 255 | mr_free(p);
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | p = mr_conf_sread("mondo_kernel");
|
|---|
| 259 | if (p != NULL) {
|
|---|
| 260 | mr_cnf->kernel = p;
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | p = mr_conf_sread("mondo_additional_modules");
|
|---|
| 264 | if (p != NULL) {
|
|---|
| 265 | mr_cnf->additional_modules = p;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | p = mr_conf_sread("mondo_boot_loader");
|
|---|
| 269 | if (p != NULL) {
|
|---|
| 270 | mr_cnf->boot_loader = p;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | p = mr_conf_bread("mondo_differential");
|
|---|
| 274 | if (p != NULL) {
|
|---|
| 275 | mr_cnf->differential = mr_atob(p);
|
|---|
| 276 | mr_free(p);
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | p = mr_conf_sread("mondo_compression_tool");
|
|---|
| 280 | if (p != NULL) {
|
|---|
| 281 | mr_cnf->compression_tool = p;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | p = mr_conf_sread("mondo_compression_suffix");
|
|---|
| 285 | if (p != NULL) {
|
|---|
| 286 | mr_cnf->compression_suffix = p;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | p = mr_conf_iread("mondo_compression_level");
|
|---|
| 290 | if (p != NULL) {
|
|---|
| 291 | mr_cnf->compression_level = atoi(p);
|
|---|
| 292 | mr_free(p);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | p = mr_conf_sread("mondo_exclude_paths");
|
|---|
| 296 | if (p != NULL) {
|
|---|
| 297 | mr_cnf->exclude_paths = p;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | p = mr_conf_sread("mondo_include_paths");
|
|---|
| 301 | if (p != NULL) {
|
|---|
| 302 | mr_cnf->include_paths = p;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | p = mr_conf_sread("mondo_ui_mode");
|
|---|
| 306 | if (p != NULL) {
|
|---|
| 307 | mr_cnf->ui_mode = p;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | p = mr_conf_bread("mondo_automatic_restore");
|
|---|
| 311 | if (p != NULL) {
|
|---|
| 312 | mr_cnf->automatic_restore = mr_atob(p);
|
|---|
| 313 | mr_free(p);
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | p = mr_conf_sread("mondo_scratch_dir");
|
|---|
| 317 | if (p != NULL) {
|
|---|
| 318 | mr_cnf->scratch_dir = p;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | p = mr_conf_sread("mondo_tmp_dir");
|
|---|
| 322 | if (p != NULL) {
|
|---|
| 323 | mr_cnf->tmp_dir = p;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | p = mr_conf_sread("mondo_images_dir");
|
|---|
| 327 | if (p != NULL) {
|
|---|
| 328 | mr_cnf->images_dir = p;
|
|---|
| 329 | }
|
|---|
| 330 | mr_msg(5, "Directory for images is %s", mr_cnf->images_dir);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | /* destroy the mr_ar_conf structure's content */
|
|---|
| 334 | static void mr_ar_clean_conf(struct mr_ar_conf *mr_cnf) {
|
|---|
| 335 |
|
|---|
| 336 | if (mr_cnf == NULL) {
|
|---|
| 337 | return;
|
|---|
| 338 | }
|
|---|
| 339 | mr_free(mr_cnf->iso_creation_cmd);
|
|---|
| 340 | mr_free(mr_cnf->iso_creation_opt);
|
|---|
| 341 | mr_free(mr_cnf->iso_burning_cmd);
|
|---|
| 342 | mr_free(mr_cnf->iso_burning_dev);
|
|---|
| 343 | mr_free(mr_cnf->iso_burning_opt);
|
|---|
| 344 | mr_free(mr_cnf->media_device);
|
|---|
| 345 | mr_free(mr_cnf->prefix);
|
|---|
| 346 | mr_free(mr_cnf->kernel);
|
|---|
| 347 | mr_free(mr_cnf->additional_modules);
|
|---|
| 348 | mr_free(mr_cnf->boot_loader);
|
|---|
| 349 | mr_free(mr_cnf->compression_tool);
|
|---|
| 350 | mr_free(mr_cnf->exclude_paths);
|
|---|
| 351 | mr_free(mr_cnf->include_paths);
|
|---|
| 352 | mr_free(mr_cnf->ui_mode);
|
|---|
| 353 | mr_free(mr_cnf->scratch_dir);
|
|---|
| 354 | mr_free(mr_cnf->tmp_dir);
|
|---|
| 355 | mr_free(mr_cnf->images_dir);
|
|---|
| 356 | mr_free(mr_cnf);
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | /* Create the pointer to the function called in mr_exit */
|
|---|
| 360 | void (*mr_cleanup)(void) = NULL;
|
|---|
| 361 |
|
|---|
| 362 | /* Just for init */
|
|---|
| 363 | void mr_ar_cleanup_empty(void) {
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | /* Cleanup all memory allocated in various structures */
|
|---|
| 367 | void mr_ar_cleanup(void) {
|
|---|
| 368 | /* Highly incomplete function for the moment */
|
|---|
| 369 | /* We have to free all allocated memory */
|
|---|
| 370 | mr_ar_clean_conf(mr_conf);
|
|---|
| 371 | /* We have to remove all temporary files */
|
|---|
| 372 | /* We have to unmount what has been mounted */
|
|---|
| 373 | /* We have to properly end newt */
|
|---|
| 374 | /* We have to remind people of log files */
|
|---|
| 375 |
|
|---|
| 376 | mr_msg_close();
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | /*-----------------------------------------------------------*/
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 | /**
|
|---|
| 384 | * Backup/verify the user's data.
|
|---|
| 385 | * What did you think it did, anyway? :-)
|
|---|
| 386 | */
|
|---|
| 387 | int main(int argc, char *argv[])
|
|---|
| 388 | {
|
|---|
| 389 | struct stat stbuf;
|
|---|
| 390 | char *tmp = NULL;
|
|---|
| 391 | int res = 0;
|
|---|
| 392 | int retval = 0;
|
|---|
| 393 | char *say_at_end = NULL;
|
|---|
| 394 | char *say_at_end2 = NULL;
|
|---|
| 395 |
|
|---|
| 396 | #ifdef ENABLE_NLS
|
|---|
| 397 | setlocale(LC_ALL, "");
|
|---|
| 398 | (void) textdomain("mondo");
|
|---|
| 399 | #endif
|
|---|
| 400 | printf(_("Initializing...\n"));
|
|---|
| 401 |
|
|---|
| 402 | bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
|
|---|
| 403 | reset_bkpinfo();
|
|---|
| 404 |
|
|---|
| 405 | /* Reference a dummy cleanup function for mr_exit temporarily */
|
|---|
| 406 | mr_cleanup = &mr_ar_cleanup_empty;
|
|---|
| 407 |
|
|---|
| 408 | /* initialize log file with time stamp */
|
|---|
| 409 | /* We start with a loglevel of 4 - Adapted later on */
|
|---|
| 410 | /* It's mandatory to set this up first as all mr_ functions rely on it */
|
|---|
| 411 | unlink(MONDO_LOGFILE);
|
|---|
| 412 | mr_msg_init(MONDO_LOGFILE,4);
|
|---|
| 413 | mr_msg(0, _("Time started: %s"), mr_date());
|
|---|
| 414 |
|
|---|
| 415 | /* Make sure I'm root; abort if not */
|
|---|
| 416 | if (getuid() != 0) {
|
|---|
| 417 | mr_log_exit(127, _("Please run as root."));
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | /* If -V, -v or --version then echo version no. and quit */
|
|---|
| 421 | if (argc == 2
|
|---|
| 422 | && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
|
|---|
| 423 | || !strcmp(argv[argc - 1], "--version"))) {
|
|---|
| 424 | printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
|
|---|
| 425 | mr_exit(0, NULL);
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | /* Conf file management */
|
|---|
| 429 | mr_conf = mr_malloc(sizeof(struct mr_ar_conf));
|
|---|
| 430 | mr_ar_reset_conf(mr_conf);
|
|---|
| 431 | /* Check md5 sum before */
|
|---|
| 432 | /* Get content */
|
|---|
| 433 | if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
|
|---|
| 434 | mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
|
|---|
| 435 | }
|
|---|
| 436 | mr_ar_store_conf(mr_conf);
|
|---|
| 437 | /* Reference the right cleanup function for mr_exit now it's allocated */
|
|---|
| 438 | mr_cleanup = &mr_ar_cleanup;
|
|---|
| 439 | mr_conf_close();
|
|---|
| 440 |
|
|---|
| 441 | if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf") == 0) {
|
|---|
| 442 | mr_ar_store_conf(mr_conf);
|
|---|
| 443 | mr_conf_close();
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | /* Check md5 sum before */
|
|---|
| 447 | /* Get content of mindi conf file now to finish structure initialization */
|
|---|
| 448 | /* Tempo Hack */
|
|---|
| 449 | #define MINDI_CONF_DIR MONDO_CONF_DIR"/../mindi"
|
|---|
| 450 | if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf.dist") != 0) {
|
|---|
| 451 | mr_log_exit(-1, "Unable to open "MINDI_CONF_DIR"/mindi.conf.dist");
|
|---|
| 452 | }
|
|---|
| 453 | mr_ar_store_conf_mindi(mr_conf);
|
|---|
| 454 | mr_conf_close();
|
|---|
| 455 |
|
|---|
| 456 | if (mr_conf_open(MINDI_CONF_DIR"/mindi.conf") == 0) {
|
|---|
| 457 | mr_ar_store_conf_mindi(mr_conf);
|
|---|
| 458 | mr_conf_close();
|
|---|
| 459 | }
|
|---|
| 460 | mr_msg(5, "Command for ISO images is %s", mr_conf->iso_creation_cmd);
|
|---|
| 461 |
|
|---|
| 462 | /* Add MONDO_SHARE + other environment variables for mindi */
|
|---|
| 463 | setenv_mondo_var();
|
|---|
| 464 |
|
|---|
| 465 | /* Initialize variables */
|
|---|
| 466 | malloc_libmondo_global_strings();
|
|---|
| 467 | diffs = 0;
|
|---|
| 468 | if (stat(MONDO_CACHE, &stbuf) != 0) {
|
|---|
| 469 | mr_mkdir(MONDO_CACHE,0x755);
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | /* BERLIOS: Hardcoded to be improved */
|
|---|
| 473 | unlink(MONDO_CACHE"/mindi.conf");
|
|---|
| 474 | unlink(MONDORESTORECFG);
|
|---|
| 475 |
|
|---|
| 476 | /* Configure the bkpinfo structure, global file paths, etc. */
|
|---|
| 477 | g_main_pid = getpid();
|
|---|
| 478 | mr_msg(9, "This");
|
|---|
| 479 |
|
|---|
| 480 | register_pid(g_main_pid, "mondo");
|
|---|
| 481 | set_signals(TRUE); // catch SIGTERM, etc.
|
|---|
| 482 | run_program_and_log_output("dmesg -n1", TRUE);
|
|---|
| 483 |
|
|---|
| 484 | mr_msg(9, "Next");
|
|---|
| 485 | make_hole_for_dir(MONDO_CACHE);
|
|---|
| 486 |
|
|---|
| 487 | welcome_to_mondoarchive();
|
|---|
| 488 | distro_specific_kludges_at_start_of_mondoarchive();
|
|---|
| 489 | g_kernel_version = get_kernel_version();
|
|---|
| 490 |
|
|---|
| 491 | if (argc == 4 && !strcmp(argv[1], "getfattr")) {
|
|---|
| 492 | mr_conf->log_level = 10;
|
|---|
| 493 | g_text_mode = TRUE;
|
|---|
| 494 | setup_newt_stuff();
|
|---|
| 495 | if (!strstr(argv[2], "filelist")) {
|
|---|
| 496 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
|---|
| 497 | finish(1);
|
|---|
| 498 | } else {
|
|---|
| 499 | finish(get_fattr_list(argv[2], argv[3]));
|
|---|
| 500 | }
|
|---|
| 501 | finish(0);
|
|---|
| 502 | }
|
|---|
| 503 | if (argc == 4 && !strcmp(argv[1], "setfattr")) {
|
|---|
| 504 | mr_conf->log_level = 10;
|
|---|
| 505 | g_text_mode = TRUE;
|
|---|
| 506 | setup_newt_stuff();
|
|---|
| 507 | finish(set_fattr_list(argv[2], argv[3]));
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | if (argc == 3 && !strcmp(argv[1], "wildcards")) {
|
|---|
| 511 | mr_conf->log_level = 10;
|
|---|
| 512 | g_text_mode = TRUE;
|
|---|
| 513 | setup_newt_stuff();
|
|---|
| 514 | tmp = mr_stresc(argv[2], WILDCHARS, BACKSLASH);
|
|---|
| 515 | printf("in=%s; out=%s\n", argv[2], tmp);
|
|---|
| 516 | mr_free(tmp);
|
|---|
| 517 | finish(1);
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | if (argc == 4 && !strcmp(argv[1], "getfacl")) {
|
|---|
| 521 | mr_conf->log_level = 10;
|
|---|
| 522 | g_text_mode = TRUE;
|
|---|
| 523 | setup_newt_stuff();
|
|---|
| 524 | if (!strstr(argv[2], "filelist")) {
|
|---|
| 525 | mr_msg(1,_("Sorry - filelist goes first\n"));
|
|---|
| 526 | finish(1);
|
|---|
| 527 | } else {
|
|---|
| 528 | finish(get_acl_list(argv[2], argv[3]));
|
|---|
| 529 | }
|
|---|
| 530 | finish(0);
|
|---|
| 531 | }
|
|---|
| 532 | if (argc == 4 && !strcmp(argv[1], "setfacl")) {
|
|---|
| 533 | mr_conf->log_level = 10;
|
|---|
| 534 | g_text_mode = TRUE;
|
|---|
| 535 | setup_newt_stuff();
|
|---|
| 536 | finish(set_acl_list(argv[2], argv[3]));
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | if (argc > 2 && !strcmp(argv[1], "find-cd")) {
|
|---|
| 540 | mr_conf->log_level = 10;
|
|---|
| 541 | g_text_mode = TRUE;
|
|---|
| 542 | setup_newt_stuff();
|
|---|
| 543 | malloc_string(tmp);
|
|---|
| 544 | if (find_cdrw_device(tmp)) {
|
|---|
| 545 | mr_msg(1,_("Failed to find CDR-RW drive\n"));
|
|---|
| 546 | } else {
|
|---|
| 547 | mr_msg(1,_("CD-RW is at %s\n"), tmp);
|
|---|
| 548 | }
|
|---|
| 549 | tmp[0] = '\0';
|
|---|
| 550 | if (find_cdrom_device(tmp, atoi(argv[2]))) {
|
|---|
| 551 | mr_msg(1,_("Failed to find CD-ROM drive\n"));
|
|---|
| 552 | } else {
|
|---|
| 553 | mr_msg(1,_("CD-ROM is at %s\n"), tmp);
|
|---|
| 554 | }
|
|---|
| 555 | mr_free(tmp);
|
|---|
| 556 | finish(0);
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
|
|---|
| 560 | mr_conf->log_level = 10;
|
|---|
| 561 | g_text_mode = TRUE;
|
|---|
| 562 | setup_newt_stuff();
|
|---|
| 563 | malloc_string(tmp);
|
|---|
| 564 | if (find_dvd_device(tmp, atoi(argv[2]))) {
|
|---|
| 565 | mr_msg(1,_("Failed to find DVD drive\n"));
|
|---|
| 566 | } else {
|
|---|
| 567 | mr_msg(1,_("DVD is at %s\n"), tmp);
|
|---|
| 568 | }
|
|---|
| 569 | mr_free(tmp);
|
|---|
| 570 | finish(0);
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | if (argc > 2 && !strcmp(argv[1], "disksize")) {
|
|---|
| 574 | printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
|
|---|
| 575 | finish(0);
|
|---|
| 576 | }
|
|---|
| 577 | if (argc > 2 && !strcmp(argv[1], "test-dev")) {
|
|---|
| 578 | if (is_dev_an_NTFS_dev(argv[2])) {
|
|---|
| 579 | mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
|
|---|
| 580 | } else {
|
|---|
| 581 | mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
|
|---|
| 582 | }
|
|---|
| 583 | finish(0);
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | if (pre_param_configuration()) {
|
|---|
| 587 | fatal_error
|
|---|
| 588 | ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
|
|---|
| 589 | }
|
|---|
| 590 | sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
|
|---|
| 591 | bkpinfo->scratchdir);
|
|---|
| 592 |
|
|---|
| 593 | /* Process command line, if there is one. If not, ask user for info. */
|
|---|
| 594 | if (argc == 1) {
|
|---|
| 595 | g_text_mode = FALSE;
|
|---|
| 596 | setup_newt_stuff();
|
|---|
| 597 | res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */
|
|---|
| 598 | if (res) {
|
|---|
| 599 | fatal_error
|
|---|
| 600 | ("Syntax error. Please review the parameters you have supplied and try again.");
|
|---|
| 601 | }
|
|---|
| 602 | } else {
|
|---|
| 603 | res = handle_incoming_parameters(argc, argv);
|
|---|
| 604 | if (res) {
|
|---|
| 605 | mr_msg(1,
|
|---|
| 606 | _("Errors were detected in the command line you supplied.\n"));
|
|---|
| 607 | mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
|
|---|
| 608 | mr_msg(1, "Mondoarchive will now exit.");
|
|---|
| 609 | finish(1);
|
|---|
| 610 | }
|
|---|
| 611 | setup_newt_stuff();
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | /* Finish configuring global structures */
|
|---|
| 615 | if (post_param_configuration()) {
|
|---|
| 616 | fatal_error
|
|---|
| 617 | ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
|
|---|
| 618 | }
|
|---|
| 619 |
|
|---|
| 620 | log_to_screen
|
|---|
| 621 | (_("BusyBox's sources are available from http://www.busybox.net"));
|
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 | /* If we're meant to backup then backup */
|
|---|
| 625 | if (bkpinfo->backup_data) {
|
|---|
| 626 | res = backup_data();
|
|---|
| 627 | retval += res;
|
|---|
| 628 | if (res) {
|
|---|
| 629 | mr_strcat(say_at_end,
|
|---|
| 630 | _("Data archived. Please check the logs, just as a precaution. "));
|
|---|
| 631 | } else {
|
|---|
| 632 | mr_strcat(say_at_end, _("Data archived OK. "));
|
|---|
| 633 | }
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | /* If we're meant to verify then verify */
|
|---|
| 637 | if (bkpinfo->verify_data) {
|
|---|
| 638 | res = verify_data();
|
|---|
| 639 | if (res < 0) {
|
|---|
| 640 | mr_asprintf(&say_at_end2, _("%d difference%c found."), -res,
|
|---|
| 641 | (-res != 1) ? 's' : ' ');
|
|---|
| 642 | res = 0;
|
|---|
| 643 | }
|
|---|
| 644 | retval += res;
|
|---|
| 645 | }
|
|---|
| 646 |
|
|---|
| 647 | /* Report result of entire operation (success? errors?) */
|
|---|
| 648 | if (!retval) {
|
|---|
| 649 | mvaddstr_and_log_it(g_currentY++, 0,
|
|---|
| 650 | _("Backup and/or verify ran to completion. Everything appears to be fine."));
|
|---|
| 651 | } else {
|
|---|
| 652 | mvaddstr_and_log_it(g_currentY++, 0,
|
|---|
| 653 | _("Backup and/or verify ran to completion. However, errors did occur."));
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
|
|---|
| 657 | log_to_screen
|
|---|
| 658 | (_(MINDI_CACHE"/mondorescue.iso, a boot/utility CD, is available if you want it."));
|
|---|
| 659 | }
|
|---|
| 660 |
|
|---|
| 661 | if (length_of_file(MONDO_CACHE"/changed.files") > 2) {
|
|---|
| 662 | if (g_text_mode) {
|
|---|
| 663 | log_to_screen
|
|---|
| 664 | (_("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
|
|---|
| 665 | } else {
|
|---|
| 666 | mr_msg(1,
|
|---|
| 667 | _("Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives"));
|
|---|
| 668 | mr_msg(2, "Calling popup_changelist_from_file()");
|
|---|
| 669 | popup_changelist_from_file(MONDO_CACHE"/changed.files");
|
|---|
| 670 | mr_msg(2, "Returned from popup_changelist_from_file()");
|
|---|
| 671 | }
|
|---|
| 672 | } else {
|
|---|
| 673 | unlink(MONDO_CACHE"/changed.files");
|
|---|
| 674 | }
|
|---|
| 675 | log_to_screen(say_at_end);
|
|---|
| 676 | mr_free(say_at_end);
|
|---|
| 677 | if (say_at_end2 != NULL) {
|
|---|
| 678 | log_to_screen(say_at_end2);
|
|---|
| 679 | mr_free(say_at_end2);
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
|
|---|
| 683 | run_program_and_log_output(tmp, TRUE);
|
|---|
| 684 | mr_free(tmp);
|
|---|
| 685 | if (bkpinfo->backup_media_type == usb) {
|
|---|
| 686 | log_msg(1, "Unmounting USB device.");
|
|---|
| 687 | mr_asprintf(&tmp, "umount %s1", bkpinfo->media_device);
|
|---|
| 688 | run_program_and_log_output(tmp, TRUE);
|
|---|
| 689 | mr_free(tmp);
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 | run_program_and_log_output("mount", 2);
|
|---|
| 693 |
|
|---|
| 694 | system("rm -f "MONDO_CACHE"/last-backup.aborted");
|
|---|
| 695 | if (!retval) {
|
|---|
| 696 | printf(_("Mondoarchive ran OK.\n"));
|
|---|
| 697 | } else {
|
|---|
| 698 | printf(_("Errors occurred during backup. Please check logfile.\n"));
|
|---|
| 699 | }
|
|---|
| 700 | distro_specific_kludges_at_end_of_mondoarchive();
|
|---|
| 701 | register_pid(0, "mondo");
|
|---|
| 702 | set_signals(FALSE);
|
|---|
| 703 |
|
|---|
| 704 | free_libmondo_global_strings();
|
|---|
| 705 | mr_free(bkpinfo);
|
|---|
| 706 |
|
|---|
| 707 | if (!g_cdrom_drive_is_here) {
|
|---|
| 708 | mr_msg(10, "FYI, g_cdrom_drive_is_here was never used");
|
|---|
| 709 | }
|
|---|
| 710 | if (!g_dvd_drive_is_here) {
|
|---|
| 711 | mr_msg(10, "FYI, g_dvd_drive_is_here was never used");
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | /* finalize log file with time stamp */
|
|---|
| 715 | mr_msg(1, "Time finished: %s", mr_date());
|
|---|
| 716 | mr_msg_close();
|
|---|
| 717 |
|
|---|
| 718 | chdir("/tmp");
|
|---|
| 719 |
|
|---|
| 720 | if (!g_text_mode) {
|
|---|
| 721 | popup_and_OK
|
|---|
| 722 | (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
|
|---|
| 723 | log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
|
|---|
| 724 | } else {
|
|---|
| 725 | printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
|
|---|
| 726 | mr_exit(retval, NULL);
|
|---|
| 727 | }
|
|---|
| 728 | finish(retval);
|
|---|
| 729 |
|
|---|
| 730 | return EXIT_SUCCESS;
|
|---|
| 731 | }
|
|---|