diff --git a/packages/installer/ghaf-installer.sh b/packages/installer/ghaf-installer.sh index b272fa170..4b5f693c0 100755 --- a/packages/installer/ghaf-installer.sh +++ b/packages/installer/ghaf-installer.sh @@ -3,16 +3,36 @@ # SPDX-License-Identifier: Apache-2.0 if [ "$EUID" -ne 0 ]; then - echo "Please run as root" + echo "Please run as root" exit fi # Make sure $IMG_PATH env is set if [ -z "$IMG_PATH" ]; then - echo "IMG_PATH is not set!" - exit + echo "IMG_PATH is not set!" + exit fi +usage() { + echo " " + echo "Usage: $(basename "$0") [-w]" + echo " -w Wipe only" + exit 1 +} + +WIPE_ONLY=false + +while getopts "w" opt; do + case $opt in + w) + WIPE_ONLY=true + ;; + ?) + usage + ;; + esac +done + clear cat <<"EOF" @@ -33,45 +53,46 @@ EOF echo "Welcome to Ghaf installer!" -echo "To install image choose path to the device on which image will be installed." +echo "To install image or wipe installed image choose path to the device." hwinfo --disk --short while true; do - read -r -p "Device name [e.g. /dev/nvme0n1]: " DEVICE_NAME - - if [ ! -d "/sys/block/$(basename "$DEVICE_NAME")" ]; then - echo "Device not found!" - continue - fi - - # Check if removable - if [ "$(cat "/sys/block/$(basename "$DEVICE_NAME")/removable")" != "0" ]; then - read -r -p "Device provided is removable, do you want to continue? [y/N] " response - case "$response" in - [yY][eE][sS]|[yY]) - break - ;; - *) - continue - ;; - esac - fi - - break + read -r -p "Device name [e.g. /dev/nvme0n1]: " DEVICE_NAME + + if [ ! -d "/sys/block/$(basename "$DEVICE_NAME")" ]; then + echo "Device not found!" + continue + fi + + # Check if removable + if [ "$(cat "/sys/block/$(basename "$DEVICE_NAME")/removable")" != "0" ]; then + read -r -p "Device provided is removable, do you want to continue? [y/N] " response + case "$response" in + [yY][eE][sS] | [yY]) + break + ;; + *) + continue + ;; + esac + fi + + break done -echo "Installing Ghaf on $DEVICE_NAME" +echo "Installing/Deleting Ghaf on $DEVICE_NAME" read -r -p 'Do you want to continue? [y/N] ' response case "$response" in - [yY][eE][sS]|[yY]);; - *) - echo "Exiting..." - exit - ;; +[yY][eE][sS] | [yY]) ;; +*) + echo "Exiting..." + exit + ;; esac +echo "Wiping device..." # Wipe any possible ZFS leftovers from previous installations # Set sector size to 512 bytes SECTOR=512 @@ -83,6 +104,13 @@ SECTORS=$(blockdev --getsz "$DEVICE_NAME") dd if=/dev/zero of="$DEVICE_NAME" bs="$SECTOR" count="$MIB_TO_SECTORS" conv=fsync status=none # Wipe last 10MiB of disk dd if=/dev/zero of="$DEVICE_NAME" bs="$SECTOR" count="$MIB_TO_SECTORS" seek="$((SECTORS - MIB_TO_SECTORS))" conv=fsync status=none +echo "Wipe done." + +if [ "$WIPE_ONLY" = true ]; then + echo "Wipe only option selected. Exiting..." + echo "Please remove the installation media and reboot" + exit +fi echo "Installing..." zstdcat "$IMG_PATH" | dd of="$DEVICE_NAME" bs=32M status=progress