@@ -114,8 +114,9 @@ ui_msg_empty_line()
114114{
115115 if test " ${RECOVERY_OUTPUT:? } " = ' true' ; then
116116 _send_text_to_recovery ' '
117+ test " ${TEST_INSTALL:- false} " = ' false' || sleep 2> /dev/null ' 0.01'
117118 else
118- _print_text ' %s' ' '
119+ _print_text 1>&2 ' %s' ' '
119120 fi
120121}
121122
@@ -415,9 +416,15 @@ _disable_write_locks()
415416 test " ${DRY_RUN:? } " -lt 2 || return 1
416417
417418 if test -d ' /sys/kernel/security/sony_ric' ; then
418- ui_msg ' Disabling Sony RIC...' # Sony RIC may prevent you to remount the system partition as read-write
419+ # Sony RIC may prevent you to remount the system partition as read-write
420+ ui_msg ' Disabling Sony RIC...'
419421 printf ' %s\n' ' 0' 1> ' /sys/kernel/security/sony_ric/enable' || ui_warning ' Failed to disable Sony RIC'
420422 fi
423+ if test -n " ${VENDOR_PATH?} " && test -f " ${VENDOR_PATH:? } /bin/write_protect" ; then
424+ # Alcatel TCL Flip 2
425+ ui_msg ' Disabling write protect...'
426+ PATH=" ${PREVIOUS_PATH:? } :${PATH:? } " " ${VENDOR_PATH:? } /bin/write_protect" 0 || ui_warning ' Failed to disable write protect'
427+ fi
421428}
422429
423430_execute_system_remount ()
@@ -428,7 +435,7 @@ _execute_system_remount()
428435 # Use the system remount binary if available (this will save us many problems)
429436 if test -f " ${SYS_PATH:? } /bin/remount" ; then
430437 ui_msg ' Executing the remount binary...'
431- _remount_output=" $( " ${SYS_PATH:? } /bin/remount" 2>&1 ) " || ui_warning ' Failed to execute the remount binary'
438+ _remount_output=" $( PATH= " ${PREVIOUS_PATH :? } : ${PATH :? } " " ${SYS_PATH:? } /bin/remount" 2>&1 ) " || ui_warning ' Failed to execute the remount binary'
432439 ui_debug " ${_remount_output?} "
433440 case " ${_remount_output?} " in
434441 * ' reboot your device' * ) if test " ${IS_EMU:? } " = ' true' ; then exit 252; else exit 251; fi ;;
@@ -891,16 +898,8 @@ reset_appops_if_needed()
891898 fi
892899}
893900
894- _write_test ()
901+ _write_test_helper ()
895902{
896- test " ${DRY_RUN:? } " -lt 2 || return 0
897-
898- test -d " ${1:? } " || {
899- ui_warning " Missing folder => ${1?} "
900- mkdir -p " ${1:? } " || return 4
901- set_perm 0 0 0755 " ${1:? } "
902- }
903-
904903 touch -- " ${1:? } /write-test-file.dat" || return 1
905904 if test " ${FIRST_INSTALLATION:? } " = ' true' ; then
906905 printf ' %512s' ' ' 1> " ${1:? } /write-test-file.dat" || return 2
@@ -909,12 +908,17 @@ _write_test()
909908 return 0
910909}
911910
912- _write_test_cleaning ()
911+ _write_test ()
913912{
913+ local _folder _status
914914 test " ${DRY_RUN:? } " -lt 2 || return 0
915915
916- rm -f -- " ${1:? } /write-test-file.dat" || return 1
917- return 0
916+ _status=0
917+ if test -d " ${1:? } /etc" ; then _folder=" ${1:? } /etc" ; else _folder=" ${1:? } " ; fi
918+ _write_test_helper " ${_folder:? } " || _status=" ${?} "
919+
920+ rm -f -- " ${_folder:? } /write-test-file.dat" || :
921+ return " ${_status:? } "
918922}
919923
920924_detect_architectures ()
@@ -1166,7 +1170,7 @@ initialize()
11661170
11671171 if test " ${DRY_RUN:? } " -gt 0; then
11681172 ui_warning " DRY RUN mode ${DRY_RUN?} enabled. No files on your device will be modified!!!"
1169- sleep 2> /dev/null ' 0.02 ' || : # Wait some time otherwise ui_debug may appear before the previous ui_warning
1173+ sleep 2> /dev/null ' 0.01 ' || : # Wait some time otherwise ui_debug may appear before the previous ui_warning
11701174 ui_debug ' '
11711175 fi
11721176
@@ -1334,6 +1338,26 @@ initialize()
13341338 readonly SETUP_TYPE
13351339 export SETUP_TYPE
13361340
1341+ if mount_partition_if_possible ' vendor' " ${SLOT_SUFFIX: +vendor}${SLOT_SUFFIX-}${NL:? } vendor${NL:? } " ; then
1342+ VENDOR_PATH=" ${LAST_MOUNTPOINT:? } "
1343+ UNMOUNT_VENDOR=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1344+ fi
1345+ if mount_partition_if_possible ' product' " ${SLOT_SUFFIX: +product}${SLOT_SUFFIX-}${NL:? } product${NL:? } " ; then
1346+ PRODUCT_PATH=" ${LAST_MOUNTPOINT:? } "
1347+ UNMOUNT_PRODUCT=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1348+ fi
1349+ if mount_partition_if_possible ' system_ext' " ${SLOT_SUFFIX: +system_ext}${SLOT_SUFFIX-}${NL:? } system_ext${NL:? } " ; then
1350+ SYS_EXT_PATH=" ${LAST_MOUNTPOINT:? } "
1351+ UNMOUNT_SYS_EXT=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1352+ fi
1353+ if mount_partition_if_possible ' odm' " ${SLOT_SUFFIX: +odm}${SLOT_SUFFIX-}${NL:? } odm${NL:? } " ; then
1354+ ODM_PATH=" ${LAST_MOUNTPOINT:? } "
1355+ UNMOUNT_ODM=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1356+ fi
1357+
1358+ LD_LIBRARY_PATH=" ${LD_LIBRARY_PATH-}${LD_LIBRARY_PATH: +: }${VENDOR_PATH:-/ vendor} /lib64:${SYS_PATH:? } /lib64:${VENDOR_PATH:-/ vendor} /lib:${SYS_PATH:? } /lib"
1359+ export LD_LIBRARY_PATH
1360+
13371361 _disable_write_locks
13381362 _execute_system_remount
13391363
@@ -1354,25 +1378,17 @@ initialize()
13541378 ui_error " Remounting '${SYS_MOUNTPOINT?} ' failed!!!" 30
13551379 }
13561380
1357- if mount_partition_if_possible ' vendor' " ${SLOT_SUFFIX: +vendor}${SLOT_SUFFIX-}${NL:? } vendor${NL:? } " ; then
1358- VENDOR_PATH=" ${LAST_MOUNTPOINT:? } "
1359- UNMOUNT_VENDOR=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1360- remount_read_write_if_possible " ${LAST_MOUNTPOINT:? } " false && VENDOR_RW=' true'
1381+ if test -n " ${VENDOR_PATH?} " ; then
1382+ remount_read_write_if_possible " ${VENDOR_PATH:? } " false && VENDOR_RW=' true'
13611383 fi
1362- if mount_partition_if_possible ' product' " ${SLOT_SUFFIX: +product}${SLOT_SUFFIX-}${NL:? } product${NL:? } " ; then
1363- PRODUCT_PATH=" ${LAST_MOUNTPOINT:? } "
1364- UNMOUNT_PRODUCT=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1365- remount_read_write_if_possible " ${LAST_MOUNTPOINT:? } " false && PRODUCT_RW=' true'
1384+ if test -n " ${PRODUCT_PATH?} " ; then
1385+ remount_read_write_if_possible " ${PRODUCT_PATH:? } " false && PRODUCT_RW=' true'
13661386 fi
1367- if mount_partition_if_possible ' system_ext' " ${SLOT_SUFFIX: +system_ext}${SLOT_SUFFIX-}${NL:? } system_ext${NL:? } " ; then
1368- SYS_EXT_PATH=" ${LAST_MOUNTPOINT:? } "
1369- UNMOUNT_SYS_EXT=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1370- remount_read_write_if_possible " ${LAST_MOUNTPOINT:? } " false && SYS_EXT_RW=' true'
1387+ if test -n " ${SYS_EXT_PATH?} " ; then
1388+ remount_read_write_if_possible " ${SYS_EXT_PATH:? } " false && SYS_EXT_RW=' true'
13711389 fi
1372- if mount_partition_if_possible ' odm' " ${SLOT_SUFFIX: +odm}${SLOT_SUFFIX-}${NL:? } odm${NL:? } " ; then
1373- ODM_PATH=" ${LAST_MOUNTPOINT:? } "
1374- UNMOUNT_ODM=" ${LAST_PARTITION_MUST_BE_UNMOUNTED:? } "
1375- # remount_read_write_if_possible "${LAST_MOUNTPOINT:?}" false && ODM_RW='true'
1390+ if test -n " ${ODM_PATH?} " ; then
1391+ : # remount_read_write_if_possible "${ODM_PATH:?}" false && ODM_RW='true'
13761392 fi
13771393 readonly VENDOR_PATH PRODUCT_PATH SYS_EXT_PATH ODM_PATH
13781394 export VENDOR_PATH PRODUCT_PATH SYS_EXT_PATH ODM_PATH
@@ -1428,6 +1444,12 @@ initialize()
14281444 ui_error " Unsupported CPU, ABI list => $( printf ' %s\n' " ${_raw_arch_list?} " | LC_ALL=C tr -s -- ' ,' || true) "
14291445 fi
14301446
1447+ if test " ${SETUP_TYPE:? } " = ' install' ; then
1448+ ui_msg ' Extracting...'
1449+ custom_package_extract_dir ' origin' " ${TMP_PATH:? } "
1450+ mkdir -p -- " ${TMP_PATH:? } /files/etc" || ui_error " Failed to create the dir '${TMP_PATH?} /files/etc'"
1451+ fi
1452+
14311453 unset LAST_MOUNTPOINT
14321454 unset LAST_PARTITION_MUST_BE_UNMOUNTED
14331455 unset CURRENTLY_ROLLING_BACK
@@ -1459,8 +1481,7 @@ clean_previous_installations()
14591481 _initial_free_space=" $( get_free_disk_space_of_partition " ${SYS_PATH:? } " ) " || _initial_free_space=' -1'
14601482 test " ${_initial_free_space:? } " ! = 0 || ui_error " There is NO free space on '${SYS_PATH?} ' ($( get_file_system " ${SYS_PATH?} " || :) )" 31
14611483
1462- _write_test " ${SYS_PATH:? } /etc" || ui_error " Something is wrong because '${SYS_PATH?} ' ($( get_file_system " ${SYS_PATH?} " || :) ) is NOT really writable!!! Return code: ${?} " 30
1463- _write_test_cleaning " ${SYS_PATH:? } /etc" || ui_error ' Failed to delete the test file'
1484+ _write_test " ${SYS_PATH:? } " || ui_error " Something is wrong because '${SYS_PATH?} ' ($( get_file_system " ${SYS_PATH?} " || :) ) is NOT really writable!!! Return code: ${?} " 30
14641485 else
14651486 ui_msg ' Uninstalling...'
14661487 fi
@@ -1535,36 +1556,35 @@ prepare_installation()
15351556
15361557 ui_msg ' Preparing installation...'
15371558 _need_newline=' false'
1538- sleep ' 0.1 ' # It avoid the following output to be printed interleaved with the previous output
1559+ sleep 2> /dev/null ' 0.01 ' # It avoid the following output to be printed interleaved with the previous output
15391560
1540- if test " ${API:? } " -ge 29; then # Android 10+
1541- _need_newline=' true'
1542- replace_permission_placeholders ' ACCESS_BACKGROUND_LOCATION' ' true'
1561+ if test " ${API:? } " -ge 23; then
1562+ if test " ${API:? } " -ge 29; then # Android 10+
1563+ _need_newline=' true'
1564+ replace_permission_placeholders ' ACCESS_BACKGROUND_LOCATION' ' true'
15431565
1544- if test " ${API:? } " -ge 31; then # Android 12+
1545- replace_permission_placeholders ' BLUETOOTH_ADVERTISE'
1546- replace_permission_placeholders ' BLUETOOTH_CONNECT'
1547- replace_permission_placeholders ' BLUETOOTH_SCAN'
1566+ if test " ${API:? } " -ge 31; then # Android 12+
1567+ replace_permission_placeholders ' BLUETOOTH_ADVERTISE'
1568+ replace_permission_placeholders ' BLUETOOTH_CONNECT'
1569+ replace_permission_placeholders ' BLUETOOTH_SCAN'
15481570
1549- if test " ${API:? } " -ge 33; then # Android 13+
1550- replace_permission_placeholders ' POST_NOTIFICATIONS'
1571+ if test " ${API:? } " -ge 33; then # Android 13+
1572+ replace_permission_placeholders ' POST_NOTIFICATIONS'
1573+ fi
15511574 fi
15521575 fi
1553- fi
15541576
1555- if test " ${FAKE_SIGN_PERMISSION:? } " = ' true' ; then
1556- _need_newline=' true'
1557- replace_permission_placeholders ' FAKE_PACKAGE_SIGNATURE'
1577+ if test " ${FAKE_SIGN_PERMISSION:? } " = ' true' ; then
1578+ _need_newline=' true'
1579+ replace_permission_placeholders ' FAKE_PACKAGE_SIGNATURE'
1580+ fi
15581581 fi
15591582
15601583 test " ${_need_newline:? } " = ' false' || ui_debug ' '
15611584
15621585 if test " ${API} " -lt 23; then
15631586 delete_temp " files/etc/default-permissions"
15641587 fi
1565- if test " ${API:? } " -lt 21; then
1566- delete_temp " files/etc/sysconfig"
1567- fi
15681588
15691589 if test " ${PRIVAPP_DIRNAME:? } " ! = ' priv-app' && test -e " ${TMP_PATH:? } /files/priv-app" ; then
15701590 ui_debug " Merging priv-app folder with ${PRIVAPP_DIRNAME?} folder..."
@@ -1598,8 +1618,10 @@ prepare_installation()
15981618 delete_temp " files/etc/zips"
15991619 create_dir " ${TMP_PATH:? } /files/etc/zips"
16001620 {
1621+ # REUSE-IgnoreStart
16011622 echo ' # SPDX-FileCopyrightText: NONE'
16021623 echo ' # SPDX-License-Identifier: CC0-1.0'
1624+ # REUSE-IgnoreEnd
16031625 echo ' '
16041626 echo ' install.destination=system'
16051627 echo " install.build.type=${BUILD_TYPE:? } "
@@ -1873,7 +1895,9 @@ verify_disk_space()
18731895{
18741896 local _needed_space_bytes _free_space_bytes
18751897
1876- if _needed_space_bytes=" $( get_disk_space_usage_of_file_or_folder " ${TMP_PATH:? } /files" ) " && test -n " ${_needed_space_bytes?} " ; then
1898+ ui_msg_empty_line
1899+
1900+ if test -d " ${TMP_PATH:? } /files" && _needed_space_bytes=" $( get_disk_space_usage_of_file_or_folder " ${TMP_PATH:? } /files" ) " && test -n " ${_needed_space_bytes?} " ; then
18771901 ui_msg " Disk space required: $( convert_bytes_to_mb " ${_needed_space_bytes:? } " || :) MB"
18781902 else
18791903 _needed_space_bytes=' -1'
@@ -1890,7 +1914,6 @@ verify_disk_space()
18901914 if test " ${_needed_space_bytes:? } " -ge 0 && test " ${_free_space_bytes:? } " -ge 0; then
18911915 : # OK
18921916 else
1893- ui_msg_empty_line
18941917 ui_warning ' Unable to verify needed space, continuing anyway'
18951918 return 0
18961919 fi
@@ -1951,25 +1974,22 @@ perform_secure_copy_to_device()
19511974
19521975perform_installation ()
19531976{
1954- ui_msg_empty_line
1955-
19561977 if ! verify_disk_space " ${DEST_PATH:? } " ; then
19571978 ui_msg_empty_line
19581979 ui_warning " There is NOT enough free space available, but let's try anyway"
19591980 fi
19601981
19611982 ui_msg_empty_line
19621983
1963- test " ${DRY_RUN:? } " -eq 0 || return
1964-
19651984 ui_msg ' Installing...'
1985+ test " ${DRY_RUN:? } " -eq 0 || return
19661986
19671987 if test ! -d " ${SYS_PATH:? } /etc/zips" ; then
19681988 mkdir -p " ${SYS_PATH:? } /etc/zips" || ui_error " Failed to create the dir '${SYS_PATH:? } /etc/zips'"
19691989 set_perm 0 0 0750 " ${SYS_PATH:? } /etc/zips"
19701990 fi
1971-
19721991 set_perm 0 0 0640 " ${TMP_PATH:? } /files/etc/zips/${MODULE_ID:? } .prop"
1992+
19731993 perform_secure_copy_to_device ' etc/zips'
19741994 perform_secure_copy_to_device ' etc/permissions'
19751995
@@ -2147,6 +2167,7 @@ add_line_in_file_after_string()
21472167
21482168replace_line_in_file_with_file ()
21492169{ # $1 => File to process $2 => Line to replace $3 => File to read for replacement text
2170+ test -f " ${1:? } " || ui_error " Failed to replace a line in a file because the file is missing => '$1 '" 92
21502171 sed -i -e " /${2:? } /r ${3:? } " -- " ${1:? } " || ui_error " Failed to replace (1) a line in the file => '$1 '" 92
21512172 sed -i -e " /${2:? } /d" -- " ${1:? } " || ui_error " Failed to replace (2) a line in the file => '$1 '" 92
21522173}
@@ -2267,9 +2288,9 @@ verify_sha1_hash()
22672288# File / folder related functions
22682289create_dir ()
22692290{ # Ensure dir exists
2270- test -d " $1 " && return
2271- mkdir -p " $1 " || ui_error " Failed to create the dir '$1 '" 97
2272- set_perm 0 0 0755 " $1 "
2291+ test ! -d " ${1 :? } " || return 0
2292+ mkdir -p -- " ${1 :? } " || ui_error " Failed to create the dir '${1?} '" 97
2293+ set_perm 0 0 0755 " ${1 :? } "
22732294}
22742295
22752296copy_dir_content ()
@@ -2442,10 +2463,20 @@ string_split()
24422463 printf ' %s' " ${1:? } " | cut -d ' |' -sf " ${2:? } " || return " ${?} "
24432464}
24442465
2445- set_filename_of_base_sysconfig_xml ()
2466+ setup_sysconfig ()
24462467{
2447- BASE_SYSCONFIG_XML=" etc/sysconfig/${1:? } "
2448- test -e " ${TMP_PATH:? } /files/${BASE_SYSCONFIG_XML:? } " || ui_error " You have set the wrong filename for the base sysconfig XML => ${BASE_SYSCONFIG_XML?} "
2468+ test " ${API:? } " -ge 21 || return
2469+
2470+ ui_debug " Enabling sysconfig: ${1:? } .xml"
2471+ create_dir " ${TMP_PATH:? } /files/etc/sysconfig" || ui_error " Failed to create the sysconfig folder"
2472+ move_rename_file " ${TMP_PATH:? } /origin/etc/sysconfig/${1:? } .xml" " ${TMP_PATH:? } /files/etc/sysconfig/${1:? } .xml" || ui_error " Failed to setup the sysconfig => '${1?} .xml'"
2473+ }
2474+
2475+ set_base_sysconfig ()
2476+ {
2477+ test " ${API:? } " -ge 21 || return
2478+ BASE_SYSCONFIG_XML=" etc/sysconfig/${1:? } .xml"
2479+ test -f " ${TMP_PATH:? } /files/${BASE_SYSCONFIG_XML:? } " || ui_error " You have set the wrong filename for the base sysconfig XML => ${BASE_SYSCONFIG_XML?} "
24492480}
24502481
24512482# @description Configure an app for later installation.
@@ -2517,7 +2548,7 @@ setup_app()
25172548 move_rename_file " ${TMP_PATH:? } /origin/etc/default-permissions/default-permissions-${_filename:? } .xml" " ${TMP_PATH:? } /files/etc/default-permissions/default-permissions-${_output_name:? } .xml" || ui_error " Failed to setup the default permissions xml of '${_vanity_name?} '"
25182549 _installed_file_list=" ${_installed_file_list?} |etc/default-permissions/default-permissions-${_output_name:? } .xml"
25192550 fi
2520- if test " ${_url_handling:? } " ! = ' false' && test " ${CURRENTLY_ROLLING_BACK:- false} " ! = ' true' ; then
2551+ if test " ${API :? } " -ge 21 && test " ${ _url_handling:? }" ! = ' false' && test " ${CURRENTLY_ROLLING_BACK:- false} " ! = ' true' ; then
25212552 test -n " ${BASE_SYSCONFIG_XML?} " || ui_error ' You have NOT set the filename of the base sysconfig XML'
25222553 add_line_in_file_after_string " ${TMP_PATH:? } /files/${BASE_SYSCONFIG_XML:? } " ' <!-- %CUSTOM_APP_LINKS-START% -->' " <app-link package=\" ${_internal_name:? } \" />" || ui_error " Failed to auto-enable URL handling for '${_vanity_name?} '"
25232554 fi
@@ -2607,10 +2638,18 @@ setup_util()
26072638{
26082639 ui_msg " Enabling utility: ${2?} "
26092640
2610- mkdir -p " ${TMP_PATH:? } /files/bin" || ui_error " Failed to create the folder for '${2?} '"
2641+ create_dir " ${TMP_PATH:? } /files/bin" || ui_error " Failed to create the folder for '${2?} '"
26112642 move_rename_file " ${TMP_PATH:? } /origin/bin/${1:? } .sh" " ${TMP_PATH:? } /files/bin/${1:? } " || ui_error " Failed to setup the util => '${2?} '"
26122643}
26132644
2645+ setup_xml ()
2646+ {
2647+ ui_debug " Enabling xml: ${2:? } /${1:? } .xml"
2648+
2649+ create_dir " ${TMP_PATH:? } /files/etc/${2:? } " || ui_error " Failed to create the folder => '${2?} '"
2650+ move_rename_file " ${TMP_PATH:? } /origin/etc/${2:? } /${1:? } .xml" " ${TMP_PATH:? } /files/etc/${2:? } /${1:? } .xml" || ui_error " Failed to setup the xml => '${2?} /${1?} .xml'"
2651+ }
2652+
26142653list_files ()
26152654{ # $1 => Folder to scan $2 => Prefix to remove
26162655 test -d " $1 " || return
0 commit comments