nix/docs/setup.sh
2023-09-23 21:56:31 +09:00

51 lines
No EOL
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
sudo mkdir /nix/var/nix/profiles/per-user/albert
pushd /etc/nixos/git
home-manager switch -b backup --flake /etc/nixos/git
source ~/.bashrc
sleep 10
# Import and trust the GPG key
echo "Setting up user GPG key..... "
drive=$(lsblk -o serial,name | grep -A 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 rmdir /tmp/drive
echo -e "5\ny\n" | gpg --command-fd 0 --expert --edit-key albert@sysctl.io trust
sleep 10
# Setup SOPS
echo "!!!!! Copy this key to .sops.yaml: "
sudo ssh-to-pgp \
-comment "Generated `ddate`" \
-email "root@`hostname`" \
-i /etc/ssh/ssh_host_rsa_key \
-o /etc/nixos/git/keys/hosts/$(hostname).asc
# Set 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
git add keys/hosts/`hostname`.asc
git commit -am "Setup: `whoami`@`hostname`"
git push
# Fix 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."
popd