Skip to content

Commit 547f1e6

Browse files
committed
Sync with microG unofficial installer
1 parent aae5417 commit 547f1e6

File tree

3 files changed

+149
-47
lines changed

3 files changed

+149
-47
lines changed

zip-content/inc/common-functions.sh

Lines changed: 126 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ unset CDPATH
2121

2222
### INIT OPTIONS ###
2323

24+
export DRY_RUN=0
25+
2426
# shellcheck disable=SC3040,SC2015
2527
{
2628
# Unsupported set options may cause the shell to exit (even without set -e), so first try them in a subshell to avoid this issue
@@ -185,32 +187,89 @@ _parse_kernel_cmdline()
185187
return 1
186188
}
187189

188-
_detect_slot()
190+
parse_boot_value()
189191
{
190-
_parse_kernel_cmdline 'slot_suffix'
192+
local _val
193+
194+
if _val="$(_parse_kernel_cmdline "${1:?}")"; then # Value from kernel command-line
195+
:
196+
elif _val="$(simple_getprop "ro.boot.${1:?}")" && is_valid_prop "${_val?}"; then # Value from getprop
197+
:
198+
else
199+
return 1
200+
fi
201+
202+
printf '%s\n' "${_val?}"
191203
}
192204

193-
_detect_verity_status()
205+
_detect_slot_suffix()
194206
{
195-
if _parse_kernel_cmdline 'veritymode'; then # Value from kernel command-line
207+
local _val
208+
209+
if _val="$(_parse_kernel_cmdline 'slot_suffix')" && test -n "${_val?}"; then # Value from kernel command-line
210+
:
211+
elif _val="$(_parse_kernel_cmdline 'slot')" && test -n "${_val?}" && _val="_${_val:?}"; then # Value from kernel command-line
212+
:
213+
elif _val="$(simple_getprop 'ro.boot.slot_suffix')" && is_valid_prop "${_val?}"; then # Value from getprop
214+
:
215+
elif _val="$(simple_getprop 'ro.boot.slot')" && is_valid_prop "${_val?}" && _val="_${_val:?}"; then # Value from getprop
216+
:
217+
else
218+
return 1
219+
fi
220+
221+
printf '%s\n' "${_val:?}"
222+
}
223+
224+
_detect_device_state()
225+
{
226+
parse_boot_value 'vbmeta.device_state' || printf '%s\n' 'unknown'
227+
}
228+
229+
_detect_verified_boot_state()
230+
{
231+
parse_boot_value 'verifiedbootstate' || printf '%s\n' 'unknown'
232+
}
233+
234+
_detect_verity_state()
235+
{
236+
if parse_boot_value 'veritymode'; then
196237
:
197-
elif _val="$(simple_getprop 'ro.boot.veritymode')" && is_valid_prop "${_val?}"; then # Value from getprop
198-
printf '%s\n' "${_val:?}"
199238
elif simple_getprop | grep -q -m 1 -e '^\[ro\.boot\.veritymode\]'; then # If the value exist, even if empty, it is supported
200239
printf '%s\n' 'unknown'
201240
else
202241
printf '%s\n' 'unsupported'
203242
fi
204243
}
205244

245+
is_device_locked()
246+
{
247+
case "${DEVICE_STATE?}" in
248+
'locked') return 0 ;; # Device locked
249+
*) ;; # Device unlocked: 'unlocked' or 'unknown'
250+
esac
251+
252+
return 1
253+
}
254+
255+
is_bootloader_locked()
256+
{
257+
case "${VERIFIED_BOOT_STATE?}" in
258+
'green' | 'yellow' | 'red') return 0 ;; # Boot loader locked
259+
*) ;; # Boot loader unlocked: 'orange' or 'unknown'
260+
esac
261+
262+
return 1
263+
}
264+
206265
is_verity_enabled()
207266
{
208267
case "${VERITY_MODE?}" in
209-
'unsupported' | 'unknown' | 'disabled' | 'ignore_corruption' | '') return 1 ;; # NOT enabled
210-
*) ;;
268+
'unsupported' | 'unknown' | 'disabled' | 'logging' | '') return 1 ;; # Verity NOT enabled
269+
*) ;; # Verity enabled: 'enforcing', 'eio' or 'panicking'
211270
esac
212271

213-
return 0 # Enabled
272+
return 0
214273
}
215274

216275
_detect_battery_level()
@@ -443,7 +502,7 @@ _manual_partition_mount()
443502
fi
444503
done
445504
else
446-
ui_warning "Block not found => ${1?}"
505+
ui_warning "Block not found for => $(printf '%s' "${1?}" | tr -- '\n' ' ' || :)"
447506
fi
448507

449508
IFS="${_backup_ifs:-}"
@@ -488,7 +547,7 @@ _find_and_mount_system()
488547
ui_msg "Recovery fake system: ${RECOVERY_FAKE_SYSTEM:?}"
489548
ui_msg_empty_line
490549

