summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2019-05-12 00:58:30 +0200
committerBjørn Mork <bjorn@mork.no>2019-05-12 00:58:30 +0200
commita8cc3f324dba617551bb091c7cf4dcde1c9eea17 (patch)
tree32be60f29c2053ceae21d39893ef1434b1740a47
parenta8c7339807e15a5dd8e29add39a97e017297e858 (diff)
WiP: update script
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--update.sh94
1 files changed, 94 insertions, 0 deletions
diff --git a/update.sh b/update.sh
new file mode 100644
index 0000000..dc8faca
--- /dev/null
+++ b/update.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+VENDOR="Alphanetworks"
+HWBOARD="r8000lh"
+HWVERSION="1.0.0"
+OEM="D-Link"
+MODEL="DCS-8000LH"
+PRODUCT="Internet Camera"
+VERSION="1.0.0-9999"
+PACKAGE=""
+WIRELESS_MODULE="RTL8723BU"
+DESCRIPT="An alternative opt."
+
+showBrief() {
+ echo -n "\
+
+This updates the userdata partition only.
+It will update following, ...
+ 1. /opt file system
+"
+}
+
+MD5SUM="acf7f6c0881b64f53018a26dd3e3b8c0"
+
+MECH_SIGN="QPAT"
+MECH_VERSION="1.0"
+MECH_APP="doUpdate"
+
+showUsage() {
+ echo "Usage: $0 [ info | brief | exam | update ]" 1>&2
+}
+
+exam() {
+ rm -f /tmp/update/md5
+ for i in $(cat /tmp/update/certificate.info | grep Contents | cut -d":" -f2); do
+ echo $(tar xOf "$1" $i.aes | openssl aes-128-cbc -k `cat /tmp/update/aes.key` -nosalt -d | md5sum - | cut -d' ' -f1 ) >> /tmp/update/md5
+ done
+ md5sum=$(md5sum /tmp/update/md5 | cut -d' ' -f1)
+ [ "$MD5SUM" = "$md5sum" ] && return 0
+
+ echo "md5sum failed" 1>&2
+ return 1
+}
+
+self="$0"
+action=$1
+enc_bin=$2
+end=$3
+
+if [ "$action" = "" ] || [ "$end" != "" ]; then
+ showUsage
+ exit 1
+fi
+
+if [ "$action" = "info" ]; then
+ echo -n "\
+MECH_SIGN=\"$MECH_SIGN\"
+MECH_VERSION=\"$MECH_VERSION\"
+MECH_APP=\"$MECH_APP\"
+HWBOARD=\"$HWBOARD\"
+HWVERSION=\"$HWVERSION\"
+MODEL=\"$MODEL\"
+PRODUCT=\"$PRODUCT\"
+OEM=\"$OEM\"
+VENDOR=\"$VENDOR\"
+VERSION=\"$VERSION\"
+DESCRIPT=\"$DESCRIPT\"
+PACKAGE=\"$PACKAGE\"
+"
+ exit 0
+fi
+
+if [ "$action" = "brief" ]; then
+ showBrief
+ exit 0
+fi
+
+if [ "$action" = "exam" ]; then
+ exam "$enc_bin" || exit 1
+ exit 0
+fi
+
+if [ "$action" = "update" ]; then
+ /etc/rc.d/init.d/services.sh stop > /dev/null 2> /dev/null
+ exam "$enc_bin" || { /etc/rc.d/init.d/services.sh start > /dev/null 2> /dev/null && exit 1; }
+
+ userdata="/dev/$(grep '"userdata"' /proc/mtd |cut -f1 -d:)"
+ tar xOf "$enc_bin" update.aes | openssl aes-128-cbc -k `cat /tmp/update/aes.key` -nosalt -d | dd of="$userdata" > /dev/null 2> /dev/null || exit 1
+
+ {(sleep 5 && reboot) > /dev/null 2> /dev/null &}
+ exit 0
+fi
+
+# unknown action
+showUsage && exit 1