From 21ffa34ed3bf388ebe39671bac4258c5aef9bd1c Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 1 Mar 2026 00:25:15 +0000 Subject: [PATCH] Fix script --- .local/bin/install/ssh.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.local/bin/install/ssh.sh b/.local/bin/install/ssh.sh index 0f7d1ed..4d346eb 100755 --- a/.local/bin/install/ssh.sh +++ b/.local/bin/install/ssh.sh @@ -10,7 +10,7 @@ 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 -# Generate the SSH key if it does not exist +echo "Generate the SSH key if it does not exist" [ ! -f $SSHPATH ] && ssh-keygen -t ed25519 -f "$SSHPATH" -N "" -q KEY=$(cat "$SSHPATH.pub") @@ -32,13 +32,15 @@ KEYS_URL="https://$CREDENTIALS@labs.scarif.space/api/v1/user/keys" # Get all the existing keys KEYS=$(curl -X GET -s -S --url "$KEYS_URL") -KEY_EXISTS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(.title)|contains([$TITLE])') +KEY_EXISTS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(.title|ascii_downcase)|contains([$TITLE|ascii_downcase])') 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 - IDS=$(echo "$KEYS" | jq --arg TITLE "$TITLE" 'map(select(.title == $TITLE))[].id') + IDS=$(echo "$KEYS" | jq --arg TITLE "$TITLE" 'map(select(.title|ascii_downcase == ($TITLE|ascii_downcase)))[].id') # Loop through the keys and remove them from gitea to be replaced by the new one + echo "Removing found keys to replace with this machine" if [ ! -z "$IDS" ]; then for ID in $IDS; do echo "Deleting key with ID $ID" @@ -46,19 +48,18 @@ if [[ $KEY_EXISTS == true ]]; then -s -S \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ - --url "$KEYS_URL/$ID" > /dev/null + --url "$KEYS_URL/$ID" done fi fi - -# Save the new key in gitea +echo "Saving the new key" curl -X POST \ -s -S \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ --data "$(generate_post_data)" \ - --url "$KEYS_URL" > /dev/null + --url "$KEYS_URL" HTTP_REPLACE="s/https:\/\/labs\.scarif\.space\//git@labs.scarif.space:/" @@ -71,6 +72,7 @@ HTTP_REPLACE="s/https:\/\/labs\.scarif\.space\//git@labs.scarif.space:/" # fi # done +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"