diff --git a/flash_FP3_factory.sh b/flash_FP3_factory.sh index 09e9eefa92ea0b9403be593620975e62517ac6f6..59669b042fd426efa5e3abf6e1bdac96e6a61663 100755 --- a/flash_FP3_factory.sh +++ b/flash_FP3_factory.sh @@ -16,6 +16,8 @@ set -e set -u +CLEAN_FLASH="true" # Control data wipe behavior. Default is "true". + # Target device info PRODUCT="Fairphone 3" PRODUCT_ID="FP3" @@ -100,14 +102,20 @@ flash_device() { flash_image_ab_or_abort "${sn}" system "${IMAGES_DIR}/system.img" flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" flash_image_ab_or_abort "${sn}" vendor "${IMAGES_DIR}/vendor.img" - flash_image_or_abort "${sn}" userdata "${IMAGES_DIR}/userdata.img" flash_image_ab_or_abort "${sn}" mdtp "${IMAGES_DIR}/mdtp.img" flash_image_ab_or_abort "${sn}" lksecapp "${IMAGES_DIR}/lksecapp.img" flash_image_ab_or_abort "${sn}" cmnlib "${IMAGES_DIR}/cmnlib.img" flash_image_ab_or_abort "${sn}" cmnlib64 "${IMAGES_DIR}/cmnlib64.img" flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img" + + + if [ "${CLEAN_FLASH}" = "true" ] + then + flash_image_or_abort "${sn}" userdata "${IMAGES_DIR}/userdata.img" + fi + $FASTBOOT_BIN -s "${sn}" --set-active=a - + echo "INFO: Locking bootloader" "${FASTBOOT_BIN}" -s "${sn}" oem lock echo @@ -167,6 +175,30 @@ os_checks() { esac } +# Warn about data wipe, and ask for confirmation +data_wipe_check() { + if [ "${CLEAN_FLASH}" = "true" ] + then + echo "" + echo "WARNING: Flashing this image wipes all user data and settings on the phone." + echo " Are you sure you want to wipe data and continue?" + echo "" + # Read user's input + read -rp " Type \"Yes\" (case sensitive) and press enter to wipe data and continue. Else, just press enter: " a + echo "" + if [ "_${a:-"No"}" != '_Yes' ] + # NOTE: $a is being set by the read command above, + # so the check for a to be set is mostly redundant + then + echo "WARNING: You DID NOT type \"Yes\", proceeding without data wipe." + echo "" + CLEAN_FLASH="false" + else + echo "WARNING: You typed \"Yes\", proceeding with data wipe." + CLEAN_FLASH="true" + fi + fi +} echo "" echo "*** ${PRODUCT} flashing script ***" @@ -182,5 +214,8 @@ os_checks # If only one device is found $sn will store its serial number find_device +# Call function to look for data wipe check +data_wipe_check + # Flash the device flash_device