Skip to content

Commit 3b025fa

Browse files
committed
Sync with microG unofficial installer
1 parent 4f19478 commit 3b025fa

File tree

3 files changed

+132
-86
lines changed

3 files changed

+132
-86
lines changed

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-FileCopyrightText: none
22
# SPDX-License-Identifier: CC0-1.0
3-
# SPDX-FileType: OTHER
43

54
root = true
65

.gitignore

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# SPDX-FileCopyrightText: none
22
# SPDX-License-Identifier: CC0-1.0
3-
# SPDX-FileType: OTHER
43

5-
# Custom project folders
6-
/cache/
7-
/output/
8-
/recovery-simulator/output/
9-
/utils/data/
4+
# Files to always ignore
5+
/coverage/
6+
/.ssh/
7+
/.ash_history
8+
/.bash_history
9+
/.wget-hsts
10+
/.lesshst
11+
*.log
12+
*.sarif
13+
*.dex
14+
15+
# Caches
16+
/.cache/
17+
/.git/
18+
__pycache__/
19+
.DS_Store
20+
desktop.ini
21+
Thumbs.db
1022

1123
# VS Code files
1224
/.vscode/launch.json
@@ -19,27 +31,15 @@
1931
local.properties
2032
user.gradle
2133

22-
# Files to ignore
34+
# Local files to ignore
2335
.debug/
2436
.local/
2537
/local/
2638
/build
2739
/cmdline
2840

29-
# Coverage, logs and other files
30-
/coverage/
31-
/.ssh/
32-
/.wget-hsts
33-
/.ash_history
34-
/.bash_history
35-
*.log
36-
*.sarif
37-
*.dex
38-
39-
# Caches
40-
/.cache/
41-
/.git/
42-
__pycache__/
43-
.DS_Store
44-
desktop.ini
45-
Thumbs.db
41+
# Custom project folders
42+
/cache/
43+
/output/
44+
/recovery-simulator/output/
45+
/utils/data/

zip-content/inc/common-functions.sh

Lines changed: 108 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ if test -z "${ZIPFILE:-}" || test -z "${TMP_PATH:-}" || test -z "${RECOVERY_PIPE
3535
exit 90
3636
fi
3737

38-
mkdir -p "${TMP_PATH:?}/func-tmp" || ui_error 'Failed to create the functions temp folder'
38+
mkdir -p "${TMP_PATH:?}/func-tmp" || {
39+
echo 'Failed to create the functions temp folder'
40+
exit 90
41+
}
3942

4043
readonly ROLLBACK_TEST='false'
4144
readonly NL='
@@ -74,9 +77,12 @@ _detect_slot()
7477

7578
_mount_helper()
7679
{
77-
mount "${@}" 2> /dev/null || {
78-
test -n "${DEVICE_MOUNT:-}" && "${DEVICE_MOUNT:?}" -t 'auto' "${@}"
79-
} || return "${?}"
80+
{
81+
test -n "${DEVICE_MOUNT-}" && PATH="${PREVIOUS_PATH:?}" "${DEVICE_MOUNT:?}" 2> /dev/null "${@}"
82+
} ||
83+
mount "${@}" ||
84+
return "${?}"
85+
8086
return 0
8187
}
8288

@@ -128,7 +134,7 @@ _mount_and_verify_system_partition()
128134
test -n "${_path?}" || continue
129135

