umorpha-boxes/modules/service-gitea.sh.in

119 lines
3.1 KiB
Bash
Raw Normal View History

2023-10-29 03:32:46 +00:00
#!/hint/bash -euE
# Copyright (C) 2023 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
load_module "$(dirname -- "${BASH_SOURCE[0]}")/base-sshd.sh"
load_module "$(dirname -- "${BASH_SOURCE[0]}")/base-nginx.sh"
packages+=(gitea)
2023-11-04 07:12:33 +00:00
post_install+=(20:gitea:post_install)
2023-10-29 03:32:46 +00:00
gitea:post_install() {
local arg_mountpoint=$1
cat >"$arg_mountpoint/etc/gitea/app.ini" <<-EOF
;; Base setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[server]
PROTOCOL = http+unix
HTTP_ADDR = /run/gitea/http.sock
DOMAIN = git.mothstuff.lol
ROOT_URL = https://git.mothstuff.lol/
;; Database ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[database]
;DB_TYPE = postgres
;HOST = /var/run/postgresql
;NAME = gitea
;USER = root
;SCHEMA =
DB_TYPE = sqlite3
;; Auth/Accounts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[service]
2023-10-29 03:38:14 +00:00
;DISABLE_REGISTRATION = true
2023-10-29 03:32:46 +00:00
[openid]
ENABLE_OPENID_SIGNIN = false
ENABLE_OPENID_SIGNUP = false
[oauth2_client]
ENABLE_AUTO_REGISTRATION = true
UPDATE_AVATAR = true
;; Other ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[security]
INSTALL_LOCK = true
[log]
MODE = console
LEVEL = Info
[cront.update_checker]
ENABLED = false
;; Don't be an OAuth2 identity provider
[oauth2]
ENABLE = false
EOF
systemctl --root="$arg_mountpoint" enable gitea.service
install -Dm644 /dev/stdin "$arg_mountpoint/etc/ssh/sshd_config.d/91-gitea.conf" <<-EOF
AllowGroups gitea
EOF
install -Dm644 /dev/stdin "$arg_mountpoint/etc/nginx/sites/gitea.conf" <<-'EOF'
# -*- mode: nginx; nginx-indent-level: 4; intent-tabs-mode: nil -*-
server {
server_name git.mothstuff.lol;
include /etc/nginx/snippets/listen.conf;
location / {
client_max_body_size 512M;
proxy_pass http://unix:/run/gitea/http.sock;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
2023-10-29 03:38:14 +00:00
#location /user/login {
# return 302 /user/oauth2/Infomaniak;
#}
2023-10-29 03:32:46 +00:00
}
EOF
2023-10-29 07:58:53 +00:00
########################################################################
2023-11-14 00:28:24 +00:00
install -Dm670 --owner=root --group=gitea /dev/stdin "$arg_mountpoint/etc/gitea/post-install" <<-EOF
2023-10-29 07:58:53 +00:00
#!/bin/sh
while ! gitea admin auth list | grep -q Infomaniak; do
2023-11-14 00:28:24 +00:00
gitea admin auth add-oauth \\
--name=Infomaniak \\
--provider=openidConnect \\
--key=@CLIENT_ID@ \\
--secret=@CLIENT_SECRET@ \\
--auto-discover-url=https://login.infomaniak.com/.well-known/openid-configuration \\
2023-10-29 07:58:53 +00:00
--icon-url=https://www.infomaniak.com/favicon.ico
done
EOF
2023-11-14 00:28:24 +00:00
install -Dm644 /dev/stdin "$arg_mountpoint/etc/systemd/system/gitea-init.service" <<-EOF
[Unit]
Description=Initialize Gitea configuration
Requires=gitea.service
After=gitea.service
[Service]
Type=oneshot
User=gitea
Group=gitea
2023-10-29 07:58:53 +00:00
ExecStart=/etc/gitea/post-install
EOF
2023-11-14 00:28:24 +00:00
mkdir -p -- "$arg_mountpoint/etc/systemd/system/gitea.service.wants"
ln -s "../gitea-init.service" "$arg_mountpoint/etc/systemd/system/gitea.service.wants"
2023-10-29 03:32:46 +00:00
}