#!/usr/bin/env bash
pushd /etc/nixos/git

# 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

echo ">>> Setting up Distributed Build SSH Keys..... "
sudo ssh-keygen -t rsa -b 8192 -f /root/.ssh/id_rsa -N ""
echo "" >> ./keys/ssh/builder-keys.txt
echo "# root@`hostname`" >> ./keys/ssh/builder-keys.txt
sudo cat /root/.ssh/id_rsa.pub >> ./keys/ssh/builder-keys.txt

# Add all changes to git and and push
echo ">>> Pushing to git..... "
git add keys/hosts/`hostname`.asc
git commit -am "Setup: `hostname`"
git push

echo
echo
echo ">>> Complete.  Once '.sops.yaml' is updated, "
echo ">>> run 'update-secrets' and reboot."
echo 
echo
echo ">>> Reminder:  Upload these changes to git"

popd