2018-03-02 08:18:08 -08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-12-04 22:47:49 -08:00
|
|
|
updates_dir=/data/crdroid_updates
|
2018-03-02 08:18:08 -08:00
|
|
|
|
|
|
|
if [ ! -f "$1" ]; then
|
|
|
|
echo "Usage: $0 ZIP [UNVERIFIED]"
|
|
|
|
echo "Push ZIP to $updates_dir and add it to Updater"
|
|
|
|
echo
|
2021-12-04 22:47:49 -08:00
|
|
|
echo "The name of ZIP is assumed to have crdroid-VERSION-DATE-TYPE-* as format"
|
2018-03-02 08:18:08 -08:00
|
|
|
echo "If UNVERIFIED is set, the app will verify the update"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
zip_path=`realpath "$1"`
|
|
|
|
|
|
|
|
if [ "`adb get-state 2>/dev/null`" != "device" ]; then
|
|
|
|
echo "No device found. Waiting for one..."
|
|
|
|
adb wait-for-device
|
|
|
|
fi
|
|
|
|
if ! adb root; then
|
|
|
|
echo "Could not run adbd as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
zip_path_device=$updates_dir/`basename "$zip_path"`
|
|
|
|
if adb shell test -f "$zip_path_device"; then
|
|
|
|
echo "$zip_path_device exists already"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
status=1
|
|
|
|
else
|
|
|
|
status=2
|
|
|
|
fi
|
|
|
|
|
2021-12-04 22:47:49 -08:00
|
|
|
# Assume crdroid-VERSION-DATE-TYPE-*.zip
|
2018-03-02 08:18:08 -08:00
|
|
|
zip_name=`basename "$zip_path"`
|
|
|
|
id=`echo "$zip_name" | sha1sum | cut -d' ' -f1`
|
|
|
|
version=`echo "$zip_name" | cut -d'-' -f2`
|
|
|
|
type=`echo "$zip_name" | cut -d'-' -f4`
|
|
|
|
build_date=`echo "$zip_name" | cut -d'-' -f3 | cut -d'_' -f1`
|
2020-12-28 02:09:08 -08:00
|
|
|
if [ "`uname`" = "Darwin" ]; then
|
2020-03-05 04:11:39 -08:00
|
|
|
timestamp=`date -jf "%Y%m%d %H:%M:%S" "$build_date 23:59:59" +%s`
|
|
|
|
size=`stat -f%z "$zip_path"`
|
|
|
|
else
|
|
|
|
timestamp=`date --date="$build_date 23:59:59" +%s`
|
|
|
|
size=`stat -c "%s" "$zip_path"`
|
|
|
|
fi
|
2018-03-02 08:18:08 -08:00
|
|
|
|
|
|
|
adb push "$zip_path" "$zip_path_device"
|
|
|
|
adb shell chgrp cache "$zip_path_device"
|
|
|
|
adb shell chmod 664 "$zip_path_device"
|
|
|
|
|
|
|
|
# Kill the app before updating the database
|
2021-12-04 22:47:49 -08:00
|
|
|
adb shell "killall com.crdroid.updater 2>/dev/null"
|
|
|
|
adb shell "sqlite3 /data/data/com.crdroid.updater/databases/updates.db" \
|
2018-03-02 08:18:08 -08:00
|
|
|
"\"INSERT INTO updates (status, path, download_id, timestamp, type, version, size)" \
|
|
|
|
" VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', $size)\""
|
2018-07-26 13:47:12 -07:00
|
|
|
|
|
|
|
# Exit root mode
|
|
|
|
adb unroot
|