Skip to content

Commit 8bd6119

Browse files
committed
Sync with microG unofficial installer
1 parent a7d3e33 commit 8bd6119

File tree

2 files changed

+672
-0
lines changed

2 files changed

+672
-0
lines changed

tools/dl-perm-list.sh

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/usr/bin/env sh
2+
# @name Android permissions retriever
3+
# @brief Retrieve the list of Android system permissions
4+
# @author ale5000
5+
# Get the latest version from here: https://github.com/micro5k/microg-unofficial-installer/tree/main/tools
6+
7+
# SPDX-FileCopyrightText: (c) 2025 ale5000
8+
# SPDX-License-Identifier: GPL-3.0-or-later
9+
10+
# shellcheck enable=all
11+
# shellcheck disable=SC3043 # In POSIX sh, local is undefined
12+
13+
readonly SCRIPT_NAME='Android permissions retriever'
14+
readonly SCRIPT_SHORTNAME='DlPermList'
15+
readonly SCRIPT_VERSION='0.2.0'
16+
readonly SCRIPT_AUTHOR='ale5000'
17+
18+
set -u
19+
# shellcheck disable=SC3040,SC3041,SC2015
20+
{
21+
# Unsupported set options may cause the shell to exit (even without set -e), so first try them in a subshell to avoid this issue
22+
(set -o posix 2> /dev/null) && set -o posix || true
23+
(set +H 2> /dev/null) && set +H || true
24+
(set -o pipefail 2> /dev/null) && set -o pipefail || true
25+
}
26+
27+
readonly BASE_URL='https://android.googlesource.com/platform/frameworks/base/'
28+
readonly MAX_API='36'
29+
30+
# shellcheck disable=SC2034
31+
{
32+
readonly TAG_API_23='android-6.0.1_r81' # Android 6
33+
readonly TAG_API_24='android-7.0.0_r36' # Android 7.0
34+
readonly TAG_API_25='android-7.1.2_r39' # Android 7.1
35+
readonly TAG_API_26='android-8.0.0_r51' # Android 8.0
36+
readonly TAG_API_27='android-8.1.0_r81' # Android 8.1
37+
readonly TAG_API_28='android-9.0.0_r61' # Android 9
38+
readonly TAG_API_29='android-10.0.0_r47' # Android 10
39+
readonly TAG_API_30='android-11.0.0_r48' # Android 11
40+
readonly TAG_API_31='android-12.0.0_r34' # Android 12.0
41+
readonly TAG_API_32='android-12.1.0_r27' # Android 12.1
42+
readonly TAG_API_33='android-13.0.0_r84' # Android 13
43+
readonly TAG_API_34='android-14.0.0_r75' # Android 14
44+
readonly TAG_API_35='android-15.0.0_r36' # Android 15
45+
readonly TAG_API_36='android-16.0.0_r2' # Android 16
46+
}
47+
48+
readonly WGET_CMD='wget'
49+
readonly DL_UA='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0'
50+
readonly DL_ACCEPT_HEADER='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
51+
readonly DL_ACCEPT_LANG_HEADER='Accept-Language: en-US,en;q=0.5'
52+
53+
show_status()
54+
{
55+
printf 1>&2 '\033[1;32m%s\033[0m\n' "${1?}"
56+
}
57+
58+
find_data_dir()
59+
{
60+
local _path
61+
62+
# shellcheck disable=SC3028 # Ignore: In POSIX sh, BASH_SOURCE is undefined
63+
if test -n "${TOOLS_DATA_DIR-}" && _path="${TOOLS_DATA_DIR:?}" && test -d "${_path:?}"; then
64+
:
65+
elif test -n "${BASH_SOURCE-}" && _path="$(dirname "${BASH_SOURCE:?}")/data" && test -d "${_path:?}"; then
66+
: # It is expected: expanding an array without an index gives the first element
67+
elif test -n "${0-}" && _path="$(dirname "${0:?}")/data" && test -d "${_path:?}"; then
68+
:
69+
elif _path='./data' && test -d "${_path:?}"; then
70+
:
71+
else
72+
return 1
73+
fi
74+
75+
_path="$(realpath "${_path:?}")" || return 1
76+
77+
printf '%s\n' "${_path:?}"
78+
}
79+
80+
create_and_return_data_dir()
81+
{
82+
local _path
83+
84+
# shellcheck disable=SC3028 # Ignore: In POSIX sh, BASH_SOURCE is undefined
85+
if test -n "${TOOLS_DATA_DIR-}" && _path="${TOOLS_DATA_DIR:?}"; then
86+
:
87+
elif test -n "${BASH_SOURCE-}" && test -f "${BASH_SOURCE:?}" && _path="$(dirname "${BASH_SOURCE:?}")/data"; then
88+
: # It is expected: expanding an array without an index gives the first element
89+
elif test -n "${0-}" && test -f "${0:?}" && _path="$(dirname "${0:?}")/data"; then
90+
:
91+
elif _path='./data'; then
92+
:
93+
else
94+
return 1
95+
fi
96+
97+
_path="$(realpath "${_path:?}")" || return 1
98+
test -d "${_path:?}" || mkdir -p -- "${_path:?}" || return 1
99+
100+
printf '%s\n' "${_path:?}"
101+
}
102+
103+
dl()
104+
{
105+
"${WGET_CMD:?}" -q -O "${2:?}" -U "${DL_UA:?}" --header "${DL_ACCEPT_HEADER:?}" --header "${DL_ACCEPT_LANG_HEADER:?}" --no-cache -- "${1:?}" || return "${?}"
106+
}
107+
108+
download_and_parse_permissions()
109+
{
110+
printf '%s\n' '<manifest xmlns:android="http://schemas.android.com/apk/res/android">' 1> "${DATA_DIR:?}/perms/base-permissions-api-${1:?}.xml" || return "${?}"
111+
112+
dl "${BASE_URL:?}+/refs/tags/${2:?}/core/res/AndroidManifest.xml?format=text" '-' |
113+
base64 -d |
114+
tr -s -- '\n' ' ' |
115+
sed -e 's|>|>\n|g' |
116+
grep -F -e '<permission' 1>> "${DATA_DIR:?}/perms/base-permissions-api-${1:?}.xml" || return "${?}"
117+
118+
printf '%s\n' '</manifest>' 1>> "${DATA_DIR:?}/perms/base-permissions-api-${1:?}.xml" || return "${?}"
119+
}
120+
121+
main()
122+
{
123+
local api tag
124+
125+
DATA_DIR="$(find_data_dir || create_and_return_data_dir)" || return 1
126+
test -d "${DATA_DIR:?}/perms" || mkdir -p -- "${DATA_DIR:?}/perms" || return 1
127+
128+
for api in $(seq -- 23 "${MAX_API:?}"); do
129+
tag="$(eval " printf '%s\n' \"\${TAG_API_${api:?}:?}\" ")" || printf '%s\n' "Failed to get tag for API ${api?}"
130+
printf '%s\n' "API ${api:?}: ${tag:?}"
131+
download_and_parse_permissions "${api:?}" "${tag:?}" || printf '%s\n' "Failed to download/parse XML for API ${api?}"
132+
done
133+
}
134+
135+
STATUS=0
136+
execute_script='true'
137+
138+
while test "${#}" -gt 0; do
139+
case "${1?}" in
140+
-V | --version)
141+
printf '%s\n' "${SCRIPT_NAME:?} v${SCRIPT_VERSION:?}"
142+
printf '%s\n' "Copyright (c) 2025 ${SCRIPT_AUTHOR:?}"
143+
printf '%s\n' 'License GPLv3+'
144+
execute_script='false'
145+
;;
146+
147+
--)
148+
shift
149+
break
150+
;;
151+
152+
--*)
153+
printf 1>&2 '%s\n' "${SCRIPT_SHORTNAME?}: unrecognized option '${1}'"
154+
execute_script='false'
155+
STATUS=2
156+
;;
157+
158+
-*)
159+
printf 1>&2 '%s\n' "${SCRIPT_SHORTNAME?}: invalid option -- '${1#-}'"
160+
execute_script='false'
161+
STATUS=2
162+
;;
163+
164+
*)
165+
break
166+
;;
167+
esac
168+
169+
shift
170+
done
171+
172+
if test "${execute_script:?}" = 'true'; then
173+
show_status "${SCRIPT_NAME:?} v${SCRIPT_VERSION:?} by ${SCRIPT_AUTHOR:?}"
174+
175+
if test "${#}" -eq 0; then set -- ''; fi
176+
main "${@}"
177+
STATUS="${?}"
178+
fi
179+
180+
exit "${STATUS:?}"

0 commit comments

Comments
 (0)