cyberchallenge-modem/update/update.sh

30 lines
754 B
Bash
Raw Permalink Normal View History

2020-05-22 18:34:46 +02:00
#!/bin/sh
2020-05-19 17:55:09 +02:00
pubkey="/pub.pem"
2020-05-22 18:34:46 +02:00
file="/tmp/update.tgz.cc"
2020-05-19 17:55:09 +02:00
echo "### ccOS Update Script ###"
echo "[+] Starting"
sleep 1
echo "[+] Extracting Signature"
2020-05-22 18:34:46 +02:00
skip=$(expr $(stat -c '%s' $file) - 256)
if [[ -L $file ]]
then
exit 0
fi
2020-05-19 17:55:09 +02:00
dd if=/tmp/update.tgz.cc of=sig bs=1 count=256 skip=$skip > /dev/null 2>&1
truncate -s $skip update.tgz.cc
check=`openssl dgst -sha256 -verify $pubkey -signature /tmp/sig /tmp/update.tgz.cc`
if [ "$check" == "Verified OK" ]
then
echo "[+] Signature is valid!"
echo "[+] Upgrading..."
tar -xvzf /tmp/update.tgz.cc -C /
rm /tmp/update.tgz.cc /tmp/sig
echo "[+] Done"
exit 0
else
echo "[-] Signature error, exiting..."
rm /tmp/update.tgz.cc /tmp/sig
exit 1
fi