491-
ui_error "The ROM cannot be found!"
550+
ui_error "The ROM cannot be found!!!" 123
492551
fi
493552
fi
494553

@@ -828,6 +887,7 @@ initialize()
828887
DATA_PATH='/data'
829888
PRODUCT_WRITABLE='false'
830889
VENDOR_WRITABLE='false'
890+
SYS_EXT_WRITABLE='false'
831891

832892
# Make sure that the commands are still overridden here (most shells don't have the ability to export functions)
833893
if test "${TEST_INSTALL:-false}" != 'false' && test -f "${RS_OVERRIDE_SCRIPT:?}"; then
@@ -843,11 +903,19 @@ initialize()
843903
_get_local_settings
844904

845905
if test "${INPUT_FROM_TERMINAL:?}" = 'true' && test "${LIVE_SETUP_TIMEOUT:?}" -gt 0; then LIVE_SETUP_TIMEOUT="$((LIVE_SETUP_TIMEOUT + 3))"; fi
906+
DRY_RUN="$(parse_setting 'DRY_RUN' "${DRY_RUN:?}" 'false')"
846907
LIVE_SETUP_DEFAULT="$(parse_setting 'LIVE_SETUP_DEFAULT' "${LIVE_SETUP_DEFAULT:?}" 'false')"
847908
LIVE_SETUP_TIMEOUT="$(parse_setting 'LIVE_SETUP_TIMEOUT' "${LIVE_SETUP_TIMEOUT:?}" 'false')"
848909

849910
ui_debug ''
850911

912+
case "${DRY_RUN?}" in '') DRY_RUN=0 ;; *[!0-9]*) DRY_RUN=1 ;; *) ;; esac
913+
readonly DRY_RUN
914+
if test "${DRY_RUN:?}" -gt 0; then
915+
ui_warning "DRY RUN mode ${DRY_RUN?} enabled!!! No files on your device will be modified"
916+
ui_debug ''
917+
fi
918+
851919
# Some recoveries have a fake system folder when nothing is mounted with just bin, etc and lib / lib64 or, in some rare cases, just bin and usr.
852920
# Usable binaries are under the fake /system/bin so the /system mountpoint mustn't be used while in this recovery.
853921
if test "${BOOTMODE:?}" != 'true' &&
@@ -861,13 +929,13 @@ initialize()
861929
fi
862930
export RECOVERY_FAKE_SYSTEM
863931

864-
SLOT="$(_detect_slot)" || SLOT=''
932+
SLOT="$(_detect_slot_suffix)" || SLOT=''
865933
readonly SLOT
866934
export SLOT
867935

868-
DEVICE_STATE="$(_parse_kernel_cmdline 'vbmeta\.device_state')" || DEVICE_STATE='unknown'
869-
VERIFIED_BOOT_STATE="$(_parse_kernel_cmdline 'verifiedbootstate')" || VERIFIED_BOOT_STATE='unknown'
870-
VERITY_MODE="$(_detect_verity_status)" || VERITY_MODE='unknown'
936+
DEVICE_STATE="$(_detect_device_state)"
937+
VERIFIED_BOOT_STATE="$(_detect_verified_boot_state)"
938+
VERITY_MODE="$(_detect_verity_state)"
871939
readonly DEVICE_STATE VERIFIED_BOOT_STATE VERITY_MODE
872940
export DEVICE_STATE VERIFIED_BOOT_STATE VERITY_MODE
873941

@@ -877,10 +945,19 @@ initialize()
877945
BATTERY_LEVEL="$(_detect_battery_level)" || BATTERY_LEVEL=''
878946
readonly BATTERY_LEVEL
879947
export BATTERY_LEVEL
948+
880949
if test -n "${BATTERY_LEVEL?}" && test "${BATTERY_LEVEL:?}" -le 15; then
881950
ui_error "The battery is too low. Current level: ${BATTERY_LEVEL?}%" 108
882951
fi
883952

953+
if is_device_locked; then
954+
ui_error 'The device is locked!!!' 37
955+
fi
956+
957+
if is_bootloader_locked; then
958+
ui_error "The boot loader is locked!!! Verified boot state: ${VERIFIED_BOOT_STATE?}" 37
959+
fi
960+
884961
_find_and_mount_system
885962
cp -pf "${SYS_PATH:?}/build.prop" "${TMP_PATH:?}/build.prop" # Cache the file for faster access
886963

@@ -948,7 +1025,7 @@ initialize()
9481025
export FIRST_INSTALLATION PREV_MODULE_VERCODE PREV_INSTALL_FAILED
9491026

