From 4bcaaa25d72b8a2a651ee3c2233c0b2f846ef934 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Wed, 27 Dec 2023 21:42:14 +0000 Subject: [PATCH] fic: should now be working properly --- sync/sync.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sync/sync.sh b/sync/sync.sh index ea9902e..4bb5df3 100644 --- a/sync/sync.sh +++ b/sync/sync.sh @@ -2,28 +2,33 @@ Mirror-Clear(){ # existing remotes - local response=$(curl -s -X "GET" "https://gitlab.skynet.ie/api/v4/projects/$1/remote_mirrors" --header "PRIVATE-TOKEN: $TOKEN") + local id=$(tr -d '\n\t\r ' <<<"${1}" ) + local token=$(tr -d '\n\t\r ' <<<"$TOKEN" ) + local response=$(curl -X "GET" "https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors" --header "PRIVATE-TOKEN: $token") # https://stackoverflow.com/a/67638584 - readarray -t local my_array < <(jq -c '.[]' <<< $response) + readarray -t my_array < <(jq -c '.[]' <<< $response) # iterate through the Bash array for item in "${my_array[@]}"; do - local id=$(jq --raw-output '.id' <<< "$item") - curl -s -X "DELETE" "https://gitlab.skynet.ie/api/v4/projects/$1/remote_mirrors/$id" --header "PRIVATE-TOKEN: $TOKEN" + local id_mirror=$(jq --raw-output '.id' <<< "$item") + curl -X "DELETE" "https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors/$id_mirror" --header "PRIVATE-TOKEN: $token" done } Mirror-Create(){ # make sure the values are clean of extra characters - local ID=${1} + local id=$(tr -d '\n\t\r ' <<<"${1}" ) local REPO_TMP=$(tr -d '\n\t\r ' <<<"${2}" ) local REPO=${REPO_TMP#"https://"} + local token=$(tr -d '\n\t\r ' <<<"$TOKEN" ) + local token_remote=$(tr -d '\n\t\r ' <<<"$TOKEN_REMOTE" ) - local body="url=https://oauth2:$TOKEN_REMOTE@$REPO&enabled=true&only_protected_branches=false&keep_divergent_refs=false" + local body="url=https://oauth2:$token_remote@$REPO&enabled=true&only_protected_branches=false&keep_divergent_refs=false" local uri="https://gitlab.skynet.ie/api/v4/projects/$id/remote_mirrors" echo $uri + echo $body local tmp="" - curl -sS -X "POST" "$uri" --header "PRIVATE-TOKEN: $TOKEN" --data $body > tmp + curl -X "POST" "$uri" --header "PRIVATE-TOKEN: $token" --data $body } Main() {