pkgs/nixfiles: make nixfiles-auto-install interactive
This commit is contained in:
parent
24b8e750b5
commit
71aa9f31a0
@ -2,17 +2,9 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
hostname=host${RANDOM}
|
hostname=""
|
||||||
|
|
||||||
echo "[I] Deploying with hostname ${hostname}"
|
|
||||||
|
|
||||||
device=""
|
device=""
|
||||||
for dev in "/dev/vda" "/dev/sda"; do
|
no_confirm=""
|
||||||
if [[ -b $dev ]]; then
|
|
||||||
device=$dev
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
@ -21,6 +13,15 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--device)
|
||||||
|
device=$2
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-confirm)
|
||||||
|
no_confirm=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "unknown option: $1"
|
echo "unknown option: $1"
|
||||||
exit 1
|
exit 1
|
||||||
@ -28,30 +29,75 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "[I] Formatting disk"
|
echo ""
|
||||||
|
echo " This is clerie's nixfiles auto install for new hosts"
|
||||||
|
echo " It will do dangerous things like format your disk"
|
||||||
|
echo " So be careful when using it"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [[ -z $no_confirm ]]; then
|
||||||
|
read -e -r -p "Continue?" confirm
|
||||||
|
echo "$confirm" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $hostname ]]; then
|
||||||
|
fallback_hostname="host${RANDOM}"
|
||||||
|
read -e -r -p "Hostname [$fallback_hostname]: " hostname
|
||||||
|
if [[ -z $hostname ]]; then
|
||||||
|
hostname=$fallback_hostname
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[I] Deploying with hostname ${hostname}"
|
||||||
|
|
||||||
if [[ -z $device ]]; then
|
if [[ -z $device ]]; then
|
||||||
echo "[E] No device to install to"
|
device="/dev/sda"
|
||||||
|
while true; do
|
||||||
|
read -e -r -p "Disk [$device]: " dev
|
||||||
|
if [[ -z $dev ]]; then
|
||||||
|
dev=$device
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -b $dev ]]; then
|
||||||
|
device=$dev
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "[E] Disk $dev does not exist"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[I] Deploying on disk ${device}"
|
||||||
|
|
||||||
|
if [[ -z $no_confirm ]]; then
|
||||||
|
read -e -r -p "Deploy host?" deploy
|
||||||
|
echo "$deploy" > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[I] Formatting disk"
|
||||||
|
|
||||||
|
if [[ ! -b $device ]]; then
|
||||||
|
echo "Disk $device does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[I] Using ${device}"
|
echo "[I] Using ${device}"
|
||||||
|
|
||||||
parted --script $device mklabel gpt
|
parted --script "$device" mklabel gpt
|
||||||
parted --script $device disk_set pmbr_boot on
|
parted --script "$device" disk_set pmbr_boot on
|
||||||
|
|
||||||
parted --script $device mkpart boot 0% 512M
|
parted --script "$device" mkpart boot 0% 512M
|
||||||
parted --script $device set 1 bios_grub on
|
parted --script "$device" set 1 bios_grub on
|
||||||
|
|
||||||
parted --script $device mkpart root 512M 100%
|
parted --script "$device" mkpart root 512M 100%
|
||||||
|
|
||||||
echo "[I] Creating file system"
|
echo "[I] Creating file system"
|
||||||
|
|
||||||
mkfs.ext4 -F ${device}2
|
mkfs.ext4 -F "${device}2"
|
||||||
|
|
||||||
echo "[I] Mount file system"
|
echo "[I] Mount file system"
|
||||||
|
|
||||||
mount ${device}2 /mnt
|
mount "${device}2" /mnt
|
||||||
|
|
||||||
echo "[I] Generate NixOS configuration"
|
echo "[I] Generate NixOS configuration"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user