cyberchallenge-modem/update/update.sh

40 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
/bin/echo "Usage: sudo clearpassword=<password> -E update.sh"
password=`/bin/cat /etc/txtpwd`
auth=`/bin/echo -n $clearpassword | /bin/sha512sum | /bin/cut -d' ' -f 1`
if [ "$auth" != "$password" ]; then
/bin/echo "Wrong password"
exit 1
fi
pubkey="/pub.pem"
file="/tmp/update.tgz.cc"
/bin/echo "### ccOS Update Script ###"
/bin/echo "[+] Starting"
/usr/bin/sleep 1
/bin/echo "[+] Extracting Signature"
skip=$(expr $(stat -c '%s' $file) - 256)
if [[ -L $file ]]
then
exit 0
fi
/usr/bin/dd if=/tmp/update.tgz.cc of=sig bs=1 count=256 skip=$skip > /dev/null 2>&1
/usr/bin/truncate -s $skip update.tgz.cc
check=`/usr/bin/openssl dgst -sha256 -verify $pubkey -signature /tmp/sig /tmp/update.tgz.cc`
if [ "$check" == "Verified OK" ]
then
/bin/echo "[+] Signature is valid!"
/bin/echo "[+] Upgrading..."
/usr/bin/tar -xvzf /tmp/update.tgz.cc -C /
/bin/rm /tmp/update.tgz.cc /tmp/sig
/bin/echo "[+] Done"
exit 0
else
/bin/echo "[-] Signature error, exiting..."
/bin/rm /tmp/update.tgz.cc /tmp/sig
exit 1
fi