From 9b989892a4c373dd03d789b226c45549b78faeeb Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 19 Oct 2024 03:02:29 +0200 Subject: [PATCH] improve nixos-edit init --- nixos-edit.script.nix | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/nixos-edit.script.nix b/nixos-edit.script.nix index 44c4e96..130e9fb 100644 --- a/nixos-edit.script.nix +++ b/nixos-edit.script.nix @@ -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