gitea/manifests/bin/createadmin.sh
ange 26f48e8132
All checks were successful
/ deploy (push) Successful in 13s
fix: chmod +x
2024-12-22 05:14:43 +00:00

34 lines
796 B
Bash
Executable File

#!/bin/bash -e
function get_token() {
kubectl exec app-0 -- gitea admin user generate-access-token \
--username "$NAME" \
--token-name "${NAME^^}" \
--scopes "$scopes" \
| awk '{print $NF}'
}
export NAME="$1"
scopes="$2"
export EMAIL="$NAME@$BASE_URL"
export SECRET="gitea-$NAME"
if ! kubectl get secret "$SECRET" > /dev/null 2>&1; then
p="$(openssl rand -hex 32)"
kapply common/createadmin.yaml
else
p="$(kgseckey "$SECRET" password)"
fi
opts=()
if [ -n "$scopes" ]; then
token="$(kgseckey "$SECRET" token || get_token)"
opts+=(--from-literal=token="$token")
fi
kcreatesec "$SECRET" \
--from-literal=email="$NAME@$BASE_URL" \
--from-literal=username="$SECRET" \
--from-literal=password="$p" \
"${opts[@]}"