Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f231c82 authored by Bharath's avatar Bharath Committed by Rohit Sekhar
Browse files

FP4: Add data wipe check

parent 9f0e75c6
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
set -e
set -u

CLEAN_FLASH="true" # Control data wipe behavior. Default is "true".

# Target device info
PRODUCT="Fairphone 4"
PRODUCT_ID="FP4"
@@ -111,8 +113,11 @@ flash_device() {
  flash_image_ab_or_abort "${sn}" xbl_config "${IMAGES_DIR}/xbl_config.img"
  flash_image_ab_or_abort "${sn}" core_nhlos "${IMAGES_DIR}/core_nhlos.img"

if [ "${CLEAN_FLASH}" = "true" ]
then
  "$FASTBOOT_BIN" -s "${sn}" erase userdata
  "$FASTBOOT_BIN" -s "${sn}" erase metadata
fi

  "$FASTBOOT_BIN" -s "${sn}" --set-active=a

@@ -174,6 +179,31 @@ reboot_device() {
  echo ""
}

# 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 ***"
echo ""
@@ -188,6 +218,9 @@ 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