Skip to content

Commit ce56c4b

Browse files
committed
Sync with microG unofficial installer
1 parent a668f9f commit ce56c4b

File tree

2 files changed

+78
-47
lines changed

2 files changed

+78
-47
lines changed

zip-content/customize.sh

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,34 @@ export POSIXLY_CORRECT='y'
1919

2020
### PREVENTIVE CHECKS ###
2121

22-
if test -z "${BOOTMODE:-}"; then
22+
if test -z "${BOOTMODE-}"; then
2323
printf 1>&2 '%s\n' 'Missing BOOTMODE variable'
24-
abort 'Missing BOOTMODE variable' 2> /dev/null || exit 1
24+
abort 2> /dev/null 'Missing BOOTMODE variable'
25+
exit 1
2526
fi
26-
if test -z "${OUTFD:-}" || test "${OUTFD:?}" -lt 1; then
27-
printf 1>&2 '%s\n' 'Missing or invalid OUTFD variable'
28-
abort 'Missing or invalid OUTFD variable' 2> /dev/null || exit 1
29-
fi
30-
RECOVERY_PIPE="/proc/self/fd/${OUTFD:?}"
31-
if test -z "${ZIPFILE:-}"; then
27+
if test -z "${ZIPFILE-}"; then
3228
printf 1>&2 '%s\n' 'Missing ZIPFILE variable'
33-
abort 'Missing ZIPFILE variable' 2> /dev/null || exit 1
29+
abort 2> /dev/null 'Missing ZIPFILE variable'
30+
exit 1
3431
fi
35-
if test -z "${TMPDIR:-}" || test ! -e "${TMPDIR:?}"; then
32+
if test -z "${TMPDIR-}" || test ! -e "${TMPDIR:?}"; then
3633
printf 1>&2 '%s\n' 'The temp folder is missing (2)'
37-
abort 'The temp folder is missing (2)' 2> /dev/null || exit 1
34+
abort 2> /dev/null 'The temp folder is missing (2)'
35+
exit 1
36+
fi
37+
if test -z "${OUTFD-}" || test "${OUTFD:?}" -lt 1; then
38+
printf 1>&2 '%s\n' 'Missing or invalid OUTFD variable'
39+
abort 2> /dev/null 'Missing or invalid OUTFD variable'
40+
exit 1
3841
fi
42+
RECOVERY_PIPE="/proc/self/fd/${OUTFD:?}"
43+
test -e "${RECOVERY_PIPE:?}" || RECOVERY_PIPE=''
3944

4045
export BOOTMODE
41-
export OUTFD
42-
export RECOVERY_PIPE
4346
export ZIPFILE
4447
export TMPDIR
48+
export OUTFD
49+
export RECOVERY_PIPE
4550
export ANDROID_ROOT
4651
export ANDROID_DATA
4752
unset REPLACE
@@ -130,35 +135,46 @@ _send_text_to_recovery()
130135
{
131136
if test "${RECOVERY_OUTPUT:?}" != 'true'; then return; fi # Nothing to do here
132137

133-
if test -e "${RECOVERY_PIPE:?}"; then
138+
if test -n "${RECOVERY_PIPE?}"; then
134139
printf 'ui_print %s\nui_print\n' "${1?}" >> "${RECOVERY_PIPE:?}"
135140
else
136141
printf 'ui_print %s\nui_print\n' "${1?}" 1>&"${OUTFD:?}"
137142
fi
138143

139-
if test "${DEBUG_LOG_ENABLED:?}" -eq 1; then printf 1>&2 '%s\n' "${1?}"; fi
144+
if test "${DEBUG_LOG_ENABLED:?}" = '1'; then printf 1>&2 '%s\n' "${1?}"; fi
145+
}
146+
147+
_print_text()
148+
{
149+
if test -n "${NO_COLOR-}"; then
150+
printf '%s\n' "${2?}"
151+
else
152+
# shellcheck disable=SC2059
153+
printf "${1:?}\n" "${2?}"
154+
fi
140155
}
141156

142157
ui_error()
143158
{
144-
ERROR_CODE=79
145-
if test -n "${2:-}"; then ERROR_CODE="${2:?}"; fi
159+
local _error_code
160+
_error_code=79
161+
test -z "${2-}" || _error_code="${2:?}"
146162

147163
if test "${RECOVERY_OUTPUT:?}" = 'true'; then
148-
_send_text_to_recovery "ERROR ${ERROR_CODE:?}: ${1:?}"
164+
_send_text_to_recovery "ERROR ${_error_code:?}: ${1:?}"
149165
else
150-
printf 1>&2 '\033[1;31m%s\033[0m\n' "ERROR ${ERROR_CODE:?}: ${1:?}"
166+
_print_text 1>&2 '\033[1;31m%s\033[0m' "ERROR ${_error_code:?}: ${1:?}"
151167
fi
152168

153-
abort '' 2> /dev/null || exit "${ERROR_CODE:?}"
169+
exit "${_error_code:?}"
154170
}
155171

