#!/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 overrides (getServiceOverrides $argv) set -l source "$dir/$(basename "$overrides")" set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l port (getRandomPort) initializeServiceInstallation $argv sudo cp "$dir/docker-compose.base.yml" "$root" set port (yq (getSSHPortKey) "$source" | mutatePort "$port") DOMAIN=(getServiceDomain $server) PW=$pw DB=Git USER=forgejo PW=$pw begin set -l gitEnv "$(getServiceKey "$service").environment" set -l actEnv "$(getServiceKey "runner").environment" set -l dbEnv "$(getServiceKey "db").environment" PORT=$port yq "$(getSSHPortKey) = env(PORT)" "$source" | yq "$gitEnv.FORGEJO__server__DOMAIN = env(DOMAIN)" | 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)" | URL="https://$DOMAIN/" yq "$actEnv.GITEA_INSTANCE_URL = env(URL)" | sudo tee "$overrides" >/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.base.yml" set -l overrides (getServiceOverrides $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" | sudo tee "$config" >/dev/null sudo mkdir -p "$dir" and sudo chown -R $uid:$gid "$dir" rm "$file" set port (yq (getSSHPortKey) "$overrides" | 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 sudo 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 runInstaller --force $argv end