gitea/manifests/bin/createadmin.sh

38 lines
959 B
Bash
Raw Normal View History

2024-12-22 05:08:23 +00:00
#!/bin/bash -e
2024-12-22 07:05:23 +00:00
set -o pipefail
2024-12-22 05:08:23 +00:00
function get_token() {
kubectl exec statefulset/app -- gitea admin user generate-access-token \
--username "$name" \
--token-name "${name^^}" \
2024-12-22 05:08:23 +00:00
--scopes "$scopes" \
| awk '{print $NF}'
}
name="$1"
2024-12-22 05:08:23 +00:00
scopes="$2"
email="$name@$BASE_URL"
secret="gitea-$name"
2024-12-22 07:11:02 +00:00
passwd="$(kgseckey "$secret" password || true)"
2024-12-22 05:08:23 +00:00
if [ -z "$passwd" ]; then
passwd="$(openssl rand -hex 32)"
kubectl exec statefulset/app -- \
gitea admin user create --admin --must-change-password=false \
--email "$email" \
--username "$name" \
--password "$passwd"
2024-12-22 05:08:23 +00:00
fi
opts=()
[ -n "$scopes" ] && opts+=(
--from-literal=token="$(kgseckey "$secret" token || get_token)"
--from-literal=tokenscopes="$scopes"
)
kcreatesec "$secret" \
--from-literal=email="$email" \
--from-literal=username="$name" \
--from-literal=password="$passwd" \
"${opts[@]}"