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"
|
2018-09-29 19:55:08 +00:00
|
|
|
REPO_GUARDIAN="https://guardianproject.info/fdroid/repo"
|
2018-01-23 20:11:52 +00:00
|
|
|
REPO_MICROG="https://microg.org/fdroid/repo"
|
2018-11-07 19:34:06 +00:00
|
|
|
REPO_NANOLX="https://nanolx.org/fdroid/repo"
|
2019-01-16 17:23:55 +00:00
|
|
|
REPO_BROMITE="https://fdroid.bromite.org/fdroid/repo"
|
2018-01-23 20:11:52 +00:00
|
|
|
|
|
|
|
# check dependencies
|
2019-08-05 17:56:48 +00:00
|
|
|
for dep in gawk curl sha256sum 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
|
|
|
|
|
2019-06-19 22:01:22 +00:00
|
|
|
index_update_required () {
|
|
|
|
INDEX_FILE=${1}
|
|
|
|
|
2019-06-19 22:02:32 +00:00
|
|
|
test ! -f ${INDEX_FILE} && return 0
|
2019-06-26 18:27:07 +00:00
|
|
|
test $(stat --format=%Z ${INDEX_FILE}) -le $(($(date +%s) - 3600)) && return 0
|
|
|
|
test "$(file -b ${INDEX_FILE})" == "empty" && return 0
|
2019-06-19 22:01:22 +00:00
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2019-07-07 19:41:13 +00:00
|
|
|
check_sha256sum () {
|
|
|
|
INPUT="${1}"
|
|
|
|
|
|
|
|
IN_CHECKSUM=""
|
|
|
|
EX_CHECKSUM="${2}"
|
|
|
|
|
|
|
|
case ${INPUT} in
|
2019-07-08 18:52:43 +00:00
|
|
|
*.gz )
|
|
|
|
IN_CHECKSUM=$(gzip -dc ${INPUT} 2>/dev/null | sha256sum | gawk '{print $1}')
|
2019-07-07 19:41:13 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
* )
|
|
|
|
IN_CHECKSUM=$(sha256sum ${INPUT} 2>/dev/null | gawk '{print $1}')
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2019-07-26 18:27:24 +00:00
|
|
|
[[ ${IN_CHECKSUM} == ${EX_CHECKSUM} ]] && return 0 || return 1
|
2019-07-07 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 22:38:28 +00:00
|
|
|
update_index () {
|
|
|
|
INDEX_JAR=${1}
|
|
|
|
INDEX_JSON="${CWD}/data/$(basename ${INDEX_JAR} .jar).json"
|
|
|
|
INDEX_REPO=${2}
|
|
|
|
|
2019-06-23 18:46:01 +00:00
|
|
|
if index_update_required ${INDEX_JSON}; then
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${INDEX_JAR}" "${INDEX_REPO}/index-v1.jar" || error " failed to update repo index"
|
2019-06-19 22:38:28 +00:00
|
|
|
|
2019-06-26 18:27:07 +00:00
|
|
|
unzip -q ${INDEX_JAR} index-v1.json -d "${CWD}/data/"
|
|
|
|
mv "${CWD}/data/index-v1.json" "${INDEX_JSON}"
|
|
|
|
rm -f ${INDEX_JAR}
|
|
|
|
fi
|
2019-06-19 22:38:28 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 17:21:52 +00:00
|
|
|
update_indices () {
|
|
|
|
echo "+++ upating Repo Indices"
|
|
|
|
echo " ++ F-Droid"
|
2019-06-19 22:38:28 +00:00
|
|
|
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_FDROID}).index-v1.jar" "${REPO_FDROID}"
|
2018-09-15 17:21:52 +00:00
|
|
|
|
|
|
|
echo " ++ Guardian Project"
|
2019-06-19 22:38:28 +00:00
|
|
|
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_GUARDIAN}).index-v1.jar" "${REPO_GUARDIAN}"
|
2018-09-15 17:21:52 +00:00
|
|
|
|
|
|
|
echo " ++ microG"
|
2019-06-19 22:38:28 +00:00
|
|
|
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_MICROG}).index-v1.jar" "${REPO_MICROG}"
|
2018-09-29 19:55:08 +00:00
|
|
|
|
|
|
|
echo " ++ Nanolx"
|
2019-06-19 22:38:28 +00:00
|
|
|
update_index "${CWD}/data/$(awk -F/ '{print $3}' <<< ${REPO_NANOLX}).index-v1.jar" "${REPO_NANOLX}"
|
2018-11-07 19:34:06 +00:00
|
|
|
|
|
|
|
echo " ++ Bromite"
|
2019-06-19 22:38:28 +00:00
|
|
|
update_index "${CWD}/data/$(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 )
|
|
|
|
REPO=${REPO_FDROID}
|
|
|
|
REPO_P="F-Droid"
|
|
|
|
;;
|
|
|
|
|
|
|
|
guardian )
|
|
|
|
REPO=${REPO_GUARDIAN}
|
|
|
|
REPO_P="Guardian Project"
|
|
|
|
;;
|
|
|
|
|
|
|
|
microg )
|
|
|
|
REPO=${REPO_MICROG}
|
|
|
|
REPO_P="microG"
|
|
|
|
;;
|
2018-09-29 19:55:08 +00:00
|
|
|
|
|
|
|
nanolx )
|
|
|
|
REPO=${REPO_NANOLX}
|
|
|
|
REPO_P="Nanolx"
|
|
|
|
;;
|
2018-11-07 19:34:06 +00:00
|
|
|
|
|
|
|
bromite )
|
|
|
|
REPO=${REPO_BROMITE}
|
|
|
|
REPO_P="Bromite"
|
|
|
|
;;
|
2018-01-23 20:11:52 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
DOMAIN="$(awk -F/ '{print $3}' <<< ${REPO})"
|
2019-06-19 22:38:28 +00:00
|
|
|
INDEX_FILE="${CWD}/data/${DOMAIN}.index-v1.json"
|
2018-01-23 20:11:52 +00:00
|
|
|
|
|
|
|
PKG_NAME="${2}"
|
2018-11-07 19:34:06 +00:00
|
|
|
|
|
|
|
if [ -z "${5}" ]; then
|
2019-06-19 22:38:28 +00:00
|
|
|
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})"
|
2018-11-07 19:34:06 +00:00
|
|
|
else
|
2019-06-26 18:27:07 +00:00
|
|
|
APK_NAME="$(jq -r --arg pkg "${PKG_NAME}" --arg arch "${5}" '[.packages[$pkg][] | select (.nativecode[]==$arch).apkName][0]' ${INDEX_FILE})"
|
2019-06-19 22:38:28 +00:00
|
|
|
SHA_SUM="$(jq -r --arg pkg "${PKG_NAME}" --arg arch "${5}" '[.packages[$pkg][] | select (.nativecode[]==$arch).hash][0]' ${INDEX_FILE})"
|
2018-11-07 19:34:06 +00:00
|
|
|
fi
|
2018-01-23 20:11:52 +00:00
|
|
|
|
2018-11-23 20:18:01 +00:00
|
|
|
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}"
|
|
|
|
;;
|
|
|
|
|
2019-06-19 22:38:28 +00:00
|
|
|
com.google.android.gms )
|
|
|
|
# XXX select mapbox build in official microG repo
|
2019-07-07 19:41:13 +00:00
|
|
|
APK_NAME="$(jq -r --arg pkg "${PKG_NAME}" '.packages[$pkg][0] | select (.versionName | contains("mapbox")).apkName' ${INDEX_FILE})"
|
|
|
|
SHA_SUM="$(jq -r --arg pkg "${PKG_NAME}" '.packages[$pkg][0] | select (.versionName | contains("mapbox")).hash' ${INDEX_FILE})"
|
2019-06-19 22:38:28 +00:00
|
|
|
APK_DEST="${CWD}/Full/system/${3}/${4}"
|
|
|
|
;;
|
|
|
|
|
2018-11-23 20:18:01 +00:00
|
|
|
* )
|
|
|
|
APK_DEST="${CWD}/Full/system/${3}/${4}"
|
|
|
|
;;
|
|
|
|
esac
|
2018-01-23 20:11:52 +00:00
|
|
|
|
2019-06-19 22:01:22 +00:00
|
|
|
APK_URL="${REPO}/${APK_NAME}"
|
|
|
|
|
2019-07-08 18:52:43 +00:00
|
|
|
if check_sha256sum "${APK_DEST}/${4}.apk.gz" "${SHA_SUM}"; then
|
2019-07-07 19:41:13 +00:00
|
|
|
echo -e "\nUp-to-Date from ${REPO_P} : ${4}.apk"
|
|
|
|
else echo -e "\nUpdating from ${REPO_P} : ${4}.apk"
|
2019-08-02 17:27:18 +00:00
|
|
|
mkdir -p "${APK_DEST}"
|
2019-07-08 18:52:43 +00:00
|
|
|
rm -f "${APK_DEST}/${4}.apk.gz"
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${APK_DEST}/${4}.apk" "${APK_URL}"
|
2018-01-23 20:11:52 +00:00
|
|
|
|
2019-07-07 19:41:13 +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"
|
2019-07-08 18:52:43 +00:00
|
|
|
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"
|
2019-07-07 19:41:13 +00:00
|
|
|
fi
|
2018-01-23 20:11:52 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
grab_apk_from_url () {
|
|
|
|
APK_URL="${1}"
|
|
|
|
APK_DEST="${CWD}/Full/system/${2}/${3}"
|
|
|
|
|
2019-07-26 19:27:20 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk.gz"
|
|
|
|
|
2018-01-23 20:11:52 +00:00
|
|
|
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
|
2019-08-02 17:27:18 +00:00
|
|
|
echo -e "\nUpdating from URL : ${3}.apk"
|
2019-07-26 19:27:20 +00:00
|
|
|
else echo -e "\nDownloading from URL : ${3}.apk"
|
2019-08-02 17:27:18 +00:00
|
|
|
mkdir -p "${APK_DEST}"
|
2018-01-23 20:11:52 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-26 19:27:20 +00:00
|
|
|
echo " Checking SHA256 hash not (yet) supported"
|
2018-01-23 20:11:52 +00:00
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${APK_DEST}/${3}.apk" "${APK_URL}" || \
|
2018-01-23 20:11:52 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk"
|
2019-07-07 19:41:13 +00:00
|
|
|
|
2019-08-05 17:29:06 +00:00
|
|
|
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
|
|
|
|
gzip "${APK_DEST}/${3}.apk"
|
2019-08-05 17:56:48 +00:00
|
|
|
else echo "error downloading ${3}"
|
2019-08-05 17:29:06 +00:00
|
|
|
fi
|
2018-01-23 20:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grab_apk_from_github () {
|
2019-08-05 17:56:48 +00:00
|
|
|
APK_URL="$(curl -s -N "https://api.github.com/repos/${1}/releases" | \
|
2019-08-03 18:26:55 +00:00
|
|
|
gawk -F\" '/browser_download_url.*apk/{print $4 ; exit}')"
|
2018-01-23 20:11:52 +00:00
|
|
|
APK_DEST="${CWD}/Full/system/${2}/${3}"
|
|
|
|
|
2019-07-26 19:27:20 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk.gz"
|
|
|
|
|
2018-01-23 20:11:52 +00:00
|
|
|
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
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
|
|
|
|
|
2018-01-23 20:11:52 +00:00
|
|
|
echo " Checking SHA256 hash not (yet) supported"
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${APK_DEST}/${3}.apk" "${APK_URL}" || \
|
2019-08-02 17:00:58 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk"
|
|
|
|
|
2019-08-05 17:29:06 +00:00
|
|
|
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
|
|
|
|
gzip "${APK_DEST}/${3}.apk"
|
2019-08-05 17:56:48 +00:00
|
|
|
else echo "error downloading ${3}"
|
2019-08-05 17:29:06 +00:00
|
|
|
fi
|
2019-08-02 17:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grab_apk_from_gitlab () {
|
2019-08-05 17:56:48 +00:00
|
|
|
APK_URL="https://gitlab.com$(curl -s -N "https://gitlab.com/${1}/-/tags" | \
|
2019-08-02 17:00:58 +00:00
|
|
|
gawk -F\" '/\.apk/{print $6 ; exit}')"
|
|
|
|
APK_DEST="${CWD}/Full/system/${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"
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${APK_DEST}/${3}.apk" "${APK_URL}" || \
|
2018-01-23 20:11:52 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk"
|
2019-07-26 19:27:20 +00:00
|
|
|
|
2019-08-05 17:29:06 +00:00
|
|
|
if [[ -f "${APK_DEST}/${3}.apk" ]]; then
|
|
|
|
gzip "${APK_DEST}/${3}.apk"
|
2019-08-05 17:56:48 +00:00
|
|
|
else echo "error downloading ${3}"
|
2019-08-05 17:29:06 +00:00
|
|
|
fi
|
2018-01-23 20:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grab_apk_from_ogapps () {
|
|
|
|
case "${1}" in
|
|
|
|
"com.google.android.syncadapters.calendar" )
|
2019-07-08 15:12:31 +00:00
|
|
|
APK_URL="https://gitlab.opengapps.org/opengapps/all/raw/master/${2}/${1}/15/nodpi/2015080710.apk"
|
2018-01-23 20:11:52 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
* )
|
2019-07-08 15:12:31 +00:00
|
|
|
APK_URL="https://gitlab.opengapps.org/opengapps/all/raw/master/${2}/${1}/${4}/nodpi/${4}.apk"
|
2018-01-23 20:11:52 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "${4}" in
|
|
|
|
19 ) API_LETTER=K ;;
|
|
|
|
21 ) API_LETTER=L ;;
|
|
|
|
23 ) API_LETTER=M ;;
|
|
|
|
24 ) API_LETTER=N ;;
|
|
|
|
26 ) API_LETTER=O ;;
|
2018-08-31 18:03:52 +00:00
|
|
|
28 ) API_LETTER=P ;;
|
2018-01-23 20:11:52 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
APK_DEST="${CWD}/Full/gsync/${API_LETTER}/${2}/${3}"
|
|
|
|
|
2019-07-08 18:52:43 +00:00
|
|
|
if [[ -f "${APK_DEST}/${3}.apk.gz" ]]; then
|
2018-01-23 20:11:52 +00:00
|
|
|
echo -e "\nUpdating from OpenGApps : ${3}.apk [${API_LETTER}]"
|
2019-07-08 18:52:43 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk.gz"
|
2018-01-23 20:11:52 +00:00
|
|
|
else echo -e "\nDownloading from OpenGApps: ${3}.apk [${API_LETTER}]"
|
|
|
|
mkdir -p "${APK_DEST}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo " Checking SHA256 hash not (yet) supported"
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${APK_DEST}/${3}.apk" "${APK_URL}" || \
|
2018-01-23 20:11:52 +00:00
|
|
|
rm -f "${APK_DEST}/${3}.apk"
|
2019-07-08 15:12:31 +00:00
|
|
|
|
2019-07-08 18:52:43 +00:00
|
|
|
[ -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
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
LIB_URL="https://gitlab.opengapps.org/opengapps/${3}/raw/master/${LIBD}/${2}/${1}?inline=false"
|
2018-10-31 19:34:59 +00:00
|
|
|
SWP_DEST="${CWD}/Full/swipe/${3}"
|
2018-01-23 20:11:52 +00:00
|
|
|
|
2018-10-31 19:34:59 +00:00
|
|
|
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}"
|
2018-01-23 20:11:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo " Checking SHA256 hash not (yet) supported"
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${LIB_DEST}" "${LIB_URL}" || \
|
2018-10-31 19:34:59 +00:00
|
|
|
rm -f "${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"
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
2019-08-05 17:56:48 +00:00
|
|
|
curl -sSL -o "${PATCH_DST}" "${PATCH_URL}" || \
|
2019-03-01 13:23:44 +00:00
|
|
|
rm -f "${PATCH_DST}"
|
|
|
|
}
|