#!/bin/bash USAGE="" # shellcheck source=resteasy-helper.sh source "$(resteasy --exec-path)/resteasy-helper.sh" set -o errexit set -o nounset [[ $# -eq 1 ]] || die_with_usage "no device given" device="$1" [[ -b $device ]] || die "$device is not a block device" echo "WARNING: this will erase all data on $device." >&2 read -r -p "Continue? yes/[no]" yn >&2 [[ $yn == "yes" ]] || die "aborting" sgdisk \ --zap-all \ --clear \ --new=1:0:0 \ --change-name=1:resteasy \ --typecode=1:"$RESTEASY_TYPE_UUID" \ "$device" # the kernel needs some time to update partition information sleep 5 sgdisk --info=1 "$device" # note the '2p': this extract the second line of lsblk, which will correspond to # the first partition on the device partition_uuid=$(lsblk "$device" --noheadings --output=PARTUUID | sed --quiet 2p) [[ -n $partition_uuid ]] || die "cannot determine partition UUID after reformatting" mkfs.ext4 "/dev/disk/by-partuuid/$partition_uuid"