deploy.sh
13038d117b517c11271a4a3c1d2d4fd129893d0a
· 3.7 KB · 113 lines
raw
| 1 | #!/run/current-system/profile/bin/bash |
| 2 | |
| 3 | gather_env() { |
| 4 | # Gather needed information |
| 5 | echo -n "Type 'eb' for encrypted w/ boot, 'en' for encrypted w/o boot, or 'd' for decrypted install: " |
| 6 | read install_type |
| 7 | |
| 8 | echo -n "Type system hostname: " |
| 9 | read install_hostname |
| 10 | |
| 11 | echo -n "Type device file for ROOT data: " |
| 12 | read root_dev |
| 13 | |
| 14 | echo -n "Type device file for BOOT data: " |
| 15 | read boot_dev |
| 16 | |
| 17 | echo -n "Type device file for SWAP: " |
| 18 | read swap_dev |
| 19 | |
| 20 | echo -n "Add local device on network as substitute server? (y/n): " |
| 21 | read add_local_sub |
| 22 | if [ "$add_local_sub" == "y" ] |
| 23 | then |
| 24 | echo -n "Enter IP address of server: " |
| 25 | read substitute_ip |
| 26 | fi |
| 27 | } |
| 28 | |
| 29 | copy_and_prepare() { |
| 30 | # Associate devs with uuids |
| 31 | root_uuid=`blkid $root_dev | awk -F\" '{print $2}'` |
| 32 | boot_uuid=`blkid $boot_dev | awk -F\" '{print $2}'` |
| 33 | swap_uuid=`blkid $swap_dev | awk -F\" '{print $2}'` |
| 34 | # Let's a go! |
| 35 | echo "Information gathered. Deploying Guix on $root_dev ($root_uuid) with boot on $boot_dev ($boot_uuid) and swap on $swap_dev ($swap_uuid)" |
| 36 | echo -n "Proceed? (y/n): " |
| 37 | read install_choice |
| 38 | |
| 39 | if [ "$install_choice" != "y" ] |
| 40 | then |
| 41 | echo "Bailing!" |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | # We are installing! |
| 46 | # Copy template to root of repo |
| 47 | if [ "$install_type" == "eb" ] |
| 48 | then |
| 49 | cp ./modules/ryan-config/deploy-templates/HostTemplateEncrypted ./$install_hostname.scm |
| 50 | elif [ "$install_type" == "d" ] |
| 51 | then |
| 52 | cp ./modules/ryan-config/deploy-templates/HostTemplate ./$install_hostname.scm |
| 53 | else |
| 54 | echo "Invalid install type (not eb, en, or d), bailing!" |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
| 58 | # Correct the information |
| 59 | sed -i "s/ChangeMe_ROOT/$root_uuid/" ./$install_hostname.scm |
| 60 | sed -i "s/ChangeMe_BOOTEFI/$boot_uuid/" ./$install_hostname.scm |
| 61 | sed -i "s/ChangeMe_SWAP/$swap_uuid/" ./$install_hostname.scm |
| 62 | sed -i "s/ChangeMe_HOST/$install_hostname/" ./$install_hostname.scm |
| 63 | |
| 64 | # Install! |
| 65 | echo "Mounting /gnu/store to destination disk..." |
| 66 | herd start cow-store /mnt |
| 67 | |
| 68 | # Install the non-guix signing keys |
| 69 | echo "Installing non-guix signing keys for substitutes..." |
| 70 | curl -o sign-key.pub https://substitutes.nonguix.org/signing-key.pub |
| 71 | guix archive --authorize < sign-key.pub |
| 72 | |
| 73 | if [ "$add_local_sub" == "y" ] |
| 74 | then |
| 75 | echo "Installing local substitute server's signing keys" |
| 76 | curl -o local-sign.pub http://$substitute_ip/signing-key.pub |
| 77 | guix archive --authorize < local-sign.pub |
| 78 | fi |
| 79 | } |
| 80 | |
| 81 | install_system() { |
| 82 | echo "Beginning install!" |
| 83 | if [ "$add_local_sub" == "y"] |
| 84 | then |
| 85 | guix time-machine -C ./channels.scm -- system -L ./modules --substitute-urls="http://$substitute_ip https://substitutes.nonguix.org https://bordeaux.guix.gnu.org https://ci.guix.gnu.org" init $install_hostname.scm /mnt |
| 86 | else |
| 87 | guix time-machine -C ./channels.scm -- system -L ./modules --substitute-urls="https://substitutes.nonguix.org https://bordeaux.guix.gnu.org https://ci.guix.gnu.org" init $install_hostname.scm /mnt |
| 88 | fi |
| 89 | |
| 90 | } |
| 91 | |
| 92 | install_user_env() { |
| 93 | # System should be installed now, we can chroot in and configure the user profile now |
| 94 | # NOTE: This assumes the user "ryan" for things, so change the USER var if you change your username |
| 95 | |
| 96 | # Copy some files over to prepare for reboot |
| 97 | USER=ryan |
| 98 | guix shell git -- git clone https://git.stationery.faith/ryan77627/guix-dotfiles /mnt/home/$USER/.config/guix |
| 99 | |
| 100 | cp ~/guix-dotfiles/$install_hostname.scm /mnt/home/$USER/.config/guix/$install_hostname.scm |
| 101 | cp ~/guix-dotfiles/modules/ryan-config/user_first_run.sh /mnt/home/$USER/.bashrc |
| 102 | |
| 103 | chown 1000:1000 -R /mnt/home/ryan |
| 104 | |
| 105 | } |
| 106 | |
| 107 | gather_env |
| 108 | copy_and_prepare |
| 109 | install_system |
| 110 | install_user_env |
| 111 | |
| 112 | # Reboot the machine at this point! |
| 113 | reboot |