summaryrefslogtreecommitdiff
path: root/resteasy/libexec/resteasy-prepare-drive
blob: 6da4899f1db67a19df3d25f41d660247f7137d36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
USAGE="<block_device>"

# 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"