130136
case "${_path:?}" in
131-
'/mnt/'* | "${TMP_PATH:?}/"*) continue ;; # Note: These paths can only be mounted manually (example: /mnt/system)
137+
'/mnt'/* | "${TMP_PATH:?}"/*) continue ;; # NOTE: These paths can only be mounted manually (example: /mnt/system)
132138
*) ;;
133139
esac
134140

@@ -309,9 +315,8 @@ _manual_partition_mount()
309315
_curr_mp_list="${_curr_mp_list?}${_curr_mp_list:+, }${_path:?}"
310316

311317
umount 2> /dev/null "${_path:?}" || :
312-
if _mount_helper '-o' 'rw' "${_block:?}" "${_path:?}"; then
318+
if _mount_helper "${_block:?}" "${_path:?}"; then
313319
IFS="${_backup_ifs:-}"
314-
ui_debug "Mounted: ${_path?}"
315320
LAST_MOUNTPOINT="${_path:?}"
316321
return 0
317322
fi
@@ -361,8 +366,8 @@ _find_and_mount_system()
361366

362367
if _mount_and_verify_system_partition "${_sys_mountpoint_list?}"; then
363368
: # Mounted and found
364-
elif _manual_partition_mount "${SLOT:+system}${SLOT-}${NL:?}system${NL:?}FACTORYFS${NL:?}" "${_sys_mountpoint_list?}" && _verify_system_partition "${_sys_mountpoint_list?}"; then
365-
: # Mounted and found
369+
elif _manual_partition_mount "${SLOT:+system}${SLOT-}${NL:?}system${NL:?}FACTORYFS${NL:?}" "${_sys_mountpoint_list?}" && test -n "${LAST_MOUNTPOINT?}" && _verify_system_partition "${_sys_mountpoint_list?}"; then
370+
ui_debug "Mounted: ${LAST_MOUNTPOINT?}" # Mounted and found
366371
else
367372
deinitialize
368373

@@ -382,26 +387,68 @@ _find_and_mount_system()
382387
readonly SYS_MOUNTPOINT SYS_PATH
383388
}
384389

385-
UNMOUNT_PRODUCT=0
386-
UNMOUNT_VENDOR=0
387-
UNMOUNT_SYS_EXT=0
388-
UNMOUNT_ODM=0
389390
mount_partition_if_exist()
390391
{
391-
local _path
392+
local _backup_ifs _partition_name _block_search_list _raw_mp_list _mp_list _mp
393+
unset LAST_MOUNTPOINT
392394
LAST_PARTITION_MUST_BE_UNMOUNTED=0
393395

394-
test -e "/${2:?}" || return 1
395-
_path="$(_canonicalize "/${2:?}")"
396+
_partition_name="${2:?}"
397+
_block_search_list="${1:?}"
398+
_raw_mp_list="/mnt/${2:?}${NL:?}${3-}${NL:?}/${2:?}${NL:?}"
396399

397-
if is_mounted "${_path:?}"; then
398-
return 0
399-
elif _manual_partition_mount "${1:?}" "${_path:?}${NL:?}"; then
400+
_backup_ifs="${IFS-}"
401+
IFS="${NL:?}"
402+
403+
_mp_list=''
404+
for _mp in ${_raw_mp_list?}; do
405+
if test -n "${_mp?}" && test -e "${_mp:?}"; then
406+
_mp="$(_canonicalize "${_mp:?}")"
407+
_mp_list="${_mp_list?}${_mp:?}${NL:?}"
408+
fi
409+
done
410+
unset _raw_mp_list
411+
set -f || :
412+
# shellcheck disable=SC2086 # Word splitting is intended
413+
set -- ${_mp_list?} || ui_error "Failed expanding \${_mp_list} inside mount_partition_if_exist()"
414+
set +f || :
415+
416+
IFS="${_backup_ifs?}"
417+
418+
test -n "${_mp_list?}" || return 1 # No usable mountpoint found
419+
420+
ui_debug "Checking ${_partition_name?}..."
421+
422+
for _mp in "${@}"; do
423+
if is_mounted "${_mp:?}"; then
424+
LAST_MOUNTPOINT="${_mp:?}"
425+
ui_debug "Already mounted: ${LAST_MOUNTPOINT?}"
426+
return 0 # Already mounted
427+
fi
428+
done
429+
430+
if _manual_partition_mount "${_block_search_list:?}" "${_mp_list:?}" && test -n "${LAST_MOUNTPOINT?}"; then
400431
LAST_PARTITION_MUST_BE_UNMOUNTED=1
401-
return 0
432+
ui_debug "Mounted: ${LAST_MOUNTPOINT?}"
433+
return 0 # Successfully mounted
402434
fi
403435

404-
return 1
436+
for _mp in "${@}"; do
437+
case "${_mp:?}" in
438+
'/mnt'/* | "${TMP_PATH:?}"/*) continue ;; # NOTE: These paths can only be mounted manually (example: /mnt/system)
439+
*) ;;
440+
esac
441+
442+
if _mount_helper "${_mp:?}"; then
443+
LAST_MOUNTPOINT="${_mp:?}"
444+
LAST_PARTITION_MUST_BE_UNMOUNTED=1
445+
ui_debug "Mounted (2): ${LAST_MOUNTPOINT?}"
446+
return 0 # Successfully mounted
447+
fi
448+
done
449+
450+
ui_warning "Mounting of ${_partition_name?} failed"
451+
return 2
405452
}
406453

407454
_get_local_settings()
@@ -455,12 +502,11 @@ parse_setting()
455502
remount_read_write_if_needed()
456503
{
457504
local _mountpoint _required
458-
_mountpoint="$(_canonicalize "${1:?}")"
505+
_mountpoint="${1:?}"
459506
_required="${2:-true}"
460507

461508
if is_mounted "${_mountpoint:?}" && is_mounted_read_only "${_mountpoint:?}"; then
462509
ui_msg "INFO: The '${_mountpoint:-}' mount point is read-only, it will be remounted"
463-
ui_msg_empty_line
464510
remount_read_write "${_mountpoint:?}" || {
465511
if test "${_required:?}" = 'true'; then
466512
ui_error "Remounting of '${_mountpoint:-}' failed"
@@ -471,6 +517,7 @@ remount_read_write_if_needed()
471517
fi
472518
}
473519
fi
520+
return 0
474521
}
475522

476523
is_string_starting_with()
@@ -654,8 +701,16 @@ display_info()
654701
initialize()
655702
{
656703
local _raw_arch_list
704+
657705
UNMOUNT_SYSTEM=0
658-
DATA_INIT_STATUS=0
706+
UNMOUNT_PRODUCT=0
707+
UNMOUNT_VENDOR=0
708+
UNMOUNT_SYS_EXT=0
709+
UNMOUNT_ODM=0
710+
UNMOUNT_DATA=0
711+
DATA_PATH='/data'
712+
PRODUCT_WRITABLE='false'
713+
VENDOR_WRITABLE='false'
659714

660715
# Make sure that the commands are still overridden here (most shells don't have the ability to export functions)
661716
if test "${TEST_INSTALL:-false}" != 'false' && test -f "${RS_OVERRIDE_SCRIPT:?}"; then
@@ -728,7 +783,7 @@ initialize()
728783
*) ;;
729784
esac
730785

731-
if is_string_starting_with 'sdk_google_phone_' "${BUILD_PRODUCT?}" || is_valid_prop "$(simple_getprop 'ro.leapdroid.version' || true)"; then
786+
if is_string_starting_with 'sdk_google_phone_' "${BUILD_PRODUCT?}" || is_valid_prop "$(simple_getprop 'ro.leapdroid.version' || :)"; then
732787
IS_EMU='true'
733788
fi
734789

@@ -809,40 +864,33 @@ initialize()
809864
}
810865
fi
811866

812-
if test "${ANDROID_DATA:-}" = '/data'; then ANDROID_DATA=''; fi # Avoid double checks
813-
814-
DATA_PATH="$(_canonicalize "${ANDROID_DATA:-/data}")"
815-
if test ! -e "${DATA_PATH:?}/data" && ! is_mounted "${DATA_PATH:?}"; then
816-
ui_debug "Mounting data..."
817-
unset LAST_MOUNTPOINT
818-
_mount_helper '-o' 'rw' "${DATA_PATH:?}" || _manual_partition_mount "userdata${NL:?}DATAFS${NL:?}" "${ANDROID_DATA:-}${NL:?}/data${NL:?}" || :
819-
if test -n "${LAST_MOUNTPOINT-}"; then DATA_PATH="${LAST_MOUNTPOINT:?}"; fi
820-
821-
if is_mounted "${DATA_PATH:?}"; then
822-
DATA_INIT_STATUS=1
823-
ui_debug "Mounted: ${DATA_PATH:-}"
824-
else
825-
ui_warning "The data partition cannot be mounted, so updates of installed / removed apps cannot be automatically deleted and their Dalvik cache cannot be automatically cleaned. I suggest to manually do a factory reset after flashing this ZIP."
826-
fi
827-
fi
828-
readonly DATA_PATH
829-
830-
if mount_partition_if_exist "${SLOT:+product}${SLOT-}${NL:?}product${NL:?}" "product"; then
867+
if mount_partition_if_exist "${SLOT:+product}${SLOT-}${NL:?}product${NL:?}" 'product'; then
831868
UNMOUNT_PRODUCT="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
832-
remount_read_write_if_needed '/product' false
869+
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false && PRODUCT_WRITABLE='true'
833870
fi
834-
if mount_partition_if_exist "${SLOT:+vendor}${SLOT-}${NL:?}vendor${NL:?}" "vendor"; then
871+
if mount_partition_if_exist "${SLOT:+vendor}${SLOT-}${NL:?}vendor${NL:?}" 'vendor'; then
835872
UNMOUNT_VENDOR="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
836-
remount_read_write_if_needed '/vendor' false
873+
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false && VENDOR_WRITABLE='true'
837874
fi
838-
if mount_partition_if_exist "${SLOT:+system_ext}${SLOT-}${NL:?}system_ext${NL:?}" "system_ext"; then
875+
if mount_partition_if_exist "${SLOT:+system_ext}${SLOT-}${NL:?}system_ext${NL:?}" 'system_ext'; then
839876
UNMOUNT_SYS_EXT="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
840-
remount_read_write_if_needed '/system_ext' false
877+
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false
841878
fi
842-
if mount_partition_if_exist "${SLOT:+odm}${SLOT-}${NL:?}odm${NL:?}" "odm"; then
879+
if mount_partition_if_exist "${SLOT:+odm}${SLOT-}${NL:?}odm${NL:?}" 'odm'; then
843880
UNMOUNT_ODM="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
844-
remount_read_write_if_needed '/odm' false
881+
remount_read_write_if_needed "${LAST_MOUNTPOINT:?}" false
882+
fi
883+
884+
if test "${ANDROID_DATA-}" = '/data'; then ANDROID_DATA=''; fi # Avoid double checks
885+
if mount_partition_if_exist "userdata${NL:?}DATAFS${NL:?}" 'data' "${ANDROID_DATA-}"; then
886+
DATA_PATH="${LAST_MOUNTPOINT:?}"
887+
UNMOUNT_DATA="${LAST_PARTITION_MUST_BE_UNMOUNTED:?}"
888+
remount_read_write_if_needed "${DATA_PATH:?}" true
889+
else
890+
ui_warning "The data partition cannot be mounted, so updates of installed / removed apps cannot be automatically deleted and their Dalvik cache cannot be automatically cleaned. I suggest to manually do a factory reset after flashing this ZIP."
845891
fi
892+
readonly DATA_PATH
893+
unset ANDROID_DATA
846894

847895
DEST_PATH="${SYS_PATH:?}"
848896
readonly DEST_PATH
@@ -855,14 +903,12 @@ initialize()
855903
ui_error "The '${DEST_PATH?}' partition is NOT writable"
856904
fi
857905

858-
unset LAST_PARTITION_MUST_BE_UNMOUNTED
859-
860906
# Display header
861-
ui_msg "$(write_separator_line "${#MODULE_NAME}" '-' || true)"
907+
ui_msg "$(write_separator_line "${#MODULE_NAME}" '-' || :)"
862908
ui_msg "${MODULE_NAME:?}"
863909
ui_msg "${MODULE_VERSION:?}"
864910
ui_msg "(by ${MODULE_AUTHOR:?})"
865-
ui_msg "$(write_separator_line "${#MODULE_NAME}" '-' || true)"
911+
ui_msg "$(write_separator_line "${#MODULE_NAME}" '-' || :)"
866912

867913
# shellcheck disable=SC2312
868914
_raw_arch_list=','"$(sys_getprop 'ro.product.cpu.abi')"','"$(sys_getprop 'ro.product.cpu.abi2')"','"$(sys_getprop 'ro.product.cpu.upgradeabi')"','"$(sys_getprop 'ro.product.cpu.abilist')"','
@@ -900,12 +946,13 @@ initialize()
900946
zip_extract_file "${SYS_PATH}/framework/framework-res.apk" 'AndroidManifest.xml' "${TMP_PATH}/framework-res"
901947
XML_MANIFEST="${TMP_PATH}/framework-res/AndroidManifest.xml"
902948
# Detect the presence of the fake signature permission
903-
# Note: It won't detect it if signature spoofing doesn't require a permission, but it is still fine for our case
949+
# NOTE: It won't detect it if signature spoofing doesn't require a permission, but it is still fine for our case
904950
if search_ascii_string_as_utf16_in_file 'android.permission.FAKE_PACKAGE_SIGNATURE' "${XML_MANIFEST}"; then
905951
FAKE_SIGN_PERMISSION='true'
906952
fi
907953

908954
unset LAST_MOUNTPOINT
955+
unset LAST_PARTITION_MUST_BE_UNMOUNTED
909956
unset CURRENTLY_ROLLBACKING
910957
}
911958

@@ -916,7 +963,7 @@ deinitialize()
916963
rmdir -- "${TMP_PATH:?}/system_mountpoint" || ui_error 'Failed to delete the temp mountpoint'
917964
fi
918965

919-
if test "${DATA_INIT_STATUS:?}" -eq 1 && test -n "${DATA_PATH-}"; then unmount "${DATA_PATH:?}"; fi
966+
if test "${UNMOUNT_DATA:?}" -eq 1 && test -n "${DATA_PATH-}"; then unmount "${DATA_PATH:?}"; fi
920967
}
921968

922969
clean_previous_installations()
@@ -1298,8 +1345,8 @@ verify_disk_space()
12981345
_free_space_bytes="$(get_free_disk_space_of_partition "${1:?}")" || _free_space_bytes='-1'
12991346
display_free_space "${1:?}" "${_free_space_bytes?}" || :
13001347

1301-
if test -e '/product'; then display_free_space '/product' "$(get_free_disk_space_of_partition '/product' || :)"; fi
1302-
if test -e '/vendor'; then display_free_space '/vendor' "$(get_free_disk_space_of_partition '/vendor' || :)"; fi
1348+
if test "${PRODUCT_WRITABLE:?}" = 'true'; then display_free_space '/product' "$(get_free_disk_space_of_partition '/product' || :)"; fi
1349+
if test "${VENDOR_WRITABLE:?}" = 'true'; then display_free_space '/vendor' "$(get_free_disk_space_of_partition '/vendor' || :)"; fi
13031350

13041351
if test "${_needed_space_bytes:?}" -ge 0 && test "${_free_space_bytes:?}" -ge 0; then
13051352
: # OK
@@ -1628,7 +1675,7 @@ is_substring()
16281675

16291676
replace_string_global()
16301677
{
1631-
printf '%s' "${1:?}" | sed -e "s@${2:?}@${3:?}@g" || return "${?}" # Note: pattern and replacement cannot contain @
1678+
printf '%s' "${1:?}" | sed -e "s@${2:?}@${3:?}@g" || return "${?}" # NOTE: pattern and replacement cannot contain @
16321679
}
16331680

16341681
replace_slash_with_at()
@@ -2346,7 +2393,7 @@ _timeout_exit_code_remapper()
23462393
;;
23472394
126) # COMMAND is found but cannot be invoked (126) - Example: missing execute permission
23482395
;;
2349-
127) # COMMAND cannot be found (127) - Note: this return value may even be used when timeout is unable to execute the COMMAND
2396+
127) # COMMAND cannot be found (127) - NOTE: this return value may even be used when timeout is unable to execute the COMMAND
23502397
ui_msg_empty_line
23512398
ui_warning 'timeout returned cmd NOT found (127)'
23522399
return 127

0 commit comments

Comments
 (0)