55# Get the latest version from here: https://github.com/micro5k/microg-unofficial-installer/tree/main/tools
66
77# SPDX-FileCopyrightText: (c) 2025 ale5000
8- # SPDX-License-Identifier: GPL-3.0-or-later
8+ # SPDX-License-Identifier: GPL-3.0-or-later OR Apache-2.0
99
1010# shellcheck enable=all
1111# shellcheck disable=SC3043 # In POSIX sh, local is undefined
1212
1313readonly SCRIPT_NAME=' Android permissions retriever'
1414readonly SCRIPT_SHORTNAME=' DlPermList'
15- readonly SCRIPT_VERSION=' 0.2 .0'
15+ readonly SCRIPT_VERSION=' 0.3 .0'
1616readonly SCRIPT_AUTHOR=' ale5000'
1717
1818set -u
1919# shellcheck disable=SC3040,SC3041,SC2015
2020{
2121 # 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
2322 (set +H 2> /dev/null) && set +H || true
2423 (set -o pipefail 2> /dev/null) && set -o pipefail || true
2524}
@@ -50,11 +49,34 @@ readonly DL_UA='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/201001
5049readonly DL_ACCEPT_HEADER=' Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
5150readonly DL_ACCEPT_LANG_HEADER=' Accept-Language: en-US,en;q=0.5'
5251
52+ pause_if_needed ()
53+ {
54+ # shellcheck disable=SC3028 # Ignore: In POSIX sh, SHLVL is undefined
55+ if test " ${NO_PAUSE:- 0} " = ' 0' && test " ${no_pause:- 0} " = ' 0' && test " ${CI:- false} " = ' false' && test " ${TERM_PROGRAM:- unknown} " ! = ' vscode' && test " ${SHLVL:- 1} " = ' 1' && test -t 0 && test -t 1 && test -t 2; then
56+ if test -n " ${NO_COLOR-} " ; then
57+ printf 1>&2 ' \n%s' ' Press any key to exit... ' || :
58+ else
59+ printf 1>&2 ' \n\033[1;32m\r%s' ' Press any key to exit... ' || :
60+ fi
61+ # shellcheck disable=SC3045 # Ignore: In POSIX sh, read -s / -n is undefined
62+ IFS=' ' read 2> /dev/null 1>&2 -r -s -n1 _ || IFS=' ' read 1>&2 -r _ || :
63+ printf 1>&2 ' \n' || :
64+ test -n " ${NO_COLOR-} " || printf 1>&2 ' \033[0m\r \r' || :
65+ fi
66+ unset no_pause || :
67+ return " ${1:- 0} "
68+ }
69+
5370show_status ()
5471{
5572 printf 1>&2 ' \033[1;32m%s\033[0m\n' " ${1?} "
5673}
5774
75+ show_error ()
76+ {
77+ printf 1>&2 ' \n\033[1;31m%s\033[0m\n' " ERROR: ${1?} "
78+ }
79+
5880find_data_dir ()
5981{
6082 local _path
@@ -72,8 +94,7 @@ find_data_dir()
7294 return 1
7395 fi
7496
75- _path=" $( realpath " ${_path:? } " ) " || return 1
76-
97+ _path=" $( realpath 2> /dev/null " ${_path:? } " || readlink -f " ${_path:? } " ) " || return 1
7798 printf ' %s\n' " ${_path:? } "
7899}
79100
@@ -94,9 +115,9 @@ create_and_return_data_dir()
94115 return 1
95116 fi
96117
97- _path=" $( realpath " ${_path:? } " ) " || return 1
98118 test -d " ${_path:? } " || mkdir -p -- " ${_path:? } " || return 1
99119
120+ _path=" $( realpath 2> /dev/null " ${_path:? } " || readlink -f " ${_path:? } " ) " || return 1
100121 printf ' %s\n' " ${_path:? } "
101122}
102123
@@ -122,13 +143,24 @@ main()
122143{
123144 local api tag
124145
146+ command 1> /dev/null -v " ${WGET_CMD:? } " || {
147+ show_error ' Missing: wget'
148+ return 255
149+ }
150+
125151 DATA_DIR=" $( find_data_dir || create_and_return_data_dir) " || return 1
126152 test -d " ${DATA_DIR:? } /perms" || mkdir -p -- " ${DATA_DIR:? } /perms" || return 1
127153
128154 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?} "
155+ tag=" $( eval " printf '%s\n' \"\$ {TAG_API_${api:? } :?}\" " ) " || {
156+ printf ' %s\n' " Failed to get tag for API ${api?} "
157+ return 4
158+ }
130159 printf ' %s\n' " API ${api:? } : ${tag:? } "
131- download_and_parse_permissions " ${api:? } " " ${tag:? } " || printf ' %s\n' " Failed to download/parse XML for API ${api?} "
160+ download_and_parse_permissions " ${api:? } " " ${tag:? } " || {
161+ printf ' %s\n' " Failed to download/parse XML for API ${api?} "
162+ return 5
163+ }
132164 done
133165}
134166
@@ -139,8 +171,8 @@ while test "${#}" -gt 0; do
139171 case " ${1?} " in
140172 -V | --version)
141173 printf ' %s\n' " ${SCRIPT_NAME:? } v${SCRIPT_VERSION:? } "
142- printf ' %s\n' " Copyright (c) 2025 ${SCRIPT_AUTHOR:? } "
143- printf ' %s\n' ' License GPLv3+ '
174+ printf ' %s\n' " Copy " " right (c) 2025 ${SCRIPT_AUTHOR:? } "
175+ printf ' %s\n' ' License GPL-3.0+ OR Apache-2.0 '
144176 execute_script=' false'
145177 ;;
146178
@@ -173,8 +205,8 @@ if test "${execute_script:?}" = 'true'; then
173205 show_status " ${SCRIPT_NAME:? } v${SCRIPT_VERSION:? } by ${SCRIPT_AUTHOR:? } "
174206
175207 if test " ${# } " -eq 0; then set -- ' ' ; fi
176- main " ${@ } "
177- STATUS=" ${?} "
208+ main " ${@ } " || STATUS=" ${?} "
178209fi
179210
180- exit " ${STATUS:? } "
211+ pause_if_needed " ${STATUS:? } "
212+ exit " ${?} "
0 commit comments