1
0
Fork 0
env/.local/bin/update-drone-docker

72 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
DRONE_SERVER=${DRONE_SERVER:="https://ci.makerforce.io"}
DRONE_TOKEN=${DRONE_TOKEN:=""}
echo
echo "This script updates Docker logins on all Drone repos"
echo
path_to_httpie=$(which http)
if [ ! -x "$path_to_httpie" ] ; then
echo "HTTPie not installed. Please install it at (https://httpie.org/doc#installation)"
fi
path_to_jq=$(which jq)
if [ ! -x "$path_to_jq" ] ; then
echo "JQ not installed. Please install it at (https://stedolan.github.io/jq/download/)"
fi
if [ -z $DRONE_TOKEN ]; then
echo "Enter Drone token ($DRONE_SERVER/account/token)"
echo -n "> "
read DRONE_TOKEN
echo
fi
echo "Enter Docker username"
echo -n "> "
read docker_username
echo
echo "Enter Docker password"
echo -n "> "
read -s docker_password
echo
echo
echo "Fetching repo list..."
repo_list=$(http GET $DRONE_SERVER/api/user/repos Authorization:"Bearer $DRONE_TOKEN" | jq .[].slug -r)
#repo_enabled_list=$(http GET $DRONE_SERVER/api/user/repos Authorization:"Bearer $DRONE_TOKEN" | jq .[].enabled -r)
for r in $repo_list; do
echo "Updating docker_username in $r..."
http --check-status -b PATCH \
$DRONE_SERVER/api/repos/$r/secrets/docker_username \
Authorization:"Bearer $DRONE_TOKEN" \
data="$docker_username" \
pull_request:=false \
|| http --check-status -b POST \
$DRONE_SERVER/api/repos/$r/secrets \
Authorization:"Bearer $DRONE_TOKEN" \
name="docker_username" \
data="$docker_username" \
pull_request:=false
echo "Updating docker_password in $r..."
http --check-status -b PATCH \
$DRONE_SERVER/api/repos/$r/secrets/docker_password \
Authorization:"Bearer $DRONE_TOKEN" \
data="$docker_password" \
pull_request:=false \
|| http --check-status -b POST \
$DRONE_SERVER/api/repos/$r/secrets \
Authorization:"Bearer $DRONE_TOKEN" \
name="docker_password" \
data="$docker_password" \
pull_request:=false
done