113 lines
2.7 KiB
Bash
Executable file
113 lines
2.7 KiB
Bash
Executable file
#!/bin/bash -e
|
|
|
|
action="$1"
|
|
oldversion="$2"
|
|
|
|
if [ "$action" != configure ]; then
|
|
exit 0
|
|
fi
|
|
|
|
cmdline=$(</proc/cmdline)
|
|
device="unknown"
|
|
android_system_dir="unknown"
|
|
android_system_img="unknown"
|
|
target_checksum="unknown"
|
|
|
|
if [[ "$cmdline" =~ ^(.*)androidboot.hardware\=mt6797(.*)$ ]];
|
|
then
|
|
device="mt6797"
|
|
fi
|
|
|
|
if [[ "$cmdline" =~ ^(.*)androidboot.hardware\=mt6771(.*)$ ]];
|
|
then
|
|
device="mt6771"
|
|
fi
|
|
|
|
if [[ "$cmdline" =~ ^(.*)androidboot.hardware\=mt6873(.*)$ ]];
|
|
then
|
|
device="mt6873"
|
|
fi
|
|
|
|
if [[ "$device" == unknown ]]
|
|
then
|
|
model=$(</proc/device-tree/model)
|
|
if [[ "$model" =~ ^(.*)MT6797(.*)$ ]];
|
|
then
|
|
device="mt6797"
|
|
fi
|
|
|
|
if [[ "$model" =~ ^(.*)MT6771(.*)$ ]];
|
|
then
|
|
device="mt6771"
|
|
fi
|
|
|
|
if [[ "$model" =~ ^(.*)MT6873(.*)$ ]];
|
|
then
|
|
device="mt6873"
|
|
fi
|
|
fi
|
|
|
|
if [ "$device" == unknown ]; then
|
|
pid=$$
|
|
while [ "$device" == unknown -a $pid != 1 ]; do
|
|
env=`strings /proc/$pid/environ`
|
|
device=`echo "$env"|awk -F= '$1 == "TARGET_DEVICE" { print $2; }'`
|
|
pid=`ps -oppid -p$pid|tail -1|awk '{print $1}'`
|
|
done
|
|
fi
|
|
|
|
case $device in
|
|
"mt6797")
|
|
android_system_dir="/data"
|
|
android_system_img="/data/system.img"
|
|
target_checksum="39cd17718e838823c80be0ddfc9763d88e32c1b0"
|
|
;;
|
|
"mt6771")
|
|
android_system_dir="/var/lib/lxc/android"
|
|
android_system_img="/var/lib/lxc/android/android-rootfs.img"
|
|
target_checksum="f8b91bd83795c62f1e9b33be9a4156bdf4a90658"
|
|
;;
|
|
"mt6873")
|
|
android_system_dir="/var/lib/lxc/android"
|
|
android_system_img="/var/lib/lxc/android/android-rootfs.img"
|
|
target_checksum="719e8fea179d109aa64586e754d69c9a53da28cd"
|
|
;;
|
|
esac
|
|
|
|
[ -e /lib/udev/rules.d/80-keyboard.rules ] || \
|
|
cp /usr/lib/gemian/udev-rules/80-keyboard-$device.rules /lib/udev/rules.d/80-keyboard.rules
|
|
|
|
[ -e /lib/udev/rules.d/70-$device.rules ] || \
|
|
cp /usr/lib/gemian/udev-rules/70-$device.rules /lib/udev/rules.d/
|
|
|
|
echo "Target checksum $target_checksum"
|
|
|
|
echo "Checking $android_system_img"
|
|
|
|
current_checksum="$(sha1sum $android_system_img | cut -d' ' -f1)"
|
|
|
|
echo "Checksum $current_checksum"
|
|
|
|
if [ "$target_checksum" == "$current_checksum" ];
|
|
then
|
|
echo "Android system image upto date"
|
|
exit 0
|
|
else
|
|
tempfile="$(mktemp)"
|
|
rm $tempfile
|
|
echo "Downloading new Android system image"
|
|
curl https://gemian.thinkglobally.org/system/system.$target_checksum.img.xz --output $tempfile.xz
|
|
xz -d $tempfile.xz
|
|
downloaded_checksum="$(sha1sum $tempfile | cut -d' ' -f1)"
|
|
if [ "$target_checksum" == "$downloaded_checksum" ];
|
|
then
|
|
echo "Moving new system image into place, please reboot to activate"
|
|
mkdir -p $android_system_dir
|
|
mv $tempfile $android_system_img
|
|
exit 0
|
|
else
|
|
echo "Downloaded checksum fail - check your internet for random errors or man in the middle attacks and retry"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|