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

356 lines
9.7 KiB
Plaintext
Raw Normal View History

2018-01-23 20:11:52 +00:00
#!/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"
2020-01-31 17:04:53 +00:00
repo_ogapps="https://gitlab.opengapps.org/opengapps"
2018-01-23 20:11:52 +00:00
# check dependencies
2020-08-11 19:38:33 +00:00
for dep in gawk curl jq gzip; do
2018-01-23 20:11:52 +00:00
if ! which ${dep} &>/dev/null; then
echo "${dep} is not installed!"
exit 1
fi
done
debug_download () {
case $1 in
index)
if [ "$BP_USE_WGET" = '1' ]; then
rm -rf "$2"
debug_message normal "wget -q --show-progress \"$3\" -O \"${2#$CWD/}\"" " "
wget -q --show-progress "$3" -O "$2" || error "$4"
else
debug_message normal "curl -sSL -o \"${2#$CWD/}\" \"$3\"" " "
curl -sSL -o "$2" "$3" || error "$4"
fi
;;
no_delete)
if [ "$BP_USE_WGET" = '1' ]; then
rm -rf "$2"
debug_message normal "wget -q --show-progress \"$3\" -O \"${2#$CWD/}\""
wget -q --show-progress "$3" -O "$2"
else
debug_message normal "curl -sSL -o \"${2#$CWD/}\" \"$3\""
curl -sSL -o "$2" "$3"
fi
;;
delete)
if [ "$BP_USE_WGET" = '1' ]; then
rm -rf "$2"
debug_message normal "wget -q --show-progress \"$3\" -O \"${2#$CWD/}\""
wget -q --show-progress "$3" -O "$2" || rm -f "$4"
else
debug_message normal "curl -sSL -o \"${2#$CWD/}\" \"$3\""
curl -sSL -o "$2" "$3" || rm -f "$4"
fi
;;
esac
}
index_update_required () {
index_file=${1}
test ! -f ${index_file} && return 0
test $(stat --format=%Z ${index_file}) -le $(($(date +%s) - 3600)) && return 0
test "$(file -b ${index_file})" == "empty" && return 0
return 1
}
check_sha256sum () {
local input="${1}"
in_checksum=""
local ex_checksum="${2}"
case ${input} in
*.gz )
2020-08-11 19:38:33 +00:00
in_checksum=$(gzip -dc ${input} 2>/dev/null | ${sumsha256} | gawk '{print $1}')
;;
* )
2020-08-11 19:38:33 +00:00
in_checksum=$(${sumsha256} ${input} 2>/dev/null | gawk '{print $1}')
;;
esac
[[ ${in_checksum} == ${ex_checksum} ]] && return 0 || return 1
}
update_index () {
local index_jar=${1}
local index_json="$repofolder/$(basename ${index_jar} .jar).json"
local index_repo=${2}
if index_update_required ${index_json}; then
debug_download index "${index_jar}" "${index_repo}/index-v1.jar" " failed to update repo index"
unzip -q ${index_jar} index-v1.json -d "$repofolder/"
mv "$repofolder/index-v1.json" "${index_json}"
rm -f ${index_jar}
fi
}
2018-09-15 17:21:52 +00:00
update_indices () {
echo "+++ upating Repo Indices"
echo " ++ F-Droid"
[ ! -d "$repofolder" ] && rm -rf "$repofolder" && mkdir -p "$repofolder"
update_index "$repofolder/$(awk -F/ '{print $3}' <<< ${repo_fdroid}).index-v1.jar" "${repo_fdroid}"
2018-09-15 17:21:52 +00:00
echo " ++ Guardian Project"
update_index "$repofolder/$(awk -F/ '{print $3}' <<< ${repo_guardian}).index-v1.jar" "${repo_guardian}"
2018-09-15 17:21:52 +00:00
echo " ++ microG"
update_index "$repofolder/$(awk -F/ '{print $3}' <<< ${repo_microg}).index-v1.jar" "${repo_microg}"
2018-09-29 19:55:08 +00:00
echo " ++ Nanolx"
update_index "$repofolder/$(awk -F/ '{print $3}' <<< ${repo_nanolx}).index-v1.jar" "${repo_nanolx}"
echo " ++ Bromite"
update_index "$repofolder/$(awk -F/ '{print $3}' <<< ${repo_bromite}).index-v1.jar" "${repo_bromite}"
2018-09-15 17:21:52 +00:00
}
2018-01-23 20:11:52 +00:00
grab_apk_from_repo () {
case "${1}" in
fdroid )
local repo=${repo_fdroid}
local repo_p="F-Droid"
2018-01-23 20:11:52 +00:00
;;
guardian )
local repo=${repo_guardian}
local repo_p="Guardian Project"
2018-01-23 20:11:52 +00:00
;;
microg )
local repo=${repo_microg}
local repo_p="microG"
2018-01-23 20:11:52 +00:00
;;
2018-09-29 19:55:08 +00:00
nanolx )
local repo=${repo_nanolx}
local repo_p="Nanolx"
2018-09-29 19:55:08 +00:00
;;
bromite )
local repo=${repo_bromite}
local repo_p="Bromite"
;;
2018-01-23 20:11:52 +00:00
esac
local domain="$(awk -F/ '{print $3}' <<< ${repo})"
index_file="$repofolder/${domain}.index-v1.json"
2018-01-23 20:11:52 +00:00
local pkg_name="${2}"
if [ -z "${5}" ]; then
local apk_name="$(jq -r --arg pkg "${pkg_name}" '.packages[$pkg][0].apkName' ${index_file})"
local sha_sum="$(jq -r --arg pkg "${pkg_name}" '.packages[$pkg][0].hash' ${index_file})"
else
local apk_name="$(jq -r --arg pkg "${pkg_name}" --arg arch "${5}" '[.packages[$pkg][] | select (.nativecode[]==$arch).apkName][0]' ${index_file})"
local sha_sum="$(jq -r --arg pkg "${pkg_name}" --arg arch "${5}" '[.packages[$pkg][] | select (.nativecode[]==$arch).hash][0]' ${index_file})"
fi
2018-01-23 20:11:52 +00:00
case "${pkg_name}" in
2018-11-23 20:18:01 +00:00
com.android.webview )
local apk_dest="${appsfolder[12]}/${3}/${4}"
2018-11-23 20:18:01 +00:00
;;
net.osmand.plus | net.osmand.srtmPlugin.paid )
local apk_dest="${appsfolder[10]}/${3}/${4}"
2018-11-23 20:18:01 +00:00
;;
* )
local apk_dest="${appsfolder[2]}/${3}/${4}"
2018-11-23 20:18:01 +00:00
;;
esac
2018-01-23 20:11:52 +00:00
local apk_url="${repo}/${apk_name}"
2020-08-18 18:51:43 +00:00
if check_sha256sum "${apk_dest}/${4}.apk.gz" "${sha_sum}"; then
echo -e "\nUp-to-Date from ${repo_p} : ${4}.apk"
else echo -e "\nUpdating from ${repo_p} : ${4}.apk"
mkdir -p "${apk_dest}"
rm -f "${apk_dest}/${4}.apk.gz"
debug_download no_delete "${apk_dest}/${4}.apk" "${apk_url}"
2018-01-23 20:11:52 +00:00
2020-08-18 18:51:43 +00:00
if check_sha256sum "${apk_dest}/${4}.apk" "${sha_sum}"; then
2019-07-07 19:49:40 +00:00
echo " SHA256 hash of ${4}.apk is correct"
gzip "${apk_dest}/${4}.apk"
2019-07-07 19:49:40 +00:00
else echo -e " SHA256 hash of ${4}.apk is wrong!\
\n expected : ${sha_sum}\
\n got : ${in_checksum}"
rm -f "${apk_dest}/${4}.apk"
fi
2018-01-23 20:11:52 +00:00
fi
}
grab_apk_from_url () {
local apk_url="${1}"
local apk_dest="${appsfolder[2]}/${2}/${3}"
2018-01-23 20:11:52 +00:00
rm -f "${apk_dest}/${3}.apk.gz"
if [[ -f "${apk_dest}/${3}.apk" ]]; then
2019-08-02 17:27:18 +00:00
echo -e "\nUpdating from URL : ${3}.apk"
else echo -e "\nDownloading from URL : ${3}.apk"
mkdir -p "${apk_dest}"
2018-01-23 20:11:52 +00:00
fi
echo " Checking SHA256 hash not (yet) supported"
2018-01-23 20:11:52 +00:00
debug_download delete "${apk_dest}/${3}.apk" "${apk_url}" "${apk_dest}/${3}.apk"
if [[ -f "${apk_dest}/${3}.apk" ]]; then
gzip "${apk_dest}/${3}.apk"
else echo "error downloading ${3}"
fi
2018-01-23 20:11:52 +00:00
}
grab_apk_from_github () {
[ "$BP_DEBUG" = '1' ] && debug_message normal "curl -s -N \"https://api.github.com/repos/${1}/releases\""
local apk_url="$(curl -s -N "https://api.github.com/repos/${1}/releases" | \
gawk -F\" '/browser_download_url.*apk/{print $4 ; exit}')"
local apk_dest="${appsfolder[2]}/${2}/${3}"
2018-01-23 20:11:52 +00:00
rm -f "${apk_dest}/${3}.apk.gz"
if [[ -f "${apk_dest}/${3}.apk" ]]; then
2018-01-23 20:11:52 +00:00
echo -e "\nUpdating from GitHub : ${3}.apk"
else echo -e "\nDownloading from GitHub : ${3}.apk"
mkdir -p "${apk_dest}"
2018-01-23 20:11:52 +00:00
fi
2018-01-23 20:11:52 +00:00
echo " Checking SHA256 hash not (yet) supported"
debug_download delete "${apk_dest}/${3}.apk" "${apk_url}" "${apk_dest}/${3}.apk"
if [[ -f "${apk_dest}/${3}.apk" ]]; then
gzip "${apk_dest}/${3}.apk"
else echo "error downloading ${3}"
fi
}
grab_apk_from_gitlab () {
[ "$BP_DEBUG" = '1' ] && debug_message newline "curl -s -N \"https://gitlab.com/${1}/-/tags\"" "\n"
local apk_url=$(curl -s -N "https://gitlab.com/${1}/-/tags" | grep '.apk' | head -n 1)
local apk_url=${apk_url%\">*.apk*}
local apk_url="https://gitlab.com${apk_url##*a href=\"}"
2020-01-17 21:46:23 +00:00
local apk_url="${apk_url/\"*}"
local apk_dest="${appsfolder[2]}/${2}/${3}"
rm -f "${apk_dest}/${3}.apk.gz"
if [[ -f "${apk_dest}/${3}.apk" ]]; then
echo -e "\nUpdating from GitLab : ${3}.apk"
else echo -e "\nDownloading from GitLab : ${3}.apk"
mkdir -p "${apk_dest}"
fi
echo " Checking SHA256 hash not (yet) supported"
debug_download delete "${apk_dest}/${3}.apk" "${apk_url}" "${apk_dest}/${3}.apk"
if [[ -f "${apk_dest}/${3}.apk" ]]; then
gzip "${apk_dest}/${3}.apk"
else echo "error downloading ${3}"
fi
2018-01-23 20:11:52 +00:00
}
grab_apk_from_ogapps () {
2020-01-27 17:09:45 +00:00
case "${4}" in
19 ) local api_letter=K ;;
21 ) local api_letter=L ;;
23 ) local api_letter=M ;;
24 ) local api_letter=N ;;
26 ) local api_letter=O ;;
28 ) local api_letter=P ;;
29 ) local api_letter=Q ;;
esac
2018-01-23 20:11:52 +00:00
case "${1}" in
"com.google.android.syncadapters.calendar" )
2020-01-27 17:09:45 +00:00
# use SDK 19 Calendar Syncadapter for SDK 19
# use SDK 21 Calendar Syncadapter for SDK 21 - 29
if [ "${4}" -eq 19 ]; then
2020-01-31 17:04:53 +00:00
local apk_url="${repo_ogapps}/all/raw/master/${2}/${1}/15/nodpi/2015080710.apk"
else
2020-07-17 17:04:18 +00:00
local apk_url="${repo_ogapps}/all/raw/master/${2}/${1}/21/nodpi/2016267990.apk"
fi
2018-01-23 20:11:52 +00:00
;;
2020-01-27 17:09:45 +00:00
"com.google.android.syncadapters.contacts" )
2020-01-31 17:04:53 +00:00
local apk_url="${repo_ogapps}/all/raw/master/${2}/${1}/${4}/nodpi/${4}.apk"
2020-01-27 17:09:45 +00:00
;;
"com.google.android.backuptransport" )
# Use SDK 28 Backuptransport on SDK 29 aswell
if [ "${4}" -eq 29 ]; then
2020-01-31 17:04:53 +00:00
local apk_url="${repo_ogapps}/all/raw/master/${2}/${1}/28/nodpi/28.apk"
2020-01-27 17:09:45 +00:00
else
2020-01-31 17:04:53 +00:00
local apk_url="${repo_ogapps}/all/raw/master/${2}/${1}/${4}/nodpi/${4}.apk"
2020-01-27 17:09:45 +00:00
fi
2018-01-23 20:11:52 +00:00
;;
esac
apk_dest="${appsfolder[6]}/${api_letter}/${2}/${3}"
2018-01-23 20:11:52 +00:00
if [[ -f "${apk_dest}/${3}.apk.gz" ]]; then
echo -e "\nUpdating from OpenGApps : ${3}.apk [${api_letter}]"
rm -f "${apk_dest}/${3}.apk.gz"
else echo -e "\nDownloading from OpenGApps: ${3}.apk [${api_letter}]"
mkdir -p "${apk_dest}"
2018-01-23 20:11:52 +00:00
fi
echo " Checking SHA256 hash not (yet) supported"
debug_download delete "${apk_dest}/${3}.apk" "${apk_url}" "${apk_dest}/${3}.apk"
[ -f "${apk_dest}/${3}.apk" ] && gzip "${apk_dest}/${3}.apk"
2018-01-23 20:11:52 +00:00
}
grab_lib_from_ogapps () {
case "${3}" in
arm | x86 ) LIBD=lib ;;
arm64 | x86_64 ) LIBD=lib64 ;;
esac
2020-01-31 17:04:53 +00:00
local lib_url="${repo_ogapps}/${3}/raw/master/${LIBD}/${2}/${1}?inline=false"
local swp_dest="${appsfolder[8]}/${3}"
2018-01-23 20:11:52 +00:00
if [[ "${4}" == "true" ]]; then
local 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}"
2018-01-23 20:11:52 +00:00
fi
echo " Checking SHA256 hash not (yet) supported"
debug_download delete "${lib_dest}" "${lib_url}" "${lib_dest}"
2018-01-23 20:11:52 +00:00
}
2019-03-01 13:23:44 +00:00
grab_patches () {
base_url="https://github.com/Lanchon/haystack/blob/master/patches"
2019-03-01 13:23:44 +00:00
patch_url="${base_url}/${1}?raw=true"
patch_dst="${CWD}/patcher/dexpatcher/${2}"
2019-03-01 13:23:44 +00:00
echo -e "\nUpdating from Haystack : ${2}"
echo " Checking SHA256 hash not (yet) supported"
debug_download delete "${patch_dst}" "${patch_url}""${patch_dst}"
2019-03-01 13:23:44 +00:00
}