Skip to content

Commit

Permalink
Add a wiping option to the installer
Browse files Browse the repository at this point in the history
When running Ghaf on a target device and also trying to boot from an SSD
there is a conflick in the boot, as to which target image will be run.
for that reason the insstaller now has an option to wipe the installed
ghaf image from the DUT.

Normal installation (wipe and install)remains:
`sudo ghaf-installer`

To only wipe the system run:
`sudo ghaf-installer -w`

Signed-off-by: Brian McGillion <[email protected]>
  • Loading branch information
brianmcgillion committed Aug 28, 2024
1 parent ec9377d commit 3105ca4
Showing 1 changed file with 59 additions and 31 deletions.
90 changes: 59 additions & 31 deletions packages/installer/ghaf-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3105ca4

Please sign in to comment.