Improve install

This commit is contained in:
2026-03-14 16:07:57 +00:00
parent 673748402a
commit dbeb4d02a4
5 changed files with 156 additions and 21 deletions

View File

@@ -1,8 +1,10 @@
#! /bin/bash
echo "Setting up SSH"
echo "-------------------------------------"
echo "SSH Setup Script"
echo "-------------------------------------"
# Extract the login details from enpass
echo "Extracting login details from enpass"
LABS=$(enpass-cli -vault="$HOME/Documents/Enpass/Vaults/primary" -sort show "Scarif: Labs" 2>&1)
LABSUN=$(echo "$LABS" | grep -Po "(?<=login: )\w+")
LABSPW=$(enpass-cli -vault="$HOME/Documents/Enpass/Vaults/primary" -sort pass "Scarif: Labs")
@@ -10,7 +12,8 @@ LABSPW=$(enpass-cli -vault="$HOME/Documents/Enpass/Vaults/primary" -sort pass "S
SSHPATH="$HOME/.ssh/id_ed25519" # The path to the SSH key file
TITLE="$USER@$(cat /etc/hostname)" # The title for the SSH key
echo "Generate the SSH key if it does not exist"
echo "~~~~~~~~"
echo "Generating the SSH key if it does not exist"
[ ! -f $SSHPATH ] && ssh-keygen -t ed25519 -f "$SSHPATH" -N "" -q
KEY=$(cat "$SSHPATH.pub")
@@ -34,6 +37,8 @@ KEYS=$(curl -X GET -s -S --url "$KEYS_URL")
KEY_EXISTS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(.title|ascii_downcase)|contains([$TITLE|ascii_downcase])')
echo "~~~~~~~~"
echo "Checking if the key exists on the server"
if [[ $KEY_EXISTS == true ]]; then
echo "Found keys with the same title as this machine."
# Extract the ids of the keys with the same title as this machine
@@ -53,6 +58,7 @@ if [[ $KEY_EXISTS == true ]]; then
fi
fi
echo "~~~~~~~~"
echo "Saving the new key"
curl -X POST \
-s -S \
@@ -72,6 +78,7 @@ for dir in "$HOME/.local/nixos"; do
fi
done
echo "~~~~~~~~"
echo "Replacing remote URL to use SSH key"
DOTFILES_SSH_URL=$(git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" remote get-url origin | sed "$HTTP_REPLACE")
git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" remote set-url origin "$DOTFILES_SSH_URL"