summaryrefslogtreecommitdiff
path: root/ota-upload.sh
blob: cc47fdb0f57c0333ab513e18e2f8b9d06faeb52f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

set -e

DIR="$(dirname "$(realpath "$0")")"
PROGNAME="$0"

OTA_DIR="~/LineageOTA/builds/full"
OTA_USER="lineage"
OTA_HOST="lineageos-ota.ch1p.io"
OTA_PORT=60011

BOLD=$(tput bold)
RST=$(tput sgr0)
RED=$(tput setaf 1)
CYAN=$(tput setaf 6)

echoinfo() {
	>&2 echo "${CYAN}$@${RST}"
}

echoerr() {
	>&2 echo "${RED}${BOLD}error:${RST}${RED} $@${RST}"
}

die() {
    echoerr "$@"
    exit 1
}

usage() {
	cat <<-_EOF 
	usage: $PROGNAME OPTIONS DEVICE

	Options:
	    --root DIR  LineageOS root

	_EOF
	exit 1
}

ROOT=
DEVICE=

while [[ $# -gt 0 ]]; do
	case $1 in
		--root)
			ROOT="$2"
			shift
			;;
		*)
			if [ -n "$DEVICE" ]; then
				die "unexpected extra argument: $1"
			fi
			DEVICE="$1"
	esac
	shift
done

[ -z "$DEVICE" ] && die "no device specified"
[ -z "$ROOT" ] && die "lineageos root device not specified"
[ -d "$ROOT" ] || die "$ROOT: no such directory"

PRODUCT_DIR="$ROOT/out/target/product/$DEVICE"
[ -d "$PRODUCT_DIR" ] || die "product directory for device \"$DEVICE\" not found"

ZIP="$(realpath "$(find "$PRODUCT_DIR" -type f -samefile "$PRODUCT_DIR/lineage_${DEVICE}-ota-eng.user.zip" | grep -v "lineage_${DEVICE}-ota-eng.user.zip" | sort -r | head -1)")"
ZIP_NAME="$(basename "$ZIP")"

PROP="$PRODUCT_DIR/system/build.prop"
PROP_NAME="${ZIP_NAME}.prop"

echo 
echo "    Device: ${BOLD}${DEVICE}${RST}"
echo "       ZIP: ${BOLD}${ZIP_NAME}${RST}"
echo

echo -n "Press enter to confirm or Ctrl+C to cancel."
read

echoinfo "uploading zip (${BOLD}${ZIP_NAME}${RST}${CYAN})${RST}"
scp -P$OTA_PORT "$ZIP" $OTA_USER@$OTA_HOST:$OTA_DIR/

echoinfo "uploading prop file (${BOLD}${PROP_NAME}${RST}${CYAN})${RST}"
scp -P$OTA_PORT "$PROP" $OTA_USER@$OTA_HOST:$OTA_DIR/$PROP_NAME