From 33a7e1524d9134dab37e1ba812e0526a7fd72435 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Thu, 14 Sep 2023 13:36:03 -0400 Subject: [PATCH] preparing deploy script --- deploy.sh | 67 +++++++++++++++++++ .../deploy-templates/HostTemplate.scm | 19 ++++++ .../HostTemplateEncrypted.scm | 24 +++++++ 3 files changed, 110 insertions(+) create mode 100755 deploy.sh create mode 100644 modules/ryan-config/deploy-templates/HostTemplate.scm create mode 100644 modules/ryan-config/deploy-templates/HostTemplateEncrypted.scm diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..2d73d9b --- /dev/null +++ b/deploy.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +gather_env() { + # Gather needed information + echo -n "Type 'e' for encrypted or 'd' for decrypted install: " + read install_type + + echo -n "Type system hostname: " + read install_hostname + + echo -n "Type device file for ROOT data: " + read root_dev + + echo -n "Type device file for BOOT data: " + read boot_dev + + echo -n "Type device file for SWAP: " + read swap_dev + +} + +copy_and_prepare() { + # Associate devs with uuids + root_uuid=`blkid $root_dev | awk -F\" '{print $2}'` + boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'` + swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'` + # Let's a go! + echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)" + echo -n "Proceed? (y/n): " + read install_choice + + if [ "$install_choice" != "y" ] + then + echo "Bailing!" + exit 1 + fi + + # We are installing! + # Copy template to root of repo + if [ "$install_type" == "e" ] + then + cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted.scm ./$install_hostname.scm + elif [ "$install_type" == "d" ] + then + cp ./modules/ryan-config/deploy-templates/HostTemplate.scm ./$install_hostname.scm + else + echo "Invalid install type (not d or e), bailing!" + exit 1 + fi + + # Correct the information + sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm + sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm + sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm + sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm + + # Install! + echo "Mounting /gnu/store to destination disk..." + herd start cow-store /mnt + + echo "Beginning install!" + guix time-machine -C ./channels.scm -- system -L ./modules --substitute-urls='https://bordeaux.guix.gnu.org https://ci.guix.gnu.org https://substitutes.nonguix.org' init $install_hostname.scm /mnt + +} + +gather_env +copy_and_prepare diff --git a/modules/ryan-config/deploy-templates/HostTemplate.scm b/modules/ryan-config/deploy-templates/HostTemplate.scm new file mode 100644 index 0000000..9718c51 --- /dev/null +++ b/modules/ryan-config/deploy-templates/HostTemplate.scm @@ -0,0 +1,19 @@ +(use-modules (ryan-config base-system) + (gnu)) + +(operating-system + (inherit base-operating-system) + (host-name "ChangeMe_HOST") + (file-systems (cons* (file-system + (mount-point "/") + (device (uuid "ChangeMe_ROOT" + 'ext4)) + (type "ext4")) + (file-system + (mount-point "/boot/efi") + (device (uuid "ChangeMe_BOOTEFI" + 'fat32)) + (type "vfat")) %base-file-systems)) + (swap-devices + (list + (swap-space (target (uuid "ChangeMe_SWAP")))))) diff --git a/modules/ryan-config/deploy-templates/HostTemplateEncrypted.scm b/modules/ryan-config/deploy-templates/HostTemplateEncrypted.scm new file mode 100644 index 0000000..5d74aaa --- /dev/null +++ b/modules/ryan-config/deploy-templates/HostTemplateEncrypted.scm @@ -0,0 +1,24 @@ +(use-modules (ryan-config base-system) + (gnu)) + +(operating-system + (inherit base-operating-system) + (host-name "ChangeMe_HOST") + (mapped-devices (list (mapped-device + (source (uuid + "ChangeMe_ROOT")) + (target "sysroot") + (type luks-device-mapping)))) + (file-systems (cons* (file-system + (mount-point "/") + (device "/dev/mapper/sysroot") + (type "ext4") + (dependencies mapped-devices)) + (file-system + (mount-point "/boot/efi") + (device (uuid "ChangeMe_BOOTEFI" + 'fat32)) + (type "vfat")) %base-file-systems)) + (swap-devices + (list + (swap-space (target (uuid "ChangeMe_SWAP"))))))