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

Commit f3d4ff3c authored by Bharath's avatar Bharath
Browse files

FP3: Allow to opt out of data wipe

Allow users to opt out of data wipe which is often
the case while upgrading.

Change-Id: Ia8eed077dd08ba30d84447f5a6c58cfd1c35e0b5
parent c0423b12
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -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,12 +102,18 @@ 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"
@@ -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