#!/bin/sh

COPYCFG=0
ONLYKERNEL=0

while getopts ck flag
do
    case "${flag}" in
        c) COPYCFG=1;;
        k) ONLYKERNEL=1;;
    esac
done

if [ "$ONLYKERNEL" -eq "1" ]; then
    "$(dirname "$0")"/update_kernel_only.sh 2>&1 | tee /home/user/update_kernel_only.log
    exit
fi

echo "Update.sh Log"      > /home/user/LogUpdate.txt
echo "==================" >> /home/user/LogUpdate.txt
date                      >> /home/user/LogUpdate.txt
echo ""                   >> /home/user/LogUpdate.txt

"$(dirname "$0")"/update_real.sh 2>&1 | tee /home/user/update.log

cat /home/user/update.log >> /home/user/LogUpdate.txt

cp /home/user/LogUpdate.txt /mnt/inactive_rootfs/home/user/LogUpdate.txt

if [ "$COPYCFG" -eq "1" ]; then
    if [ -d "/mnt/inactive_rootfs/home/user" ] ; then
        mkdir -p /mnt/inactive_rootfs/home/user/simulatedPrinter/drives/Z
        cp -f /home/user/simulatedPrinter/drives/Z/scfg.ini /mnt/inactive_rootfs/home/user/simulatedPrinter/drives/Z/scfg.ini
    fi
fi
