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,13 +30,12 @@ KEYS=$(curl -X GET -s --url "$KEYS_URL")
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
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" ]; do
# 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
curl -X DELETE \
-s \
@@ -44,12 +43,28 @@ if [ ! -z "$IDS" ]; do
-H "Content-Type:application/json" \
--url "$KEYS_URL/$ID"
done
fi
fi
# Save the new key in gitea
curl -X POST \
# 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
HTTP_REPLACE="s/https:\/\/labs\.scarif\.space\//git@labs.scarif.space:/"
for dir in $(ls "$HOME/.local/src"); do
dir="$HOME/.local/src/$dir"
if [ -d $dir ]; then
cd "$dir"
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"