Update remote repositories to use ssh

This commit is contained in:
2021-04-16 14:12:06 +01:00
parent 38060ef848
commit 6516ff47b9

View File

@@ -30,26 +30,41 @@ KEYS=$(curl -X GET -s --url "$KEYS_URL")
KEY_EXISTS=$(echo $KEYS | jq --arg KEY "$(cat "$SSHPATH.pub")" 'contains({ key: $KEY })') KEY_EXISTS=$(echo $KEYS | jq --arg KEY "$(cat "$SSHPATH.pub")" 'contains({ key: $KEY })')
[[ $KEY_EXISTS == true ]] && return if [[ $KEY_EXISTS != true ]]; do
# 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')
# Extract the ids of the keys with the same title as this machine # Loop through the keys and remove them from gitea to be replaced by the new one
IDS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(select(.title == $TITLE))[].id') if [ ! -z "$IDS" ]; then
for ID in IDS; do
curl -X DELETE \
-s \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--url "$KEYS_URL/$ID"
done
fi
# Loop through the keys and remove them from gitea to be replaced by the new one # Save the new key in gitea
if [ ! -z "$IDS" ]; do curl -X POST \
for ID in IDS; do -s \
curl -X DELETE \ -H "Accept: application/json" \
-s \ -H "Content-Type:application/json" \
-H "Accept: application/json" \ --data "$(generate_post_data)" \
-H "Content-Type:application/json" \ --url "$KEYS_URL"
--url "$KEYS_URL/$ID"
done
fi fi
# Save the new key in gitea HTTP_REPLACE="s/https:\/\/labs\.scarif\.space\//git@labs.scarif.space:/"
curl -X POST \
-s \ for dir in $(ls "$HOME/.local/src"); do
-H "Accept: application/json" \ dir="$HOME/.local/src/$dir"
-H "Content-Type:application/json" \ if [ -d $dir ]; then
--data "$(generate_post_data)" \ cd "$dir"
--url "$KEYS_URL" SSH_URL=$(git remote get-url origin | sed "$HTTP_REPLACE")
git remote set-url origin "$SSH_URL"
fi
done
DOTFILES_SSH_URL=$(git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" get-url origin | sed "$HTTP_REPLACE")
git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" set-url origin "$DOTFILES_SSH_URL"