Gabriele M | e198389 | 2018-03-02 17:18:08 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Jackeagle | 7324036 | 2019-01-27 18:07:02 +0530 | [diff] [blame] | 3 | updates_dir=/data/bliss_updates |
Gabriele M | e198389 | 2018-03-02 17:18:08 +0100 | [diff] [blame] | 4 | |
| 5 | if [ ! -f "$1" ]; then |
| 6 | echo "Usage: $0 ZIP [UNVERIFIED]" |
| 7 | echo "Push ZIP to $updates_dir and add it to Updater" |
| 8 | echo |
Jackeagle | 7324036 | 2019-01-27 18:07:02 +0530 | [diff] [blame] | 9 | echo "The name of ZIP is assumed to have Bliss-VERSION-CODENAME-TYPE-DATE.* as format" |
Gabriele M | e198389 | 2018-03-02 17:18:08 +0100 | [diff] [blame] | 10 | echo "If UNVERIFIED is set, the app will verify the update" |
| 11 | exit |
| 12 | fi |
| 13 | zip_path=`realpath "$1"` |
| 14 | |
| 15 | if [ "`adb get-state 2>/dev/null`" != "device" ]; then |
| 16 | echo "No device found. Waiting for one..." |
| 17 | adb wait-for-device |
| 18 | fi |
| 19 | if ! adb root; then |
| 20 | echo "Could not run adbd as root" |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
| 24 | zip_path_device=$updates_dir/`basename "$zip_path"` |
| 25 | if adb shell test -f "$zip_path_device"; then |
| 26 | echo "$zip_path_device exists already" |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | if [ -n "$2" ]; then |
| 31 | status=1 |
| 32 | else |
| 33 | status=2 |
| 34 | fi |
| 35 | |
Jackeagle | 7324036 | 2019-01-27 18:07:02 +0530 | [diff] [blame] | 36 | # Assume Bliss-VERSION-CODENAME-TYPE-DATE.zip |
Gabriele M | e198389 | 2018-03-02 17:18:08 +0100 | [diff] [blame] | 37 | zip_name=`basename "$zip_path"` |
| 38 | id=`echo "$zip_name" | sha1sum | cut -d' ' -f1` |
| 39 | version=`echo "$zip_name" | cut -d'-' -f2` |
| 40 | type=`echo "$zip_name" | cut -d'-' -f4` |
| 41 | build_date=`echo "$zip_name" | cut -d'-' -f3 | cut -d'_' -f1` |
chrmhoffmann | 29ca6e5 | 2020-12-28 11:09:08 +0100 | [diff] [blame] | 42 | if [ "`uname`" = "Darwin" ]; then |
Mickey Knox | 416401a | 2020-03-05 13:11:39 +0100 | [diff] [blame] | 43 | timestamp=`date -jf "%Y%m%d %H:%M:%S" "$build_date 23:59:59" +%s` |
| 44 | size=`stat -f%z "$zip_path"` |
| 45 | else |
| 46 | timestamp=`date --date="$build_date 23:59:59" +%s` |
| 47 | size=`stat -c "%s" "$zip_path"` |
| 48 | fi |
Gabriele M | e198389 | 2018-03-02 17:18:08 +0100 | [diff] [blame] | 49 | |
| 50 | adb push "$zip_path" "$zip_path_device" |
| 51 | adb shell chgrp cache "$zip_path_device" |
| 52 | adb shell chmod 664 "$zip_path_device" |
| 53 | |
| 54 | # Kill the app before updating the database |
Jackeagle | 7324036 | 2019-01-27 18:07:02 +0530 | [diff] [blame] | 55 | adb shell "killall com.blissroms.updater 2>/dev/null" |
| 56 | adb shell "sqlite3 /data/data/com.blissroms.updater/databases/updates.db" \ |
Gabriele M | e198389 | 2018-03-02 17:18:08 +0100 | [diff] [blame] | 57 | "\"INSERT INTO updates (status, path, download_id, timestamp, type, version, size)" \ |
| 58 | " VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', $size)\"" |
Rashed Abdel-Tawab | 1022c6b | 2018-07-26 16:47:12 -0400 | [diff] [blame] | 59 | |
| 60 | # Exit root mode |
| 61 | adb unroot |