# upgrade-from-disk-EABI

UPGRADE_MARKER="/.magic_upgrade"
UPGRADE_LOG="/var/log/upgrade.log"
RSYNC_MODULE="CMG-DCM-mk4-eabi"



# Check we're a valid target for EABI upgrade.
if [ ! -e "/etc/system_type" ]
then
	echo "Very old system? Try running /mnt/upgrade first."
	exit 1
fi
. "/etc/system_type"
if [ "$BUILD_MACHINE" != "CMG-DCM-mk4" ]
then
    echo "System is not an EAM, or is already configured for EABI. Please use"
    echo "the standard upgrade command."
    exit 1
fi



# The following commands must always succeed
set -e

# Save a copy of this static executable in /root for use after we've rsynced
cp /mnt/CMG-DCM-mk4/lib/platinum/force-reboot /root

# Run the upgrade scripts on the next boot
touch "${UPGRADE_MARKER}"
sync

# do upgrade
echo "$(isodate -se) -- Beginning EABI upgrade from disk." >> "${UPGRADE_LOG}"
rsync \
    --super \
    --verbose --stats --human-readable --progress --itemize-changes \
    --archive --no-perms --no-owner --no-group --chmod=ugo=rwX \
    --delete --delete-delay --force \
    --exclude "/dev" --exclude "lost+found" --exclude "/mnt" --exclude "/media" \
    --exclude "/proc" --exclude "/sys" --exclude "/tmp" --exclude "resolv.conf" \
    --exclude "/run" --exclude "/boot/grub" \
    --exclude "/etc/shadow" --exclude "*.local" --exclude "/home" \
    --exclude "/root" --exclude "/usr/local" --exclude "/var" \
    --exclude "${UPGRADE_MARKER}" \
    "/mnt/${RSYNC_MODULE}/" "/"

# Try to reboot.
echo
echo :::: Rebooting to complete upgrade.
echo
/root/force-reboot
