blob: 52bc6da4a7a53961365fc5c52663892285cda94f [file] [log] [blame]
Gabriele Me1983892018-03-02 17:18:08 +01001#!/bin/sh
2
Jackeagle18950b72019-03-26 00:20:46 +05303updates_dir=/data/bliss_updaters
Gabriele Me1983892018-03-02 17:18:08 +01004
5if [ ! -f "$1" ]; then
6 echo "Usage: $0 ZIP [UNVERIFIED]"
7 echo "Push ZIP to $updates_dir and add it to Updater"
8 echo
9 echo "The name of ZIP is assumed to have lineage-VERSION-DATE-TYPE-* as format"
10 echo "If UNVERIFIED is set, the app will verify the update"
11 exit
12fi
13zip_path=`realpath "$1"`
14
15if [ "`adb get-state 2>/dev/null`" != "device" ]; then
16 echo "No device found. Waiting for one..."
17 adb wait-for-device
18fi
19if ! adb root; then
20 echo "Could not run adbd as root"
21 exit 1
22fi
23
24zip_path_device=$updates_dir/`basename "$zip_path"`
25if adb shell test -f "$zip_path_device"; then
26 echo "$zip_path_device exists already"
27 exit 1
28fi
29
30if [ -n "$2" ]; then
31 status=1
32else
33 status=2
34fi
35
36# Assume lineage-VERSION-DATE-TYPE-*.zip
37zip_name=`basename "$zip_path"`
38id=`echo "$zip_name" | sha1sum | cut -d' ' -f1`
39version=`echo "$zip_name" | cut -d'-' -f2`
40type=`echo "$zip_name" | cut -d'-' -f4`
41build_date=`echo "$zip_name" | cut -d'-' -f3 | cut -d'_' -f1`
42timestamp=`date --date="$build_date 23:59:59" +%s`
43size=`stat -c "%s" "$zip_path"`
44
45adb push "$zip_path" "$zip_path_device"
46adb shell chgrp cache "$zip_path_device"
47adb shell chmod 664 "$zip_path_device"
48
49# Kill the app before updating the database
Jackeagle18950b72019-03-26 00:20:46 +053050adb shell "killall com.blissroms.updater 2>/dev/null"
51adb shell "sqlite3 /data/data/com.blissroms.updater/databases/updates.db" \
Gabriele Me1983892018-03-02 17:18:08 +010052 "\"INSERT INTO updates (status, path, download_id, timestamp, type, version, size)" \
53 " VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', $size)\""
Rashed Abdel-Tawab1022c6b2018-07-26 16:47:12 -040054
55# Exit root mode
56adb unroot