Add convertdomain scripts for plane and calcom, clean up repeated code

This commit is contained in:
Bernhard "bero" Rosenkränzer (Boggins) 2025-01-15 00:24:39 +01:00
parent 97b59fb351
commit 28277c8133

View File

@ -77,11 +77,32 @@ do_serviceprep() {
sed -i "s#dc=federatedcomputer,dc=cloud#$DOMAIN_NEW_LDAP_dc#g" /federated/apps/ldap/data/root/convertdomain1.ldif
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/ldap/data/root/convertdomain1.ldif
}
convert_generic() {
#### Conversions that must be done for almost everything
# FIXME check if Jitsi really needs upper-case DC. If we can use lower case dc like everywhere else,
# we can avoid generating DOMAIN_NEW_LDAP_DC
sed -i "s#$DOMAIN#$DOMAIN_NEW#g;s#$DOMAIN_LDAP_dc#$DOMAIN_NEW_LDAP_dc#g;s#$DOMAIN_LDAP_DC#$DOMAIN_NEW_LDAP_DC#g" /federated/apps/$1/docker-compose.yml
[ -e /federated/apps/$1/.env ] && sed -i "s#$DOMAIN#$DOMAIN_NEW#g;s#$DOMAIN_LDAP_dc#$DOMAIN_NEW_LDAP_dc#g;s#$DOMAIN_LDAP_DC#$DOMAIN_NEW_LDAP_DC#g" /federated/apps/$1/.env
}
convert_calcom() {
echo -ne "\n* Converting calcom..."
convert_generic calcom
/federated/bin/sync-calcomusers
echo done
}
convert_plane() {
echo -ne "\n* Converting plane..."
convert_generic plane
docker exec postgresql psql -U plane -c "UPDATE instances SET domain='$DOMAIN_NEW' WHERE domain='$DOMAIN'"
docker exec postgresql psql -U plane -c "UPDATE users SET email=REPLACE(email, '@$DOMAIN', '@$DOMAIN_NEW') WHERE email LIKE '%@$DOMAIN'"
docker exec postgresql psql -U plane -c "UPDATE profiles SET company_name='$DOMAIN_NEW' WHERE company_name='$DOMAIN'"
echo done
}
convert_pdnsmysql() {
#### Convert PowerDNS pdnsmysql
echo -ne "\n* Converting pdnsmysql.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/pdnsmysql/docker-compose.yml
convert_generic pdnsmysql
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/pdnsmysql/docker-compose.yml | awk '{ print $2 }'`
@ -95,8 +116,8 @@ convert_pdnsmysql() {
convert_pdns() {
#### Convert PowerDNS pdns
echo -ne "\n* Converting pdns.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/pdns/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/pdns/.env
convert_generic pdns
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/pdns/docker-compose.yml | awk '{ print $2 }'`
@ -110,8 +131,7 @@ convert_pdnsadmin() {
#### Convert PowerDNS pdnsadmin
echo -ne "\n* Converting pdnsadmin.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/pdnsadmin/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/pdnsadmin/.env
convert_generic pdnsadmin
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/pdnsadmin/docker-compose.yml | awk '{ print $2 }'`
@ -130,8 +150,7 @@ convert_traefik() {
echo -ne "\n* Converting traefik. Waiting 60s first for dns.."
sleep 60
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/traefik/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/traefik/.env
convert_generic traefik
rm -rf /federated/apps/traefik/data/letsencrypt/acme.json
# Start Traefik
@ -162,8 +181,7 @@ convert_postgresql() {
#### Convert Postgresql
echo -ne "\n* Converting postgresql.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/postgresql/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/postgresql/.env
convert_generic postgresql
cp /federated/certs/certs/$DOMAIN_NEW.crt /federated/apps/postgresql/data/var/lib/postgresql/server.crt
cp /federated/certs/private/$DOMAIN_NEW.key /federated/apps/postgresql/data/var/lib/postgresql/server.key
chown 999 /federated/apps/postgresql/data/var/lib/postgresql/server.crt /federated/apps/postgresql/data/var/lib/postgresql/server.key
@ -187,8 +205,7 @@ convert_ldap() {
rm -rf /federated/apps/ldap/data/root/.ldaprc
rm -rf /federated/apps/ldap/data/certs/dhparam.pem
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/ldap/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/ldap/.env
convert_generic ldap
sed -i "s#LDAP_DOMAIN=.*#LDAP_DOMAIN=$DOMAIN_NEW#g" /federated/apps/ldap/.env
sed -i "s#LDAP_ORGANISATION=.*#LDAP_ORGANISATION=$ORG_NEW#g" /federated/apps/ldap/.env
cp /federated/certs/certs/$DOMAIN_NEW.crt /federated/certs/private/$DOMAIN_NEW.key /federated/apps/ldap/data/certs/
@ -209,12 +226,9 @@ convert_mail() {
#### Convert Mail
echo -ne "\n* Converting mail.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/mail/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/mail/.env
convert_generic mail
cp /federated/certs/certs/$DOMAIN_NEW.crt /federated/certs/private/$DOMAIN_NEW.key /federated/apps/mail/data/root/certs/
sed -i "s#$DOMAIN_LDAP_dc#dc=$DOMAIN_NEW_LDAP_dc#g" /federated/apps/mail/.env
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/mail/docker-compose.yml | awk '{ print $2 }'`
@ -245,8 +259,7 @@ convert_collabora() {
#### Convert Collabora
echo -ne "\n* Converting collabora.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/collabora/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/collabora/.env
convert_generic collabora
cp /federated/certs/certs/$DOMAIN_NEW.crt /federated/certs/private/$DOMAIN_NEW.key /federated/apps/collabora/data/root/certs/
chown 104 /federated/apps/collabora/data/root/certs/*
@ -262,8 +275,7 @@ convert_nextcloud() {
#### Convert Nextcloud
echo -ne "\n* Converting nextcloud.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/nextcloud/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/nextcloud/.env
convert_generic nextcloud
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/nextcloud/data/var/www/html/config/config.php
# Make new nextcloud config
@ -460,8 +472,7 @@ convert_matrix() {
docker exec postgresql psql -U postgres -c "CREATE DATABASE matrix"
docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE matrix TO matrix"
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/matrix/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/matrix/.env
convert_generic matrix
rm -rf /federated/apps/matrix/data
mkdir -p /federated/apps/matrix/data/matrix
@ -514,12 +525,12 @@ modules:
enabled: true
uri: "ldaps://ldap.$DOMAIN_NEW:636"
start_tls: true
base: "dc=federatedcomputer,dc=cloud"
base: "$DOMAIN_NEW_LDAP_dc"
attributes:
mail: "mail"
uid: "uid"
name: "givenName"
bind_dn: cn=admin,dc=federatedcomputer,dc=cloud
bind_dn: cn=admin,$DOMAIN_NEW_LDAP_dc
bind_password: $LDAP_SECRET
tls_options:
validate: true
@ -527,7 +538,6 @@ modules:
local_private_key_file: /data/$DOMAIN_NEW.key
EOF
sed -i "s#dc=federatedcomputer,dc=cloud#$DOMAIN_NEW_LDAP_dc#g" /federated/apps/matrix/data/matrix/homeserver.yaml
chown -R 991:991 /federated/apps/matrix/data/matrix
# sed -i "s#server_name: \"matrix.$DOMAIN\"#server_name: \"matrix.$DOMAIN_NEW\"#g" /federated/apps/matrix/data/matrix/homeserver.yaml
@ -583,8 +593,7 @@ convert_element() {
#### Convert Element
echo -ne "\n* Converting element.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/element/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/element/.env
convert_generic element
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/element/data/element/element-config.json
# Grab the container IP from docker-compose
@ -599,8 +608,7 @@ convert_listmonk() {
#### Convert Listmonk
echo -ne "\n* Converting listmonk.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/listmonk/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/listmonk/.env
convert_generic listmonk
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/listmonk/data/listmonk/config.toml
# Grab the container IP from docker-compose
@ -620,8 +628,7 @@ convert_vaultwarden() {
#### Convert Vaultwarden
echo -ne "\n* Converting vaultwarden.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/vaultwarden/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/vaultwarden/.env
convert_generic vaultwarden
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/vaultwarden/docker-compose.yml | awk '{ print $2 }'`
@ -635,9 +642,7 @@ convert_panel() {
#### Convert Panel
echo -ne "\n* Converting panel.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/panel/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/panel/.env
sed -i "s#$DOMAIN_LDAP_dc#$DOMAIN_NEW_LDAP_dc#g" /federated/apps/panel/.env
convert_generic panel
sed -i "s#SITE_NAME=.*#SITE_NAME=$ORG_NEW Panel#g" /federated/apps/panel/.env
# Grab the container IP from docker-compose
@ -652,8 +657,7 @@ convert_wireguard() {
#### Convert Wireguard
echo -ne "\n* Converting wireguard.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wireguard/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wireguard/.env
convert_generic wireguard
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wireguard/data/config/.donoteditthisfile
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wireguard/data/config/peer1/peer1.conf
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wireguard/data/config/coredns/Corefile
@ -670,11 +674,7 @@ convert_jitsi() {
#### Convert Jitsi
echo -ne "\n* Converting jitsi.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/jitsi/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/jitsi/.env
# FIXME check if Jitsi really needs upper-case DC. If we can use lower case dc like everywhere else,
# we can avoid generating DOMAIN_NEW_LDAP_DC
sed -i "s#$DOMAIN_LDAP_DC#$DOMAIN_NEW_LDAP_DC#g" /federated/apps/jitsi/.env
convert_generic jitsi
start_service_convert "jitsi" "nc -z 192.168.0.25 443 &> /dev/null"
@ -684,8 +684,7 @@ convert_baserow() {
#### Convert Baserow
echo -ne "\n* Converting baserow.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/baserow/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/baserow/.env
convert_generic baserow
docker exec postgresql bash -c "psql -U baserow -c \"update auth_user set username='admin@$DOMAIN_NEW' where username='admin@$DOMAIN'\"" &> /dev/null
[ $? -ne 0 ] && fail "Couldn't update auth_user table in baserow"
@ -700,8 +699,7 @@ convert_gitea() {
#### Convert Gitea
echo -ne "\n* Converting gitea.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/gitea/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/gitea/.env
convert_generic gitea
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/gitea/data/data/gitea/conf/app.ini
# Replace users in Gitea postgres database with new domain name
@ -733,8 +731,7 @@ convert_caddy() {
#### Convert Caddy
echo -ne "\n* Converting caddy.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/caddy/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/caddy/.env
convert_generic caddy
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/caddy/data/etc/caddy/Caddyfile
# Grab the container IP from docker-compose
@ -749,8 +746,7 @@ convert_castopod() {
#### Convert Castopod
echo -ne "\n* Converting castopod.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/castopod/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/castopod/.env
convert_generic castopod
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/castopod/docker-compose.yml | awk '{ print $2 }'`
@ -768,8 +764,7 @@ convert_autodiscover() {
#### Convert Autodiscover
echo -ne "\n* Converting autodiscover.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/autodiscover/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/autodiscover/.env
convert_generic autodiscover
sed -i "s#COMPANY_NAME=.*#COMPANY_NAME=$ORG_NEW#g" /federated/apps/autodiscover/.env
# Add DNS records for auto discovery
@ -804,8 +799,7 @@ convert_wordpress() {
#### Convert Wordpress
echo -ne "\n* Converting wordpress.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wordpress/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wordpress/.env
convert_generic wordpress
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/wordpress/data/bitnami/wordpress/wp-config.php
sed -i "s#WORDPRESS_BLOG_NAME=.*#WORDPRESS_BLOG_NAME=$ORG_NEW#g" /federated/apps/wordpress/.env
@ -828,8 +822,7 @@ convert_coturn() {
#### Convert Coturn
echo -ne "\n* Converting coturn.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/coturn/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/coturn/.env
convert_generic coturn
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/coturn/data/etc/turnserver.conf
sed -i "s#static-auth-secret=.*#static-auth-secret=$COTURN_MATRIX_SECRET#g" /federated/apps/coturn/data/etc/turnserver.conf
@ -845,8 +838,7 @@ convert_bookstack() {
#### Convert Bookstack
echo -ne "\n* Converting bookstack.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/bookstack/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/bookstack/.env
convert_generic bookstack
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/bookstack/data/config/www/.env
docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD bookstack -e \"update users set email='admin@$DOMAIN_NEW' where id = 1;\""
@ -875,8 +867,7 @@ convert_freescout() {
#### Convert Freescout
echo -ne "\n* Converting freescout.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/freescout/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/freescout/.env
convert_generic freescout
docker exec postgresql bash -c "psql -U freescout -c \"update users set email='admin@$DOMAIN_NEW' where id='1'\""
@ -892,8 +883,7 @@ convert_msp() {
#### Convert MSP
echo -ne "\n* Converting msp.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/msp/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/msp/.env
convert_generic msp
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/msp/docker-compose.yml | awk '{ print $2 }'`
@ -1033,8 +1023,7 @@ convert_dashboard() {
#### Convert Dashboard
echo -ne "\n* Converting dashboard.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/dashboard/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/dashboard/.env
convert_generic dashboard
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/dashboard/docker-compose.yml | awk '{ print $2 }'`
@ -1048,8 +1037,7 @@ convert_roundcube() {
#### Convert Roundcube
echo -ne "\n* Converting roundcube.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/roundcube/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/roundcube/.env
convert_generic roundcube
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/roundcube/data/var/www/html/config/config.inc.php
# Grab the container IP from docker-compose
@ -1064,13 +1052,10 @@ convert_authelia() {
#### Convert Authelia
echo -ne "\n* Converting authelia.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/authelia/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/authelia/.env
convert_generic authelia
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/authelia/data/config/configuration.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/authelia/data/config/idproviders.yml
sed -i "s#$DOMAIN_LDAP_dc#$DOMAIN_NEW_LDAP_dc#g" /federated/apps/authelia/.env
# Configure SSO to Authelia
# Delete the entries in the pdns settings table
[[ -d "/federated/apps/pdnsmysql/data/var/lib/mysql/pdnsadmin" ]] && POWERDNS_DB="pdnsadmin" || POWERDNS_DB="pdns"
@ -1110,8 +1095,7 @@ convert_jitsiopenid() {
#### Convert JitsiOpenID
echo -ne "\n* Converting jitsiopenid.."
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/jitsiopenid/docker-compose.yml
sed -i "s#$DOMAIN#$DOMAIN_NEW#g" /federated/apps/jitsiopenid/.env
convert_generic jitsiopenid
# Grab the container IP from docker-compose
SERVICE_IP=`grep ipv4_address /federated/apps/jitsiopenid/docker-compose.yml | awk '{ print $2 }'`