From a8cc3f324dba617551bb091c7cf4dcde1c9eea17 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Sun, 12 May 2019 00:58:30 +0200 Subject: WiP: update script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- update.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 update.sh 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 -- cgit v1.2.3