156172
ui_warning()
157173
{
158174
if test "${RECOVERY_OUTPUT:?}" = 'true'; then
159175
_send_text_to_recovery "WARNING: ${1:?}"
160176
else
161-
printf 1>&2 '\033[0;33m%s\033[0m\n' "WARNING: ${1:?}"
177+
_print_text 1>&2 '\033[0;33m%s\033[0m' "WARNING: ${1:?}"
162178
fi
163179
}
164180

@@ -173,7 +189,7 @@ ui_msg()
173189

174190
ui_debug()
175191
{
176-
printf '%s\n' "${1?}"
192+
printf 1>&2 '%s\n' "${1?}"
177193
}
178194

179195
enable_debug_log()
@@ -189,6 +205,7 @@ enable_debug_log()
189205
return
190206
}
191207

208+
export NO_COLOR=1
192209
export DEBUG_LOG_ENABLED=1
193210

194211
# If they are already in use, then use alternatives
@@ -208,7 +225,7 @@ enable_debug_log()
208225
disable_debug_log()
209226
{
210227
if test "${DEBUG_LOG_ENABLED}" -ne 1; then return; fi
211-
export DEBUG_LOG_ENABLED=0
228+
212229
if test "${ALTERNATIVE_FDS:?}" -eq 0; then
213230
exec 1>&6 2>&7 # Restore stdout and stderr
214231
exec 6>&- 7>&-
@@ -217,6 +234,9 @@ disable_debug_log()
217234
# shellcheck disable=SC3023
218235
exec 88>&- 89>&-
219236
fi
237+
238+
export DEBUG_LOG_ENABLED=0
239+
unset NO_COLOR
220240
}
221241

222242
set_perm()

zip-content/inc/common-functions.sh

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ unset CDPATH
3030

3131
### PREVENTIVE CHECKS ###
3232

33-
if test -z "${ZIPFILE:-}" || test -z "${TMP_PATH:-}" || test -z "${RECOVERY_PIPE:-}" || test -z "${OUTFD:-}" || test -z "${INPUT_FROM_TERMINAL:-}" || test -z "${DEBUG_LOG_ENABLED:-}"; then
33+
if test -z "${ZIPFILE:-}" || test -z "${TMP_PATH:-}" || test "${RECOVERY_PIPE-unset}" = 'unset' || test -z "${OUTFD:-}" || test -z "${INPUT_FROM_TERMINAL:-}" || test -z "${DEBUG_LOG_ENABLED:-}"; then
3434
echo 'Some variables are NOT set.'
3535
exit 90
3636
fi
@@ -51,35 +51,46 @@ _send_text_to_recovery()
5151
{
5252
if test "${RECOVERY_OUTPUT:?}" != 'true'; then return; fi # Nothing to do here
5353

54-
if test -e "${RECOVERY_PIPE:?}"; then
54+
if test -n "${RECOVERY_PIPE?}"; then
5555
printf 'ui_print %s\nui_print\n' "${1?}" >> "${RECOVERY_PIPE:?}"
5656
else
5757
printf 'ui_print %s\nui_print\n' "${1?}" 1>&"${OUTFD:?}"
5858
fi
5959

60-
if test "${DEBUG_LOG_ENABLED:?}" -eq 1; then printf 1>&2 '%s\n' "${1?}"; fi
60+
if test "${DEBUG_LOG_ENABLED:?}" = '1'; then printf 1>&2 '%s\n' "${1?}"; fi
61+
}
62+
63+
_print_text()
64+
{
65+
if test -n "${NO_COLOR-}"; then
66+
printf '%s\n' "${2?}"
67+
else
68+
# shellcheck disable=SC2059
69+
printf "${1:?}\n" "${2?}"
70+
fi
6171
}
6272

