gemian-system/debian/postinst

55 lines
1.4 KiB
Bash
Executable file

#!/bin/bash -e
action="$1"
oldversion="$2"
if [ "$action" != configure ]; then
exit 0
fi
cmdline=$(</proc/cmdline)
android_system_img="unknown"
target_checksum="unknown"
if [[ "$cmdline" =~ ^(.*)androidboot.hardware\=mt6797(.*)$ ]];
then
android_system_img="/data/system.img"
target_checksum="39cd17718e838823c80be0ddfc9763d88e32c1b0"
fi
if [[ "$cmdline" =~ ^(.*)androidboot.hardware\=mt6771(.*)$ ]];
then
android_system_img="/var/lib/lxc/android/android-rootfs.img"
target_checksum="4478ce425e593fb708b86234a8ea83e6fcdaaeec"
fi
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"
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