PortValhalla/scripts/Common/Software/docker/services/forgejo/main.fish

101 lines
3.3 KiB
Fish
Executable file

#!/bin/env fish
begin
set -l dir (status dirname)
set -l user "forgejo"
set -l domain "git"
set -l server "$domain" ""
set -l service $user
source "$dir/../service.fish"
function getSSHPortKey -V service
echo "$(getServiceKey "$service").ports[1]"
end
function installSW -V dir -V domain -V server -V service
set -l root (getServiceRoot $argv)
set -l secrets (getServiceSecretsConfig $argv)
set -l source "$dir/$(basename "$secrets")"
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
set -l port (getRandomPort)
initializeServiceInstallation $argv
sudo cp "$dir/docker-compose.yml" "$root"
set port (yq (getSSHPortKey) "$source" --raw-output | mutatePort "$port")
DOMAIN=(getServiceDomain $server) PW=$pw DB=Git USER=forgejo PW=$pw begin
set -l gitEnv "$(getServiceKey "$service").environment"
set -l dbEnv "$(getServiceKey "db").environment"
PORT=$port yq "$(getSSHPortKey) = env.PORT" "$source" | \
yq "$gitEnv.FORGEJO__database__NAME = env.DB" | \
yq "$gitEnv.FORGEJO__database__USER = env.USER" | \
yq "$gitEnv.FORGEJO__database__PASSWD = env.PW" | \
yq "$dbEnv.MARIADB_DATABASE = env.DB" | \
yq "$dbEnv.MARIADB_USER = env.USER" | \
yq "$dbEnv.MARIADB_PASSWORD = env.PW" | \
yq -y . | \
sudo tee "$secrets" >/dev/null
end
installDockerService $argv
end
function configureSW -V dir -V user -V service
set -l uid
set -l gid
set -l port
set -l file (mktemp)
set -l root (getServiceRoot $argv)
set -l dir "$root/data"
set -l bin "/usr/local/bin/forgejo"
set -l config "$root/docker-compose.yml"
set -l secrets (getServiceSecretsConfig $argv)
set -l envKey "$(getServiceKey "$service").environment"
configureDockerService $argv
cp "$config" "$file"
and sudo useradd \
--system \
--shell /bin/bash \
--comment 'Git Version Control' \
--create-home \
$user
set uid (id -u $user)
set gid (id -g $user)
and yq "$envKey.USER_UID = $uid" "$file" | \
yq "$envKey.USER_GID = $gid" | \
yq -y . |
sudo tee "$config" >/dev/null
mkdir -p "$dir"
and chown -R $uid:$gid "$dir"
rm "$file"
set port (yq (getSSHPortKey) "$secrets" --raw-output | extractPort)
begin
printf "%s\n" \
"#!/bin/sh" \
"ssh -p $port -o StrictHostKeyChecking=no git@127.0.0.1 \"SSH_ORIGINAL_COMMAND=\\\"$SSH_ORIGINAL_COMMAND\\\" \$0 \$@\""
end | sudo tee "$bin" >/dev/null
chmod +x "$bin"
end
function getServiceServers -V server
printf "%s\0" $server
end
function getServiceLocations
argparse -i "name=" -- $argv
printf "%s\0" "$_flag_name" /
end
function getBackupArgs
printf "%s\n" --hidden --no-ignore . --exclude "docker-compose.yml" (getServiceRoot $argv)
end
runInstaller --force $argv
end