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