From 38c6822d3c99104978975352bcfe80fb13a94c72 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 15 Oct 2014 23:38:05 +0200 Subject: [PATCH] installer: Make restoring the backup interactive --- config/syslinux/unattended.conf | 12 ------------ lfs/cdrom | 4 ---- src/installer/hw.c | 24 ++++++++++++++++++++++++ src/installer/hw.h | 3 +++ src/installer/main.c | 23 ++++++++++++++++++----- src/scripts/backupiso | 4 ++-- 6 files changed, 47 insertions(+), 23 deletions(-) delete mode 100644 config/syslinux/unattended.conf diff --git a/config/syslinux/unattended.conf b/config/syslinux/unattended.conf deleted file mode 100644 index 169463bb9c..0000000000 --- a/config/syslinux/unattended.conf +++ /dev/null @@ -1,12 +0,0 @@ -DOMAINNAME=localdomain -HOSTNAME=ipfire -KEYMAP=/lib/kbd/keymaps/i386/qwerty/us.map.gz -LANGUAGE=en -TIMEZONE=/usr/share/zoneinfo/posix/Europe/Berlin -THEME=ipfire -GREEN_ADDRESS=192.168.0.1 -GREEN_NETMASK=255.255.255.0 -GREEN_NETADDRESS=192.168.0.0 -GREEN_BROADCAST=192.168.0.255 -ROOT_PASSWORD=ipfire -ADMIN_PASSWORD=ipfire diff --git a/lfs/cdrom b/lfs/cdrom index 7a569a0caa..79920b8ddb 100644 --- a/lfs/cdrom +++ b/lfs/cdrom @@ -86,10 +86,6 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) cp $(DIR_SRC)/doc/COPYING /install/cdrom/ cp $(DIR_SRC)/doc/{ChangeLog,packages-list.txt} /install/cdrom/doc - # Configuration - mkdir -p /install/cdrom/boot - cp $(DIR_SRC)/config/syslinux/unattended.conf /install/cdrom/boot/unattended.conf - # Make the ISO mkdir -p /install/cdrom/boot/isolinux dd if=/dev/zero bs=1k count=2 > /install/cdrom/boot/isolinux/boot.catalog diff --git a/src/installer/hw.c b/src/installer/hw.c index 4e65a8b7a0..9b9a2d0029 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -1041,3 +1041,27 @@ void hw_sync() { int hw_start_networking(const char* output) { return mysystem(output, "/usr/bin/start-networking.sh"); } + +char* hw_find_backup_file(const char* output, const char* search_path) { + char path[STRING_SIZE]; + + snprintf(path, sizeof(path), "%s/backup.ipf", search_path); + int r = access(path, R_OK); + + if (r == 0) + return strdup(path); + + return NULL; +} + +int hw_restore_backup(const char* output, const char* backup_path, const char* destination) { + char command[STRING_SIZE]; + + snprintf(command, sizeof(command), "/bin/tar xzpf %s -C %s", backup_path, destination); + int rc = mysystem(output, command); + + if (rc) + return -1; + + return 0; +} diff --git a/src/installer/hw.h b/src/installer/hw.h index c5285d543e..41ff093ad2 100644 --- a/src/installer/hw.h +++ b/src/installer/hw.h @@ -128,6 +128,9 @@ int hw_stop_all_raid_arrays(const char* output); int hw_install_bootloader(struct hw_destination* dest, const char* output); int hw_write_fstab(struct hw_destination* dest); +char* hw_find_backup_file(const char* output, const char* search_path); +int hw_restore_backup(const char* output, const char* backup_path, const char* destination); + void hw_sync(); #endif /* HEADER_HW_H */ diff --git a/src/installer/main.c b/src/installer/main.c index ba50cd9b6f..36f8dfec81 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -722,11 +722,24 @@ int main(int argc, char *argv[]) { mysystem(logfile, "/usr/bin/touch /harddisk/var/ipfire/main/gpl_accepted"); /* Copy restore file from cdrom */ - if (unattended && (strlen(restore_file) > 0)) { - fprintf(flog, "unattended: Copy restore file\n"); - snprintf(commandstring, STRING_SIZE, - "cp /cdrom/%s /harddisk/var/ipfire/backup", restore_file); - mysystem(logfile, commandstring); + char* backup_file = hw_find_backup_file(logfile, SOURCE_MOUNT_PATH); + if (backup_file) { + rc = 0; + if (!unattended) { + rc = newtWinOkCancel(title, _("A backup file has been found on the installation image.\n\n" + "Do you want to restore the backup?"), 50, 10, _("Yes"), _("No")); + } + + if (rc == 0) { + rc = hw_restore_backup(logfile, backup_file, DESTINATION_MOUNT_PATH); + + if (rc) { + errorbox(_("An error occured when the backup file was restored.")); + goto EXIT; + } + } + + free(backup_file); } // Umount the destination drive diff --git a/src/scripts/backupiso b/src/scripts/backupiso index a340d6f146..fb203bd2a7 100644 --- a/src/scripts/backupiso +++ b/src/scripts/backupiso @@ -53,8 +53,8 @@ cp -pr backupiso.tmp.${TS} backupiso.${TS} umount backupiso.tmp.${TS} rm -r backupiso.tmp.${TS} -echo "RESTORE_FILE=${TS}.ipf" >> backupiso.${TS}/boot/unattended.conf -cp /var/ipfire/backup/${TS}.ipf backupiso.${TS} +# Copy backup file to disk +cp "/var/ipfire/backup/${TS}.ipf" "backupiso.${TS}/backup.ipf" echo "Running mkisofs" mkisofs -J -r -V "ipfire backup ${TS}" \ -- 2.39.2