diff options
author | Tyler Murphy <tylerm@tylerm.dev> | 2023-10-07 15:38:22 -0400 |
---|---|---|
committer | Tyler Murphy <tylerm@tylerm.dev> | 2023-10-07 15:38:22 -0400 |
commit | 80df8ba1b36bcac4905919d0ff012b7ae099769d (patch) | |
tree | 4ddd49cb63b42947a4fa0e738eafda32948e6da1 | |
parent | sway project script (diff) | |
download | dotfiles-guix-80df8ba1b36bcac4905919d0ff012b7ae099769d.tar.gz dotfiles-guix-80df8ba1b36bcac4905919d0ff012b7ae099769d.tar.bz2 dotfiles-guix-80df8ba1b36bcac4905919d0ff012b7ae099769d.zip |
guix-strap
-rwxr-xr-x | guix-strap/guix-crypt | 62 | ||||
-rwxr-xr-x | guix-strap/guix-env | 3 | ||||
-rwxr-xr-x | guix-strap/guix-log | 10 | ||||
-rwxr-xr-x | guix-strap/guix-partition | 79 | ||||
-rwxr-xr-x | guix-strap/guix-setup | 34 |
5 files changed, 188 insertions, 0 deletions
diff --git a/guix-strap/guix-crypt b/guix-strap/guix-crypt new file mode 100755 index 0000000..dd7c496 --- /dev/null +++ b/guix-strap/guix-crypt @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +source ./guix-log +source ./guix-env + +CRYPT_PARTITION="" +EFI_PARTITION="" +PASSWORD="" +PASSWORD_CONFIRM="" + +EVENT "Setting up disk encryption with luks" + +if [[ $DISK == sd* ]]; then + CRYPT_PARTITION="$DISK""2" + EFI_PARTITION="$DISK""1" +elif [[ $DISK == nvme** ]]; then + CRYPT_PARTITION="$DISK""p2" + EFI_PARTITION="$DISK""p1" +else + ERROR "Unsupported drive type, must be sata or nvme!" + exit 1 +fi + +get_password() { + read -s -p "LUKS password: " PASSWORD + read -s -p "Confirm password: " PASSWORD_CONFIRM + if [ "$PASSWORD" == "$CONFIRM_PASSWORD" ]; then + exit 0 + else + ERROR "Passwords do not match" + get_password + fi +} + +get_password + +EVENT "Setting up luks" + +cryptsetup luksFormat --type luks1 "$CRYPT_PARTITION" <<EOF +YES +$PASSWORD +$CONFIRM_PASSWORD +EOF + +EVENT "Opening cryptroot" + +cryptsetup open "$CRYPT_PARTITION" cryptroot <<EOF +$PASSWORD +EOF + +EVENT "Mounting cryptroot" + +mount /dev/mapper/cryptroot /mnt + +EVENT "Setting up EFI vfat" + +mkfs.vfat "-F32" "$EFI_PARTITION" + +EVENT "Successfully setup efi vfat and luks" + +echo "CRYPT_PARTITION=\"$CRYPT_PARTITION\"" > ./guix-env +echo "EFI_PARTITION=\"$EFI_PARTITION\"" > ./guix-env diff --git a/guix-strap/guix-env b/guix-strap/guix-env new file mode 100755 index 0000000..2319e8d --- /dev/null +++ b/guix-strap/guix-env @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +# added by scripts during runtime!!! diff --git a/guix-strap/guix-log b/guix-strap/guix-log new file mode 100755 index 0000000..c344415 --- /dev/null +++ b/guix-strap/guix-log @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +ERROR() { + >&2 printf "\x1b[91mError: \x1b[0m\x1b[98m$1\n" +} + +EVENT() { + printf "\x1b[95m>>> \x1b[0m\x1b[98m$1\n" +} + diff --git a/guix-strap/guix-partition b/guix-strap/guix-partition new file mode 100755 index 0000000..184ea96 --- /dev/null +++ b/guix-strap/guix-partition @@ -0,0 +1,79 @@ +#!/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" diff --git a/guix-strap/guix-setup b/guix-strap/guix-setup new file mode 100755 index 0000000..97870c3 --- /dev/null +++ b/guix-strap/guix-setup @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +welcome() { + cat<<"EOF" + ░░░ ░░░ + ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░ + ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░ + ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░ + ░▒▒▒▒░ ░░░░░░ + ▒▒▒▒▒ ░░░░░░ + ▒▒▒▒▒ ░░░░░ + ░▒▒▒▒▒ ░░░░░ + ▒▒▒▒▒ ░░░░░ + ▒▒▒▒▒ ░░░░░ + ░▒▒▒▒▒░░░░░ + ▒▒▒▒▒▒░░░ + ▒▒▒▒▒▒░ + ____ _ _ _____ __ ____ _ + / ___| | | |_ _\ \/ / / ___|| |_ _ __ __ _ _ __ + | | _| | | || | \ / \___ \| __| '__/ _` | '_ \ + | |_| | |_| || | / \ ___) | |_| | | (_| | |_) | + \____|\___/|___/_/\_\ |____/ \__|_| \__,_| .__/ + |_| +This script installs GNU Guix on your system + +https://www.gnu.org/software/guix/ +EOF + echo -n "Press return to continue..." + read -r ANSWER +} + +welcome +./guix-partition +./guix-setup |