Update remote repositories to use ssh
This commit is contained in:
@@ -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=$(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
|
# 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
|
# Loop through the keys and remove them from gitea to be replaced by the new one
|
||||||
if [ ! -z "$IDS" ]; do
|
if [ ! -z "$IDS" ]; then
|
||||||
for ID in IDS; do
|
for ID in IDS; do
|
||||||
curl -X DELETE \
|
curl -X DELETE \
|
||||||
-s \
|
-s \
|
||||||
@@ -53,3 +52,19 @@ curl -X POST \
|
|||||||
-H "Content-Type:application/json" \
|
-H "Content-Type:application/json" \
|
||||||
--data "$(generate_post_data)" \
|
--data "$(generate_post_data)" \
|
||||||
--url "$KEYS_URL"
|
--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"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user