2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-10-31 09:20:23 +00:00
NanoDroid/data/build-package.download

316 lines
8.7 KiB
Bash

#!/bin/bash
# Functions borrowed or derived from
# Michael Bryant / Shadow53
# https://gitlab.com/Shadow53/android-zip-builder
REPO_FDROID="https://f-droid.org/repo"
REPO_GUARDIAN="https://guardianproject.info/fdroid/repo"
REPO_MICROG="https://microg.org/fdroid/repo"
REPO_NANOLX="https://nanolx.org/fdroid/repo"
REPO_BROMITE="https://fdroid.bromite.org/fdroid/repo"
# check dependencies
for dep in xmllint gawk wget curl sha256sum; do
if ! which ${dep} &>/dev/null; then
echo "${dep} is not installed!"
exit 1
fi
done
index_update_required () {
INDEX_FILE=${1}
test ! -f ${INDEX_FILE} && return 0
test $(stat --format=%Y ${INDEX_FILE}) -le $(($(date +%s) - 3600)) && return 0
test $(file -b ${INDEX_FILE}) == "empty" && return 0
return 1
}
update_index () {
INDEX_JAR=${1}
INDEX_JSON="${CWD}/data/$(basename ${INDEX_JAR} .jar).json"
INDEX_REPO=${2}
index_update_required ${INDEX_JSON} && \
( wget -q -O "${INDEX_JAR}" "${INDEX_REPO}/index-v1.jar" || error " failed to update repo index" )
unzip -q ${INDEX_JAR} index-v1.json -d "${CWD}/data/"
mv "${CWD}/data/index-v1.json" "${INDEX_JSON}"
rm -f ${INDEX_JAR}
}
update_indices () {
echo "+++ upating Repo Indices"
echo " ++ F-Droid"
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_FDROID}).index-v1.jar" "${REPO_FDROID}"
echo " ++ Guardian Project"
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_GUARDIAN}).index-v1.jar" "${REPO_GUARDIAN}"
echo " ++ microG"
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_MICROG}).index-v1.jar" "${REPO_MICROG}"
echo " ++ Nanolx"
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_NANOLX}).index-v1.jar" "${REPO_NANOLX}"
echo " ++ Bromite"
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_BROMITE}).index-v1.jar" "${REPO_BROMITE}"
}
grab_apk_from_repo () {
case "${1}" in
fdroid )
REPO=${REPO_FDROID}
REPO_P="F-Droid"
;;
guardian )
REPO=${REPO_GUARDIAN}
REPO_P="Guardian Project"
;;
microg )
REPO=${REPO_MICROG}
REPO_P="microG"
;;
nanolx )
REPO=${REPO_NANOLX}
REPO_P="Nanolx"
;;
bromite )
REPO=${REPO_BROMITE}
REPO_P="Bromite"
;;
esac
DOMAIN="$(awk -F/ '{print $3}' <<< ${REPO})"
INDEX_FILE="${CWD}/data/${DOMAIN}.index-v1.json"
PKG_NAME="${2}"
if [ -z "${5}" ]; then
APK_NAME="$(jq -r --arg pkg "${PKG_NAME}" '.packages[$pkg][0].apkName' ${INDEX_FILE})"
SHA_SUM="$(jq -r --arg pkg "${PKG_NAME}" '.packages[$pkg][0].hash' ${INDEX_FILE})"
else
APK_NAME="$(jq --arg pkg "${PKG_NAME}" --arg arch "${5}" '[.packages[$pkg][] | select (.nativecode[]==$arch).apkName][0]' ${INDEX_FILE})"
SHA_SUM="$(jq -r --arg pkg "${PKG_NAME}" --arg arch "${5}" '[.packages[$pkg][] | select (.nativecode[]==$arch).hash][0]' ${INDEX_FILE})"
fi
case "${PKG_NAME}" in
com.android.webview )
APK_DEST="${CWD}/BromiteWebView/system/${3}/${4}"
;;
net.osmand.plus | net.osmand.srtmPlugin.paid )
APK_DEST="${CWD}/OsmAnd/system/${3}/${4}"
;;
com.google.android.gms )
# XXX select mapbox build in official microG repo
if [ ${REPO} == ${REPO_MICROG} ]; then
APK_NAME="$(jq -r --arg pkg "${PKG_NAME}" '.packages[$pkg][] | select (.versionName | contains("mapbox")).apkName' ${INDEX_FILE})"
SHA_SUM="$(jq -r --arg pkg "${PKG_NAME}" '.packages[$pkg][] | select (.versionName | contains("mapbox")).hash' ${INDEX_FILE})"
fi
APK_DEST="${CWD}/Full/system/${3}/${4}"
;;
* )
APK_DEST="${CWD}/Full/system/${3}/${4}"
;;
esac
APK_URL="${REPO}/${APK_NAME}"
if [[ -f "${APK_DEST}/${4}.apk" ]]; then
TMP_SUM="$(sha256sum "${APK_DEST}/${4}.apk")"
if [[ "${SHA_SUM}" == "${TMP_SUM/ */}" ]]; then
echo -e "\nUp-to-Date from ${REPO_P} : ${4}.apk"
else echo -e "\nUpdating from ${REPO_P} : ${4}.apk"
rm -f "${APK_DEST}/${4}.apk"
wget -q -O "${APK_DEST}/${4}.apk" "${APK_URL}"
fi
else
echo -e "\nDownloading from ${REPO_P}: ${4}.apk"
mkdir -p "${APK_DEST}"
wget -q -O "${APK_DEST}/${4}.apk" "${APK_URL}"
fi
TMP_SUM="$(sha256sum "${APK_DEST}/${4}.apk")"
if [[ "${SHA_SUM}" == "${TMP_SUM/ */}" ]]; then
echo " SHA256 hash of ${4}.apk is correct"
else echo -e " SHA256 hash of ${4}.apk is wrong!\
\n expected : ${SHA_SUM}\
\n got : ${TMP_SUM/ *}"
rm -f "${APK_DEST}/${4}.apk"
fi
}
grab_apk_from_url () {
APK_URL="${1}"
APK_DEST="${CWD}/Full/system/${2}/${3}"
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
echo -e "\nUpdating from URL : ${3}.apk"
else echo -e "\nDownloading from URL : ${3}.apk"
mkdir -p "${APK_DEST}"
fi
echo " Checking SHA256 hash not (yet) supported"
wget -q -O "${APK_DEST}/${3}.apk" "${APK_URL}" || \
rm -f "${APK_DEST}/${3}.apk"
}
# XXX
# I've never used curl, nor whatever, I suck at
# automated HTML parsing, so you'll get eyesore
# from looking at his code, you've been warned.
USER_AGENT="Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
grab_apk_from_apkmirror () {
VERSION=$(curl -s -N https://www.apkmirror.com/apk/${1}/${2}/ | \
gawk -F\" '/apk.*release/{print $4 ; exit}' | \
sed -e "s,.*${2}-,,g;s,-release/,,g")
URL_STRING="https://www.apkmirror.com/apk/\
${1}/${2}/${2}-${VERSION}-release/\
${5}-${VERSION}-android-apk-download"
URL_WP=$(curl -s -N "${URL_STRING}/download/" | \
gawk -F\" '/If not, please click/{print $18}')
SHA_SUM=$(curl -s -N "${URL_STRING}/" | \
grep "SHA-256.*[^>]</span>" | \
sed -e 's,.*\">,,;s,</span>,,')
APK_URL="https://www.apkmirror.com${URL_WP}"
APK_DEST="${CWD}/Full/system/${3}/${4}"
if [[ -f "${APK_DEST}/${4}.apk" ]]; then
TMP_SUM="$(sha256sum "${APK_DEST}/${4}.apk")"
if [[ "${SHA_SUM}" == "${TMP_SUM/ */}" ]]; then
echo -e "\nUp-to-Date from APK Mirror: ${4}.apk"
else echo -e "\nUpdating from APK Mirror : ${4}.apk"
rm -f "${APK_DEST}/${4}.apk"
wget --user-agent="${USER_AGENT}" -q \
"${APK_URL}" -O "${APK_DEST}/${4}.apk"
fi
else
echo -e "\nDownloading from APK Mirror: ${4}.apk"
mkdir -p "${APK_DEST}"
wget --user-agent="${USER_AGENT}" -q \
"${APK_URL}" -O "${APK_DEST}/${4}.apk"
fi
TMP_SUM="$(sha256sum "${APK_DEST}/${4}.apk")"
if [[ "${SHA_SUM}" == "${TMP_SUM/ */}" ]]; then
echo " SHA256 hash of ${4}.apk is correct"
else echo -e " SHA256 hash of ${4}.apk is wrong!\
\n expected : ${SHA_SUM}\
\n got : ${TMP_SUM/ *}"
rm -f "${APK_DEST}/${4}.apk"
fi
}
grab_apk_from_github () {
TAG_NAME="$(curl -s -N https://api.github.com/repos/${1}/releases | gawk -F\" '/tag_name/{print $4; exit}')"
APK_NAME="$(curl -s -N https://api.github.com/repos/${1}/releases | gawk -F\" '/name.*.apk/{print $4; exit}')"
APK_URL="https://github.com/${1}/releases/download/${TAG_NAME}/${APK_NAME}"
APK_DEST="${CWD}/Full/system/${2}/${3}"
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
echo -e "\nUpdating from GitHub : ${3}.apk"
else echo -e "\nDownloading from GitHub : ${3}.apk"
mkdir -p "${APK_DEST}"
fi
echo " Checking SHA256 hash not (yet) supported"
wget -q -O "${APK_DEST}/${3}.apk" "${APK_URL}" || \
rm -f "${APK_DEST}/${3}.apk"
}
grab_apk_from_ogapps () {
case "${1}" in
"com.google.android.syncadapters.calendar" )
APK_URL="https://gitlab.nezorfla.me/opengapps/all/raw/master/${2}/${1}/15/nodpi/2015080710.apk?inline=false"
;;
* )
APK_URL="https://gitlab.nezorfla.me/opengapps/all/raw/master/${2}/${1}/${4}/nodpi/${4}.apk?inline=false"
;;
esac
case "${4}" in
19 ) API_LETTER=K ;;
21 ) API_LETTER=L ;;
23 ) API_LETTER=M ;;
24 ) API_LETTER=N ;;
26 ) API_LETTER=O ;;
28 ) API_LETTER=P ;;
esac
APK_DEST="${CWD}/Full/gsync/${API_LETTER}/${2}/${3}"
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
echo -e "\nUpdating from OpenGApps : ${3}.apk [${API_LETTER}]"
else echo -e "\nDownloading from OpenGApps: ${3}.apk [${API_LETTER}]"
mkdir -p "${APK_DEST}"
fi
echo " Checking SHA256 hash not (yet) supported"
wget -q -O "${APK_DEST}/${3}.apk" "${APK_URL}" || \
rm -f "${APK_DEST}/${3}.apk"
}
grab_lib_from_ogapps () {
case "${3}" in
arm | x86 ) LIBD=lib ;;
arm64 | x86_64 ) LIBD=lib64 ;;
esac
LIB_URL="https://gitlab.nezorfla.me/opengapps/${3}/raw/master/${LIBD}/${2}/${1}?inline=false"
SWP_DEST="${CWD}/Full/swipe/${3}"
if [[ "${4}" == "true" ]]; then
LIB_DEST="${SWP_DEST}/${1}_${2}"
else LIB_DEST="${SWP_DEST}/${1}"
fi
if [[ -f "${LIB_DEST}" ]]; then
echo -e "\nUpdating from OpenGApps : ${1} [${2}:${3}]"
else echo -e "\nDownloading from OpenGApps: ${1} [${2}:${3}]"
mkdir -p "${SWP_DEST}"
fi
echo " Checking SHA256 hash not (yet) supported"
wget -q -O "${LIB_DEST}" "${LIB_URL}" || \
rm -f "${LIB_DEST}"
}
grab_patches () {
BASE_URL="https://github.com/Lanchon/haystack/blob/master/patches"
PATCH_URL="${BASE_URL}/${1}?raw=true"
PATCH_DST="${CWD}/patcher/dexpatcher/${2}"
echo -e "\nUpdating from Haystack : ${2}"
echo " Checking SHA256 hash not (yet) supported"
wget -q -O "${PATCH_DST}" "${PATCH_URL}" || \
rm -f "${PATCH_DST}"
}