#!/bin/sh
# Description: Script to be executed after a liveburner upgrade.
# It will mount a safezone to backup the configuration files AFTER
# the installation of the new firmware. Actions are done at this step
# because expected files from /tmp/burner are available (not available in preinst)

SAFEZONE_MOUNTPOINT="/tmp/safezone"
ROOTFSRW_PATH="/"
LOGFILE="${SAFEZONE_MOUNTPOINT}/upgrade.log"


fatal_error()
{
	echo "$1"
	touch /.need_reboot
	exit 1
}


# Backup preapps, postapps and prereboot files
#
backup_hooks()
{
	echo "Backuping hook files in safezone..."
	mkdir -p ${SAFEZONE_MOUNTPOINT}/burner
	for elem in $(ls "/tmp/burner/")
	do
		cp -f "/tmp/burner/${elem}" "${SAFEZONE_MOUNTPOINT}/burner/"
		echo "File ${elem} moved to safezone"
	done
}

####################
# MAIN KEROS PART
####################

echo -e "\n== START of POSTINST script ==\n" 2>&1 | tee ${LOGFILE}

# Move preapps, postapps, prereboot and ipk files to safezone
backup_hooks 2>&1 | tee -a ${LOGFILE}

####################
# MAIN CUSTOMER PART
####################

# Example:
# cp ${ROOTFSRW_PATH}/etc/hosts ${SAFEZONE_MOUNTPOINT}/

echo -e "\n== End of POSTINST script ==\n" 2>&1 | tee -a ${LOGFILE}
sync
