2023-03-24 17:42:52 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
function wait_for() {
|
|
|
|
rm -f /tmp/setup-forgejo.out
|
|
|
|
success=false
|
|
|
|
for delay in 1 1 5 5 15 15 15 30 30 30 30 ; do
|
|
|
|
if "$@" >> /tmp/setup-forgejo.out 2>&1 ; then
|
|
|
|
success=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
cat /tmp/setup-forgejo.out
|
|
|
|
echo waiting $delay
|
|
|
|
sleep $delay
|
|
|
|
done
|
|
|
|
if test $success = false ; then
|
|
|
|
cat /tmp/setup-forgejo.out
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-03-25 09:34:41 -04:00
|
|
|
function run() {
|
|
|
|
local image="$1"
|
2023-03-24 17:42:52 -04:00
|
|
|
|
2023-03-25 09:34:41 -04:00
|
|
|
docker run --name forgejo \
|
2023-03-24 17:42:52 -04:00
|
|
|
-e "RUN_MODE=dev" \
|
|
|
|
-e "FORGEJO__security__INSTALL_LOCK=true" \
|
|
|
|
-e "FORGEJO__log__LEVEL=debug" \
|
|
|
|
-e "FORGEJO__actions__ENABLED=true" \
|
|
|
|
-e "FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true" \
|
2023-03-25 09:34:41 -04:00
|
|
|
-e "FORGEJO__repository__DEFAULT_PUSH_CREATE_PRIVATE=false" \
|
2023-03-24 17:42:52 -04:00
|
|
|
-e "FORGEJO__repository__DEFAULT_REPO_UNITS=repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,actions.actions" \
|
|
|
|
-d $image
|
2023-03-25 09:34:41 -04:00
|
|
|
local ip="$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" forgejo)"
|
|
|
|
echo $ip > forgejo-ip
|
2023-03-26 13:02:38 -04:00
|
|
|
docker exec forgejo sed -i -e "s|localhost|$ip|" /data/gitea/conf/app.ini
|
2023-03-25 09:34:41 -04:00
|
|
|
docker restart forgejo
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
local user="${1:-root}"
|
|
|
|
local password="${2:-admin1234}"
|
|
|
|
local image="${3:-codeberg.org/forgejo/forgejo:1.19}"
|
|
|
|
|
|
|
|
run $image
|
2023-03-24 17:42:52 -04:00
|
|
|
|
|
|
|
sleep 5 # for some reason trying to run "forgejo admin" while forgejo is booting will permanently break everything
|
|
|
|
if docker exec --user 1000 forgejo forgejo admin user list --admin | grep "$user" ; then
|
|
|
|
docker exec --user 1000 forgejo forgejo admin user change-password --username "$user" --password "$password"
|
|
|
|
else
|
|
|
|
wait_for docker exec --user 1000 forgejo forgejo admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
|
|
|
|
fi
|
2023-03-26 13:02:06 -04:00
|
|
|
docker exec --user 1000 forgejo forgejo admin user generate-access-token -u $user --raw --scopes 'all,sudo' > forgejo-token
|
2023-03-24 17:42:52 -04:00
|
|
|
( echo -n 'Authorization: token ' ; cat forgejo-token ) > forgejo-header
|
2023-03-25 09:34:41 -04:00
|
|
|
( echo "#!/bin/sh" ; echo 'curl -sS -H "Content-Type: application/json" -H @'$(pwd)/forgejo-header' "$@"' ) > forgejo-api && chmod +x forgejo-api
|
2023-03-24 17:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
docker stop forgejo >& /dev/null || true
|
|
|
|
docker rm -f forgejo >& /dev/null || true
|
|
|
|
}
|
|
|
|
|
|
|
|
"$@"
|