9501027
if test "${MODULE_VERCODE:?}" -lt "${PREV_MODULE_VERCODE:?}"; then
951-
ui_error 'Downgrade not allowed!!!'
1028+
ui_error 'Downgrade not allowed!!!' 95
9521029
fi
9531030

9541031
IS_INSTALLATION='true'
@@ -982,9 +1059,9 @@ initialize()
9821059
ui_msg_empty_line
9831060

9841061
if is_verity_enabled; then
985-
ui_error "Remounting '${SYS_MOUNTPOINT?}' failed, it is possible that DM-Verity is enabled. If this is the case you should DISABLE it!!!"
1062+
ui_error "Remounting '${SYS_MOUNTPOINT?}' failed, it is possible that Verity is enabled. If this is the case you should DISABLE it!!!" 30
9861063
else
987-
ui_error "Remounting '${SYS_MOUNTPOINT?}' failed!!!"
1064+
ui_error "Remounting '${SYS_MOUNTPOINT?}' failed!!!" 30
9881065
fi
9891066
}
9901067
fi
@@ -1002,13 +1079,15 @@ initialize()
10021079
if mount_partition_if_possible 'system_ext' "${SLOT:+system_ext}${SLOT-}${NL:?}system_ext${NL:?}"; then
10031080
SYS_EXT_PATH="${LAST_MOUNTPOINT:?}"
10041081
UNMOUNT_SYS_EXT="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
1005-
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false
1082+
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false && SYS_EXT_WRITABLE='true'
10061083
fi
10071084
if mount_partition_if_possible 'odm' "${SLOT:+odm}${SLOT-}${NL:?}odm${NL:?}"; then
10081085
ODM_PATH="${LAST_MOUNTPOINT:?}"
10091086
UNMOUNT_ODM="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
10101087
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false
10111088
fi
1089+
readonly PRODUCT_WRITABLE VENDOR_WRITABLE SYS_EXT_WRITABLE
1090+
export PRODUCT_WRITABLE VENDOR_WRITABLE SYS_EXT_WRITABLE
10121091

