los-utils/ota-upload.sh
2023-01-22 21:16:53 +03:00

91 lines
1.8 KiB
Bash
Executable File

#!/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
-h, --help show this help
_EOF
exit 1
}
ROOT=
DEVICE=
[ -z "$1" ] && usage
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
;;
--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" | grep -e .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