From a09d00d7f7b71ad24d1ec6255f4a4eabcfab04d6 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 1 May 2021 13:42:00 +0100 Subject: [PATCH] Fixed ssh command more --- .local/bin/setup/ssh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/.local/bin/setup/ssh b/.local/bin/setup/ssh index 3e7eb7f..4627001 100755 --- a/.local/bin/setup/ssh +++ b/.local/bin/setup/ssh @@ -32,13 +32,14 @@ KEYS=$(curl -X GET -s --url "$KEYS_URL") KEY_EXISTS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(.title)|contains([$TITLE])') -if [[ $KEY_EXISTS != true ]]; then +if [[ $KEY_EXISTS == true ]]; then # 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 == $TITLE))[].id') # Loop through the keys and remove them from gitea to be replaced by the new one if [ ! -z "$IDS" ]; then - for ID in IDS; do + for ID in $IDS; do + echo "Deleting key with ID $ID" curl -X DELETE \ -s \ -H "Accept: application/json" \ @@ -46,16 +47,17 @@ if [[ $KEY_EXISTS != true ]]; then --url "$KEYS_URL/$ID" done fi - - # Save the new key in gitea - curl -X POST \ - -s \ - -H "Accept: application/json" \ - -H "Content-Type:application/json" \ - --data "$(generate_post_data)" \ - --url "$KEYS_URL" fi + +# Save the new key in gitea +curl -X POST \ + -s \ + -H "Accept: application/json" \ + -H "Content-Type:application/json" \ + --data "$(generate_post_data)" \ + --url "$KEYS_URL" + HTTP_REPLACE="s/https:\/\/labs\.scarif\.space\//git@labs.scarif.space:/" for dir in $(ls "$HOME/.local/src"); do