diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2021-04-01 21:31:01 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2021-04-01 21:31:01 -0300 |
commit | 63071d4c5c4d7f2147238810b7ec3f9d06df7bd9 (patch) | |
tree | e5b293df3543a39725e1acd0088b345707090102 /lineageos-dl | |
parent | 2f4cdd61a0e7138497311595ac4db638fd7f5fd5 (diff) | |
download | downloaders-63071d4c5c4d7f2147238810b7ec3f9d06df7bd9.tar.gz downloaders-63071d4c5c4d7f2147238810b7ec3f9d06df7bd9.tar.bz2 |
Feat: adds lineageos-dl
Diffstat (limited to 'lineageos-dl')
-rwxr-xr-x | lineageos-dl | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/lineageos-dl b/lineageos-dl new file mode 100755 index 0000000..e515cac --- /dev/null +++ b/lineageos-dl @@ -0,0 +1,98 @@ +#!/bin/bash +# +# Download LineageOS images +# + +# Parameters +BASENAME="`basename $0`" +DEVICE="$1" +VERSION="$2" +DATE="$3" +FILE="lineage-${VERSION}-${DATE}-nightly-${DEVICE}-signed.zip" +UPSTREAM="https://download.lineageos.org" +RECOVERY="lineage-${VERSION}-${DATE}-recovery-${DEVICE}.img" +RECOVERY_URL="https://mirrorbits.lineageos.org/recovery/${DEVICE}/${DATE}/${RECOVERY}" +BASE_URL="https://mirrorbits.lineageos.org/full/${DEVICE}/${DATE}/${FILE}" +DL_PAGE="https://download.lineageos.org/${DEVICE}" +DL_PATTERN="mirrorbits" +DL="$HOME/data/distros/lineageos/official/${DEVICE}" +CWD="`pwd`" + +# Determine latest image version +function lineageos_dl_determine_latest { + local type="$1" + + lynx -dump "${UPSTREAM}/${DEVICE}" | grep ${DL_PATTERN} | awk '{ print $2 }' | grep ${type} | sort -r | grep -v -v '?sha256' | head -1 +} + +# Syntax check +if [ -z "$DATE" ]; then + if [ ! -z "$DEVICE" ]; then + echo "$BASENAME: trying to guess download URLs and file names..." + BASE_URL="`lineageos_dl_determine_latest full`" + FILE="`basename $BASE_URL`" + RECOVERY_URL="`lineageos_dl_determine_latest recovery`" + RECOVERY="`basename $RECOVERY_URL`" + + if [ -z "$BASE_URL" ]; then + echo "error: could not automatically determine download URL, please specify version and build date manually" + exit 1 + fi + else + echo "usage: $BASENAME <device> [<version <build_date>]" + echo "example: $BASENAME cedric" + echo "example: $BASENAME cedric 17.1 20210325" + exit 1 + fi +fi + +# Set file names +HASH="$FILE.sha256" +RECOVERY_HASH="$RECOVERY.sha256" + +# Ensure destination folder exists +echo "$BASENAME: download destination set to $DL" +mkdir -p $DL + +# Download package +if [ ! -e "$DL/$FILE" ]; then + wget -c $BASE_URL -O $DL/$FILE || exit 1 +else + echo "$BASENAME: file $FILE already exists, skipping" +fi + +# Download signature +if [ ! -e "$DL/$HASH" ]; then + wget -c "$BASE_URL?sha256" -O $DL/$HASH || exit 1 +else + echo "$BASENAME: file $HASH already exists, skipping" +fi + +# Download recovery +if [ ! -e "$DL/$RECOVERY" ]; then + wget -c $RECOVERY_URL -O $DL/$RECOVERY || exit 1 +else + echo "$BASENAME: file $RECOVERY already exists, skipping" +fi + +# Download recovery signature +if [ ! -e "$DL/$RECOVERY_HASH" ]; then + wget -c $RECOVERY_URL?sha256 -O $DL/$RECOVERY_HASH || exit 1 +else + echo "$BASENAME: file $RECOVERY_HASH already exists, skipping" +fi + +cd $DL +echo "$BASENAME: checking hashes..." +sha256sum -c $HASH +sha256sum -c $RECOVERY_HASH + +# Verify build authenticity +# https://wiki.lineageos.org/verifying-builds.html +#git clone https://github.com/LineageOS/update_verifier +#cd update_verifier +#pip3 install -r requirements.txt +echo "$BASENAME: please verify build authenticity: https://wiki.lineageos.org/verifying-builds.html" + +# Teardown +cd $CWD |