10131092
local _additional_data_mountpoint=''
10141093
if test -n "${ANDROID_DATA-}" && test "${ANDROID_DATA:?}" != '/data'; then _additional_data_mountpoint="${ANDROID_DATA:?}"; fi
@@ -1106,10 +1185,12 @@ clean_previous_installations()
11061185
{
11071186
local _initial_free_space
11081187

1188+
test "${DRY_RUN:?}" -eq 0 || return
1189+
11091190
if _write_test "${SYS_PATH:?}/etc"; then
11101191
: # Really writable
11111192
else
1112-
ui_error "Something is wrong because '${SYS_PATH?}' is NOT really writable!!!"
1193+
ui_error "Something is wrong because '${SYS_PATH?}' is NOT really writable!!!" 30
11131194
fi
11141195

11151196
_initial_free_space="$(get_free_disk_space_of_partition "${SYS_PATH:?}")" || _initial_free_space='-1'
@@ -1483,6 +1564,7 @@ verify_disk_space()
14831564

14841565
if test "${PRODUCT_WRITABLE:?}" = 'true'; then display_free_space "${PRODUCT_PATH:?}" "$(get_free_disk_space_of_partition "${PRODUCT_PATH:?}" || :)"; fi
14851566
if test "${VENDOR_WRITABLE:?}" = 'true'; then display_free_space "${VENDOR_PATH:?}" "$(get_free_disk_space_of_partition "${VENDOR_PATH:?}" || :)"; fi
1567+
if test "${SYS_EXT_WRITABLE:?}" = 'true'; then display_free_space "${SYS_EXT_PATH:?}" "$(get_free_disk_space_of_partition "${SYS_EXT_PATH:?}" || :)"; fi
14861568

14871569
if test "${_needed_space_bytes:?}" -ge 0 && test "${_free_space_bytes:?}" -ge 0; then
14881570
: # OK
@@ -1538,7 +1620,7 @@ perform_secure_copy_to_device()
15381620

15391621
local _ret_code
15401622
_ret_code=5
1541-
! _is_free_space_error "${_error_text?}" || _ret_code=28
1623+
! _is_free_space_error "${_error_text?}" || _ret_code=122
15421624

15431625
if test -n "${_error_text?}"; then
15441626
ui_error "Failed to copy '${1?}' to the device due to => $(printf '%s\n' "${_error_text?}" | head -n 1 || :)" "${_ret_code?}"
@@ -1557,6 +1639,8 @@ perform_installation()
15571639

15581640
ui_msg_empty_line
15591641

1642+
test "${DRY_RUN:?}" -eq 0 || return
1643+
15601644
ui_msg 'Installing...'
15611645

15621646
if test ! -d "${SYS_PATH:?}/etc/zips"; then
@@ -1605,7 +1689,9 @@ perform_installation()
16051689

16061690
finalize_and_report_success()
16071691
{
1608-
rm -f -- "${SYS_PATH:?}/etc/zips/${MODULE_ID:?}.failed" || :
1692+
if test "${DRY_RUN:?}" -eq 0; then
1693+
rm -f -- "${SYS_PATH:?}/etc/zips/${MODULE_ID:?}.failed" || :
1694+
fi
16091695
deinitialize
16101696
touch "${TMP_PATH:?}/installed"
16111697

@@ -1778,9 +1864,9 @@ package_extract_file()
17781864

17791865
custom_package_extract_dir()
17801866
{
1781-
mkdir -p "${2:?}" || ui_error "Failed to create the dir '${2}' for extraction" 95
1867+
mkdir -p "${2:?}" || ui_error "Failed to create the dir '${2}' for extraction"
17821868
set_perm 0 0 0755 "${2:?}"
1783-
unzip -oq "${ZIPFILE:?}" "${1:?}/*" -d "${2:?}" || ui_error "Failed to extract the dir '${1}' from this archive" 95
1869+
unzip -oq "${ZIPFILE:?}" "${1:?}/*" -d "${2:?}" || ui_error "Failed to extract the dir '${1}' from this archive"
17841870
}
17851871

17861872
zip_extract_file()
@@ -1802,6 +1888,8 @@ zip_extract_dir()
18021888
# Data reset functions
18031889
reset_gms_data_of_all_apps()
18041890
{
1891+
test "${DRY_RUN:?}" -eq 0 || return
1892+
18051893
if test -e "${DATA_PATH:?}/data"; then
18061894
ui_debug 'Resetting GMS data of all apps...'
18071895
find "${DATA_PATH:?}"/data/*/shared_prefs -name 'com.google.android.gms.*.xml' -delete
@@ -2609,7 +2697,7 @@ choose_read_with_timeout()
26092697
'c' | 'C' | "${_esc_keycode:?}") _key='ESC' ;; # ESC or C key (allowed)
26102698
'') continue ;; # Enter key (ignored)
26112699
*)
2612-
printf 'Invalid choice!!!'
2700+
printf '%s' 'Invalid choice!!!'
26132701
continue
26142702
;; # NOT allowed
26152703
esac
@@ -2644,7 +2732,7 @@ choose_read()
26442732
'c' | 'C' | "${_esc_keycode:?}") _key='ESC' ;; # ESC or C key (allowed)
26452733
'') continue ;; # Enter key (ignored)
26462734
*)
2647-
printf 'Invalid choice!!!'
2735+
printf '%s' 'Invalid choice!!!'
26482736
continue
26492737
;; # NOT allowed
26502738
esac
@@ -2861,34 +2949,44 @@ live_setup_choice()
28612949
# Other
28622950
soft_kill_app()
28632951
{
2952+
test "${DRY_RUN:?}" -eq 0 || return
2953+
28642954
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_AM?}"; then
28652955
PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" 2> /dev/null kill "${1:?}" || true
28662956
fi
28672957
}
28682958

28692959
kill_app()
28702960
{
2961+
test "${DRY_RUN:?}" -eq 0 || return
2962+
28712963
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_AM?}"; then
28722964
PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" 2> /dev/null force-stop "${1:?}" || PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" 2> /dev/null kill "${1:?}" || true
28732965
fi
28742966
}
28752967

28762968
disable_app()
28772969
{
2970+
test "${DRY_RUN:?}" -eq 0 || return
2971+
28782972
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}"; then
28792973
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null disable "${1:?}" || true
28802974
fi
28812975
}
28822976

28832977
clear_app()
28842978
{
2979+
test "${DRY_RUN:?}" -eq 0 || return
2980+
28852981
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}"; then
28862982
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null clear "${1:?}" || true
28872983
fi
28882984
}
28892985

28902986
clear_and_enable_app()
28912987
{
2988+
test "${DRY_RUN:?}" -eq 0 || return
2989+
28922990
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}"; then
28932991
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null clear "${1:?}" || true
28942992
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null enable "${1:?}" || true
@@ -2897,6 +2995,8 @@ clear_and_enable_app()
28972995

28982996
reset_authenticator_and_sync_adapter_caches()
28992997
{
2998+
test "${DRY_RUN:?}" -eq 0 || return
2999+
29003000
# Reset to avoid problems with signature changes
29013001
delete "${DATA_PATH:?}"/system/registered_services/android.accounts.AccountAuthenticator.xml
29023002
delete "${DATA_PATH:?}"/system/registered_services/android.content.SyncAdapter.xml

zip-content/module.prop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
id=google-sync-addon
66
name=Google Sync add-on
7-
version=v1.3.1.77-alpha
7+
version=v1.3.1.79-alpha
88
versionCode=5
99
author=ale5000
1010
description=It installs Google sync adapters on Android.

0 commit comments

Comments
 (0)