Files
Happy-Ripper/bin/update_dockerhub_api
T

31 lines
962 B
Bash
Executable File

#!/bin/bash
if [[ -z "${1}" ]]; then
echo "This is for the gitea actions only, as it requires the repository's secrets to pass the needed variables"
exit 1
fi
DOCKERHUB_USERNAME="${1}"
DOCKERHUB_PASSWORD="${2}"
GITEA_OWNER_REPO="${3}"
GITEA_API_KEY="${4}"
gitea_username=$(echo "${GITEA_OWNER_REPO}" | sed 's/\/.*//')
repo_name=$(echo "${GITEA_OWNER_REPO}" | sed 's/^.*\///')
NEW_DOCKERHUB_TOKEN=$(curl -s -X POST "https://hub.docker.com/v2/auth/token" \
-H "Content-Type: application/json" \
-d "{\"identifier\": \"${DOCKERHUB_USERNAME}\", \"secret\": \"${DOCKERHUB_PASSWORD}\"}" \
| jq -r .access_token)
curl -X 'PUT' \
"https://gitea.happylizard.me/api/v1/repos/${gitea_username}/${repo_name}/actions/secrets/DOCKERHUB_TOKEN" \
-H 'accept: application/json' \
-H "Authorization: token ${GITEA_API_KEY}" \
-H 'Content-Type: application/json' \
-d "{
\"data\": \"${NEW_DOCKERHUB_TOKEN}\",
\"description\": \"\"
}"