#!/usr/bin/env bash pushd /etc/nixos/git # Home-Manager Setup echo "Setting up Home Manager..... " sudo mkdir /nix/var/nix/profiles/per-user/albert home-manager switch -b backup --flake /etc/nixos/git source ~/.bashrc # Import and trust the GPG key echo "Setting up user GPG key..... " drive=$(lsblk -o serial,name | grep 012345679518 | awk {'print $2'}) sudo mkdir /tmp/drive sudo cryptsetup luksOpen /dev/${drive}3 usb-luks sudo mount /dev/mapper/usb-luks /tmp/drive gpg --import /tmp/drive/gpg/albert@sysctl.io/privkey.asc sudo umount /tmp/drive sudo rmdir /tmp/drive sudo cryptsetup luksClose /dev/mapper/usb-luks echo -e "5\ny\n" | gpg --command-fd 0 --expert --edit-key albert@sysctl.io trust # Setup SOPS echo "Setting up SOPS keys..... " echo "!!!!!" echo "!!!!!" echo "!!!!!" echo "!!!!! Copy this signature to .sops.yaml: " echo "!!!!!" echo "!!!!!" echo "!!!!!" sudo ssh-to-pgp \ -comment "Generated `date +%Y.%m.%d`" \ -email "root@`hostname`" \ -i /etc/ssh/ssh_host_rsa_key \ -o /etc/nixos/git/keys/hosts/$(hostname).asc # Set up ssh keys echo "Setting up SSH Keys..... " ssh-keygen -t rsa -b 8192 -f ~/.ssh/id_rsa -N "" echo "" >> ./keys/ssh/keys.txt echo "# `whoami`@`hostname`" >> ./keys/ssh/keys.txt cat /home/albert/.ssh/id_rsa.pub >> ./keys/ssh/keys.txt # Add all changes to git and and push echo "Pushing to git..... " git add keys/hosts/`hostname`.asc git commit -am "Setup: `whoami`@`hostname`" git push # Fix gnupg permissions: echo "Fixing ~/.gnupg permissions..... " find ~/.gnupg -type f -exec chmod 600 {} \; find ~/.gnupg -type d -exec chmod 700 {} \; echo echo echo "Complete. Once '.sops.yaml' is updated, " echo "you may run 'update-secrets'" echo "and reboot." echo echo "Reminder: Upload these changes to git" popd