114 lines
3.8 KiB
Fish
114 lines
3.8 KiB
Fish
#!/bin/env fish
|
|
begin
|
|
set -l dir (status dirname)
|
|
set -l turn turn
|
|
set -l domain cloud ""
|
|
set -l service web
|
|
set -l office collabora
|
|
set -l officeDomain "office" ""
|
|
set -l server $service $domain
|
|
|
|
set -l services \
|
|
$server \
|
|
$turn turn "" \
|
|
$office $officeDomain
|
|
|
|
source "$dir/../service.fish"
|
|
|
|
function installSW -V dir -V domain -V service -V turn -V office -V officeDomain
|
|
set -l genPW __generatePW
|
|
|
|
function $genPW -a length
|
|
if [ -z "$length" ]
|
|
set length 32
|
|
end
|
|
|
|
nix-shell -p keepassxc --run "keepassxc-cli generate --length $length"
|
|
end
|
|
|
|
set -l file (mktemp)
|
|
set -l root (getServiceRoot $argv)
|
|
set -l source "$dir/docker-compose.core.yml"
|
|
set -l core "$root/$(basename "$source")"
|
|
set -l domain (getServiceDomain $domain)
|
|
set -l base "$root/docker-compose.base.yml"
|
|
set -l baseSource "$dir/$(basename "$base")"
|
|
set -l secrets (getServiceSecretsConfig $argv)
|
|
set -l secretsSource "$dir/$(basename "$secrets")"
|
|
set -l turnKey "$(getServiceKey "$turn")"
|
|
set -l portKey "$turnKey.ports[1]"
|
|
set -l officeEnv "$(getServiceKey "$office").environment"
|
|
set -l dbPW ($genPW)
|
|
set -l turnPW ($genPW)
|
|
set -l turnPort
|
|
set -l redisPW ($genPW)
|
|
set -l nextcloudPW ($genPW 64)
|
|
|
|
initializeServiceInstallation $argv
|
|
sudo cp -r "$dir"/{cache.Dockerfile,cloud.Dockerfile,.dockerignore,fpm,nginx,php.ini} "$root"
|
|
|
|
begin
|
|
printf "%s\n" \
|
|
"MYSQL_DATABASE=Nextcloud" \
|
|
"MYSQL_USER=nextcloud" \
|
|
"MYSQL_PASSWORD=$dbPW"
|
|
end | sudo tee "$root/db.env" >/dev/null
|
|
|
|
echo "REDIS_HOST_PASSWORD=$redisPW" | sudo tee "$root/cache.env" >/dev/null
|
|
|
|
begin
|
|
printf "%s\n" \
|
|
"NEXTCLOUD_ADMIN_USER=admin" \
|
|
"NEXTCLOUD_ADMIN_PASSWORD=$nextcloudPW"
|
|
end | sudo tee "$root/nextcloud.env" >/dev/null
|
|
|
|
PROTO="https" DOMAIN="$domain" begin
|
|
set -l envKey "$(getServiceKey nextcloud).environment"
|
|
|
|
yq "$envKey.NEXTCLOUD_TRUSTED_DOMAINS = env(DOMAIN)" "$source" | \
|
|
yq "$envKey.OVERWRITEPROTOCOL = env(PROTO)" | \
|
|
yq "$envKey.OVERWRITEHOST = env(DOMAIN)" | \
|
|
URL="$PROTO://$DOMAIN" yq "$envKey.OVERWRITECLIURL = env(URL)" | \
|
|
sudo tee "$core" >/dev/null
|
|
|
|
DOMAIN=(getServiceDomain $officeDomain) yq "$officeEnv.server_name = env(DOMAIN)" "$baseSource" | \
|
|
URL="https://$(string escape --style regex "$DOMAIN"):443" yq "$officeEnv.aliasgroup1 = env(URL)" | \
|
|
sudo tee "$base" >/dev/null
|
|
end
|
|
|
|
begin
|
|
set -l key "$turnKey.command"
|
|
|
|
PW="--static-auth-secret=$turnPW" \
|
|
DOMAIN="--realm=$domain" \
|
|
yq "$key |= . + [env(PW), env(DOMAIN)]" "$secretsSource" | \
|
|
sudo tee "$secrets" >/dev/null
|
|
end
|
|
|
|
installDockerService $argv
|
|
set turnPort (yq (getServicePortKey "$turn") "$secrets" | extractPort)
|
|
set turnPort (yq "$portKey" "$secrets" | mutatePort "$turnPort")
|
|
|
|
cp "$secrets" "$file"
|
|
PORT="$turnPort" yq "$portKey = env(PORT)" "$file" | sudo tee "$secrets" >/dev/null
|
|
rm "$file"
|
|
end
|
|
|
|
function configureSW -V dir
|
|
configureDockerService $argv
|
|
end
|
|
|
|
function getServiceServers -V services
|
|
for i in (seq 1 3 (count $services))
|
|
printf "%s\0" $services[(math $i + 1)] $services[(math $i + 2)]
|
|
end
|
|
end
|
|
|
|
function getServiceLocations -V services -a index
|
|
set -l i (math (math (math $index - 1) / 2 "*" 3) + 1)
|
|
set -l name $services[$i]
|
|
printf "%s\0" "$name" /
|
|
end
|
|
|
|
runInstaller --force $argv
|
|
end
|