6373
ui_error()
6474
{
65-
ERROR_CODE=91
66-
if test -n "${2:-}"; then ERROR_CODE="${2:?}"; fi
75+
local _error_code
76+
_error_code=91
77+
test -z "${2-}" || _error_code="${2:?}"
6778

6879
if test "${RECOVERY_OUTPUT:?}" = 'true'; then
69-
_send_text_to_recovery "ERROR ${ERROR_CODE:?}: ${1:?}"
80+
_send_text_to_recovery "ERROR ${_error_code:?}: ${1:?}"
7081
else
71-
printf 1>&2 '\033[1;31m%s\033[0m\n' "ERROR ${ERROR_CODE:?}: ${1:?}"
82+
_print_text 1>&2 '\033[1;31m%s\033[0m' "ERROR ${_error_code:?}: ${1:?}"
7283
fi
7384

74-
exit "${ERROR_CODE:?}"
85+
exit "${_error_code:?}"
7586
}
7687

7788
ui_recovered_error()
7889
{
7990
if test "${RECOVERY_OUTPUT:?}" = 'true'; then
8091
_send_text_to_recovery "RECOVERED ERROR: ${1:?}"
8192
else
82-
printf 1>&2 '\033[1;31;103m%s\033[0m\n' "RECOVERED ERROR: ${1:?}"
93+
_print_text 1>&2 '\033[1;31;103m%s\033[0m' "RECOVERED ERROR: ${1:?}"
8394
fi
8495
}
8596

@@ -88,7 +99,7 @@ ui_warning()
8899
if test "${RECOVERY_OUTPUT:?}" = 'true'; then
89100
_send_text_to_recovery "WARNING: ${1:?}"
90101
else
91-
printf 1>&2 '\033[0;33m%s\033[0m\n' "WARNING: ${1:?}"
102+
_print_text 1>&2 '\033[0;33m%s\033[0m' "WARNING: ${1:?}"
92103
fi
93104
}
94105

@@ -115,27 +126,27 @@ ui_msg_sameline_start()
115126
if test "${RECOVERY_OUTPUT:?}" = 'false'; then
116127
printf '%s ' "${1:?}"
117128
return
118-
elif test -e "${RECOVERY_PIPE:?}"; then
129+
elif test -n "${RECOVERY_PIPE?}"; then
119130
printf 'ui_print %s' "${1:?}" >> "${RECOVERY_PIPE:?}"
120131
else
121132
printf 'ui_print %s' "${1:?}" 1>&"${OUTFD:?}"
122133
fi
123134

124-
if test "${DEBUG_LOG_ENABLED:?}" -eq 1; then printf 1>&2 '%s\n' "${1:?}"; fi
135+
if test "${DEBUG_LOG_ENABLED:?}" = '1'; then printf 1>&2 '%s\n' "${1:?}"; fi
125136
}
126137

127138
ui_msg_sameline_end()
128139
{
129140
if test "${RECOVERY_OUTPUT:?}" = 'false'; then
130141
printf '%s\n' "${1:?}"
131142
return
132-
elif test -e "${RECOVERY_PIPE:?}"; then
143+
elif test -n "${RECOVERY_PIPE?}"; then
133144
printf '%s\nui_print\n' "${1:?}" >> "${RECOVERY_PIPE:?}"
134145
else
135146
printf '%s\nui_print\n' "${1:?}" 1>&"${OUTFD:?}"
136147
fi
137148

138-
if test "${DEBUG_LOG_ENABLED:?}" -eq 1; then printf 1>&2 '%s\n' "${1:?}"; fi
149+
if test "${DEBUG_LOG_ENABLED:?}" = '1'; then printf 1>&2 '%s\n' "${1:?}"; fi
139150
}
140151

141152
ui_debug()
@@ -192,16 +203,6 @@ _detect_verity_status()
192203
fi
193204
}
194205

195-
_detect_battery_level()
196-
{
197-
if test -n "${DEVICE_DUMPSYS?}" && _val="$("${DEVICE_DUMPSYS:?}" battery | grep -m 1 -F -e 'level:' | cut -d ':' -f '2-' -s)" && _val="${_val# }" && test -n "${_val?}"; then
198-
printf '%s\n' "${_val:?}"
199-
return 0
200-
fi
201-
202-
return 1
203-
}
204-
205206
is_verity_enabled()
206207
{
207208
case "${VERITY_MODE?}" in
@@ -212,6 +213,16 @@ is_verity_enabled()
212213
return 0 # Enabled
213214
}
214215

216+
_detect_battery_level()
217+
{
218+
if test -n "${DEVICE_DUMPSYS?}" && _val="$("${DEVICE_DUMPSYS:?}" battery | grep -m 1 -F -e 'level:' | cut -d ':' -f '2-' -s)" && _val="${_val# }" && test -n "${_val?}"; then
219+
printf '%s\n' "${_val:?}"
220+
return 0
221+
fi
222+
223+
return 1
224+
}
225+
215226
_mount_helper()
216227
{
217228
{

0 commit comments

Comments
 (0)