dotfiles-guix/guix-strap/guix-partition

80 lines
1.1 KiB
Text
Raw Normal View History

2023-10-07 19:38:22 +00:00
#!/usr/bin/env bash
set -o emacs;
CONFIRM=""
DISK=""
source ./guix-log
source ./guix-env
EVENT "Partitioning disks"
confirm() {
if [ "$CONFIRM" == "y" ]; then
exit 0
fi
read -p "Are you sure: ($1)? [y/N] " CONFIRM
if [ "$CONFIRM" == "y" ]; then
exit 0
else
exit 1
fi
}
check_disk() {
lsblk $1 &> /dev/null || exit 1
FS=$(df $1 | tail -n 1 | awk '{print $1}')
if [ "$FS" == "none" ]; then
exit 0
else
exit 1
fi
}
get_disk() {
CONFIRM=""
read -ep "Enter disk (e.g. /dev/sda): " DISK
if [ ! -b "$DISK" ]; then
ERROR "$DISK: file does not exist"
get_disk
return
fi
(check_disk "$DISK");
if [ "$?" -ne 0 ]; then
ERROR "$DISK: not a valid disk"
get_disk
return
fi
(confirm "$DISK");
if [ "$?" -ne 0 ]; then
get_disk
fi
}
get_disk
EVENT "Partitioning disks with fdisk..."
fdisk "$DISK" <<EOF
g
n
+1GiB
t
EFI System
n
t
2
Linux Filesystem
w
EOF
echo "DISK=\"$DISK\"" >> ./guix-env
EVENT "Disks have been successfully partitioned on $DISK"