cyberchallenge-modem/update/update.sh

44 lines
1.2 KiB
Bash
Raw Normal View History

2020-05-22 18:34:46 +02:00
#!/bin/sh
2020-05-19 17:55:09 +02:00
if [[ -z $key ]]; then
/bin/echo "Usage: sudo key=<update_key> -E update.sh"
2020-09-17 16:09:01 +02:00
exit 1
fi
password=`/bin/cat /etc/update_key | /usr/bin/sha512sum | /usr/bin/cut -d' ' -f 1`
auth=`/bin/echo -n $key | /usr/bin/sha512sum | /usr/bin/cut -d' ' -f 1`
2020-09-17 16:09:01 +02:00
if [[ "$auth" != "$password" ]]; then
/bin/echo "Wrong password"
exit 1
fi
2020-05-19 17:55:09 +02:00
pubkey="/pub.pem"
2020-05-22 18:34:46 +02:00
file="/tmp/update.tgz.cc"
/bin/echo "### ccOS Update Script ###"
/bin/echo "[+] Starting"
2020-09-17 15:45:14 +02:00
/bin/sleep 1
/bin/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-09-21 09:57:13 +02:00
/bin/dd if=/tmp/update.tgz.cc of=sig bs=1 count=256 skip=$skip
/usr/bin/truncate -s $skip update.tgz.cc
check=`/usr/bin/openssl dgst -sha256 -verify $pubkey -signature /tmp/sig /tmp/update.tgz.cc`
2020-05-19 17:55:09 +02:00
if [ "$check" == "Verified OK" ]
then
/bin/echo "[+] Signature is valid!"
/bin/echo "[+] Upgrading..."
/bin/tar -xvzf /tmp/update.tgz.cc -C /
/bin/rm /tmp/update.tgz.cc /tmp/sig
/bin/echo "[+] Done"
2020-05-19 17:55:09 +02:00
exit 0
else
/bin/echo "[-] Signature error, exiting..."
/bin/rm /tmp/update.tgz.cc /tmp/sig
2020-05-19 17:55:09 +02:00
exit 1
fi