109 lines
3.8 KiB
Fish
Executable file
109 lines
3.8 KiB
Fish
Executable file
#!/bin/env fish
|
|
begin
|
|
set -l dir (status dirname)
|
|
set -l user git
|
|
set -l domain git
|
|
set -l server "$domain" ""
|
|
set -l service "forgejo"
|
|
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 home /srv/git
|
|
set -l sshDir "$home/.ssh"
|
|
set -l keyFile "$sshDir/id_rsa"
|
|
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' \
|
|
$user
|
|
|
|
set uid (id -u $user)
|
|
set gid (id -g $user)
|
|
and sudo usermod -d "$home" "$user"
|
|
|
|
and yq "$envKey.USER_UID = $uid" "$file" |
|
|
yq "$envKey.USER_GID = $gid" |
|
|
sudo tee "$config" >/dev/null
|
|
|
|
rm "$file"
|
|
|
|
and sudo mkdir -p "$dir"
|
|
and sudo mkdir -p "$home"
|
|
and sudo chown -R $uid:$gid "$dir"
|
|
and sudo chown -R $uid:$gid "$home"
|
|
and sudo -u "#$uid" mkdir -p "$sshDir"
|
|
and sudo -u "#$uid" ssh-keygen -t rsa -b 4096 -C "Forgejo Host Key" -f "$keyFile" -N ""
|
|
and sudo -u "#$uid" cat "$keyFile.pub" | sudo -u "#$uid" tee -a "$sshDir/authorized_keys"
|
|
and sudo chmod 600 "$sshDir/authorized_keys"
|
|
|
|
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"
|
|
sudo ln -s "$bin" "$(dirname "$bin")/gitea"
|
|
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
|