Dyad/rex.project/x86_64/components/backup/offer_backup.bash

109 lines
3.0 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# move this to the makefile as a dedicated target
2023-03-11 23:00:47 +00:00
set -u
APPNAME="Offer Backup"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H%M%S)"
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the file to log to
LOGFILE="${APPNAME}.log"
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
logprint "Giving the user the option of backing up before proceeding."
is_mounted() {
findmnt $1 &> /dev/null
if [ $? != 0 ]; then
logprint "Not mounted...skipping."
/usr/bin/false
else
logprint "Mounted..."
/usr/bin/true
fi
}
function disarm_chroot() {
logprint "Unmounting CHROOT VFKS mounts"
logprint "Unmounting ${T_SYSROOT}/dev"
is_mounted ${T_SYSROOT}/dev && umount -l ${T_SYSROOT}/dev
logprint "Unmounting ${T_SYSROOT}/dev/pts"
is_mounted ${T_SYSROOT}/dev/pts && umount -l ${T_SYSROOT}/dev/pts
logprint "Unmounting ${T_SYSROOT}/proc"
is_mounted ${T_SYSROOT}/proc && umount -l ${T_SYSROOT}/proc
# not a symlink on ubuntu
logprint "Unmounting ${T_SYSROOT}/dev/shm"
is_mounted ${T_SYSROOT}/dev/shm && umount -l ${T_SYSROOT}/dev/shm
logprint "Unmounting pyrois inside of chroot"
is_mounted ${T_SYSROOT}/rex_embedded && umount -l ${T_SYSROOT}/rex_embedded
}
function perform_backup() {
logprint "Entering backup routine."
disarm_chroot
disarm_chroot
logprint "Performing backup...This will take a long time..."
pushd ${dir_artifacts}
tar cpzf ${project_root}/${TIMESTAMP}.backup.tgz *
assert_zero $?
logprint "Backup completed successfully. Moving on."
logprint "Entering project root."
pushd ${project_root}
assert_zero $?
logprint "Re-arming chroot..."
make arm_chroot
echo
}
read -r -d '' msg <<-'EOF'
2023-04-02 06:38:20 +00:00
The following prompt will ask if you'd like to back up the
existing sysroot. This is useful for debugging, so that you don't have
to wait for the entire cross-compilation for every change.
If you select yes, you will see a gzipped tarball containing the
sysroot generated in your project root. If you select no, your backup
2023-04-02 06:38:20 +00:00
will not be created.
If you skip the backup and something fails from here, you'll need to
run "make clean" and start from the beginning.
If you do decide to back up, which you should, should you need to
restore from your backup, simply running "make restore" will perform
the operations necessary.
EOF
read -r -d '' yn_msg <<-'EOF'
Do you want to back up the stage?
If you select yes, the VKFS mounts for the chroot will be unmounted temporarily to perform this operation.
EOF
# Use the dialog utility to display information to the user
dialog --backtitle "Dark Horse Linux: Pyrois" --title "IMPORTANT NOTICE" --msgbox "$msg" 20 78
# Use the dialog utility to prompt the user with a yes/no question
dialog --backtitle "Dark Horse Linux: Pyrois" --title "Back up the stage?" --yesno "$yn_msg" 10 60
response=$?
if [ $response -eq 0 ]; then
logprint "User selected to perform backups."
perform_backup
else
logprint "User selected to skip backups. Moving on."
exit 0
fi