improve nixos-edit init

This commit is contained in:
Daniella / Tove 2024-10-19 03:02:29 +02:00
parent 728df2c06d
commit 9b989892a4

View file

@ -4,8 +4,45 @@ pkgs.writeShellScriptBin "nixos-edit" ''
#!/bin/sh
if [ "$1" = "init" ] ; then
if [ "$(whoami)" != root ] ; then
echo "re-executing as tudbut"
echo -n "set password for tudbut? (Y/n) "
read yn
if [ "$yn" != "n" ] ; then
passwd tudbut || exit 1
fi
sleep 2
exec sudo -u tudbut nixos-edit init || exit 1
fi
sudo chown -R tudbut: /etc/nixos
echo dir setup done
echo "> setting up ssh"
echo ssh setup
if ! [ -e ~/.ssh/id_rsa ] ; then
ssh-keygen || exit
fi
echo ssh key created
cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
echo "-> copied to clipboard for later"
echo adding it to syncfs
echo "-> you will need to input your password"
ssh root@tudbut.de ssh -p 23 localhost bash -c "echo -e '# $(cat /etc/hostname)\n$(cat ~/.ssh/id_rsa.pub)\n' >> .ssh/authorized_keys" || exit 1
echo "> ssh setup done"
echo "> setting up git"
git config --global user.name "TudbuT"
git config --global user.email "forge-public@mail.tudbut.de"
git config --global init.defaultBranch main
git config --global push.default current
echo configs set
echo mounting syncfs
startsync > /dev/null 2>&1 &
echo opening git key add page
echo "-> close firefox when complete."
firefox "https://git.tudbut.de/user/login?redirect_to=%2fuser%2fsettings%2fkeys" > /dev/null 2>&1
echo correcting remote
cd /etc/nixos
git remote set-url origin 'ssh://git@tudbut.de:222/TudbuT/nix-setup.git'
echo done
exit 0
fi