104 lines
3.5 KiB
Fish
104 lines
3.5 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 overrides (getServiceOverrides $argv)
|
|
set -l overridesSource "$dir/$(basename "$overrides")"
|
|
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,docker-compose.{base,core}.yml,.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" \
|
|
"NEXTCLOUD_TRUSTED_DOMAINS=$domain" \
|
|
"OVERWRITEPROTOCOL=https" \
|
|
"OVERWRITEHOST=$domain" \
|
|
"OVERWRITECLIURL=https://$domain"
|
|
end | sudo tee "$root/nextcloud.env" >/dev/null
|
|
|
|
PROTO="https" DOMAIN="$domain" begin
|
|
set -l key "$turnKey.command"
|
|
|
|
PW="--static-auth-secret=$turnPW" \
|
|
DOMAIN="--realm=$domain" \
|
|
yq "$key |= . + [env(PW), env(DOMAIN)]" "$overridesSource" | \
|
|
DOMAIN=(getServiceDomain $officeDomain) yq "$officeEnv.server_name = env(DOMAIN)" | \
|
|
URL="https://$(string escape --style regex "$DOMAIN"):443" yq "$officeEnv.aliasgroup1 = env(URL)" | \
|
|
sudo tee "$overrides" >/dev/null
|
|
end
|
|
|
|
installDockerService $argv
|
|
set turnPort (yq (getServicePortKey "$turn") "$overrides" | extractPort)
|
|
set turnPort (yq "$portKey" "$overrides" | mutatePort "$turnPort")
|
|
|
|
cp "$overrides" "$file"
|
|
PORT="$turnPort" yq "$portKey = env(PORT)" "$file" | sudo tee "$overrides" >/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
|