From ceacacb9d3fd394b335c3eafdf393d3c49d69982 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 7 Dec 2023 16:26:44 +0000 Subject: [PATCH] First go of installapp --- bin/installapp | 27 ++++++++++++ lib/bookstack.sh | 106 +++++++++++++++++++++++++++++++++++++++++------ lib/espocrm.sh | 90 +++++++++++++++++++++++++++++++++++++--- lib/freescout.sh | 96 ++++++++++++++++++++++++++++++++++++++---- lib/msp.sh | 87 ++++++++++++++++++++++++++++++++++++-- lib/pdns.sh | 2 +- lib/wordpress.sh | 106 ++++++++++++++++++++++++++++++++++++++++++----- 7 files changed, 473 insertions(+), 41 deletions(-) create mode 100755 bin/installapp diff --git a/bin/installapp b/bin/installapp new file mode 100755 index 0000000..eac5dcd --- /dev/null +++ b/bin/installapp @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Installs app if not already installed +. /etc/federated +. /federated/lib/functions.sh +trap cleanup `seq 1 15` + +usage() { +cat << EOF +Install application +Usage: $0 appname +Arguments: + appname Application to install. bookstack,espocrm,freescout,etc + +EOF +exit 2; +} + +[ $# != 1 ] && usage +APP=$1 + +[ ! -f /federated/lib/$APP.sh ] && failcheck "/federated/lib/$APP.sh doesn't exist." +[ -d /federated/apps/$APP ] && failcheck "/federated/apps/$APP already exists. $APP is installed?" +. /federated/lib/$APP.sh +config_$APP +start_$APP +email_$APP diff --git a/lib/bookstack.sh b/lib/bookstack.sh index 2b200d1..73ed0a9 100644 --- a/lib/bookstack.sh +++ b/lib/bookstack.sh @@ -5,7 +5,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin config_bookstack() { - echo -ne "\n* Configuring /federated/apps/bookstack container.." + echo -ne "\n* Configuring bookstack container.." spin & SPINPID=$! @@ -45,6 +45,8 @@ ADMINPASS=`cat /federated/apps/panel/.env | grep SMTP_PASSWORD | awk -F= '{ prin BOOKSTACK_ADMINPASSWORD=`htpasswd -bnBC 10 "" $ADMINPASS | tr -d ':\n' | sed 's/$2y/$2b/'` BOOKSTACK_SECRET=$(create_password); MYSQL_ROOTPASSWORD=`cat /federated/apps/pdnsmysql/.env | grep MYSQL_ROOT_PASSWORD | awk -F= '{ print $2 }'` +# Set SMTP user based on if fcore exists +[[ $(docker exec ldap slapcat | grep fcore) ]] && SMTPUSER="fcore" || SMTPUSER="admin" cat > /federated/apps/bookstack/.env < /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e \"CREATE USER 'bookstack'@'%' IDENTIFIED BY '$BOOKSTACK_SECRET';\"" &> /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e \"grant all privileges on bookstack.* to 'bookstack'@'%';\"" &> /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e 'flush privileges;'" &> /dev/null kill -9 $SPINPID &> /dev/null -echo -ne "done." +echo -ne "done.\n" } start_bookstack() { # Start service with command to make sure it's up before proceeding start_service "bookstack" "nc -z 172.99.0.36 80 &> /dev/null" "7" - docker exec pdns pdnsutil add-record $DOMAIN bookstack A 86400 $EXTERNALIP + docker exec pdns pdnsutil add-record $DOMAIN bookstack A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for bookstack" - docker exec pdns pdnsutil add-record $DOMAIN documentation A 86400 $EXTERNALIP + docker exec pdns pdnsutil add-record $DOMAIN documentation A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for bookstack" - PDNS_MYSQL_COMMAND="update users set password=\"$BOOKSTACK_ADMINPASSWORD\" where id = \"1\";" - docker exec pdnsmysql bash -c "mysql -ubookstack -p$BOOKSTACK_SECRET bookstack -e '$PDNS_MYSQL_COMMAND;'" - docker exec pdnsmysql bash -c "mysql -ubookstack -p$BOOKSTACK_SECRET bookstack -e \"update users set email='admin@$DOMAIN' where id = 1;\"" + PDNS_MYSQL_COMMAND="update users set password=\"$BOOKSTACK_ADMINPASSWORD\" where id = \"1\";" &> /dev/null + docker exec pdnsmysql bash -c "mysql -ubookstack -p$BOOKSTACK_SECRET bookstack -e '$PDNS_MYSQL_COMMAND;'" &> /dev/null + docker exec pdnsmysql bash -c "mysql -ubookstack -p$BOOKSTACK_SECRET bookstack -e \"update users set email='admin@$DOMAIN' where id = 1;\"" &> /dev/null # Set mail configuration sed -i "s#MAIL_FROM=.*#MAIL_FROM=admin@$DOMAIN#g" /federated/apps/bookstack/data/config/www/.env @@ -101,5 +103,83 @@ start_bookstack() { sed -i "s#MAIL_ENCRYPTION=.*#MAIL_ENCRYPTION=TLS#g" /federated/apps/bookstack/data/config/www/.env kill -9 $SPINPID &> /dev/null - echo -ne "done." + echo -ne "done.\n" +} +email_bookstack() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Bookstack is now installed on $DOMAIN

+

+Here is your applications chart with on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Bookstackbookstack.$DOMAINadmin@$DOMAIN
$ADMINPASS
User access is separate from panelClick hereBookstack is a simple, open-source, self-hosted, easy-to-use platform (Wiki) for organising and storing information
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" } diff --git a/lib/espocrm.sh b/lib/espocrm.sh index 7d7e279..8e5b2e3 100644 --- a/lib/espocrm.sh +++ b/lib/espocrm.sh @@ -5,7 +5,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin config_espocrm() { - echo -ne "\n* Configuring /federated/apps/espocrm container.." + echo -ne "\n* Configuring espocrm container.." spin & SPINPID=$! @@ -46,6 +46,8 @@ EXTERNALIP=$(get_externalip); ESPOCRM_SECRET=$(create_password); MYSQL_ROOTPASSWORD=`cat /federated/apps/pdnsmysql/.env | grep MYSQL_ROOT_PASSWORD | awk -F= '{ print $2 }'` LDAP_SECRET=`cat /federated/apps/ldap/.ldap.secret` +# Set SMTP user based on if fcore exists +[[ $(docker exec ldap slapcat | grep fcore) ]] && SMTPUSER="fcore" || SMTPUSER="admin" cat > /federated/apps/espocrm/.env < /dev/null -echo -ne "done." +echo -ne "done.\n" } start_espocrm() { # Start service with command to make sure it's up before proceeding start_service "espocrm" "nc -z 172.99.0.39 80 &> /dev/null" "7" - docker exec pdns pdnsutil add-record $DOMAIN espocrm A 86400 $EXTERNALIP + docker exec pdns pdnsutil add-record $DOMAIN espocrm A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for espocrm" kill -9 $SPINPID &> /dev/null - echo -ne "done." + echo -ne "done.\n" +} +email_espocrm() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

EspoCRM is now installed on $DOMAIN

+

+Here is your applications chart with on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
EspoCRMespocrm.$DOMAINadmin@$DOMAIN
admin password above
All users in panel can access EspoCRM using user@$DOMAINClick hereEspoCRM is an Open Source CRM (Customer Relationship Management) software that allows you to see, enter and evaluate all your company relationships
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" } diff --git a/lib/freescout.sh b/lib/freescout.sh index 2cd75b2..c26e7e5 100644 --- a/lib/freescout.sh +++ b/lib/freescout.sh @@ -5,7 +5,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin config_freescout() { - echo -ne "\n* Configuring /federated/apps/freescout container.." + echo -ne "\n* Configuring freescout container.." spin & SPINPID=$! @@ -45,6 +45,8 @@ EOF ADMINPASS=`cat /federated/apps/panel/.env | grep SMTP_PASSWORD | awk -F= '{ print $2 }'` EXTERNALIP=$(get_externalip); FREESCOUT_SECRET=$(create_password); +# Set SMTP user based on if fcore exists +[[ $(docker exec ldap slapcat | grep fcore) ]] && SMTPUSER="fcore" || SMTPUSER="admin" cat > /federated/apps/freescout/.env < /dev/null +docker exec postgresql psql -U postgres -c "CREATE DATABASE freescout" &> /dev/null +docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE freescout TO freescout" &> /dev/null kill -9 $SPINPID &> /dev/null -echo -ne "done." +echo -ne "done.\n" } start_freescout() { # Start service with command to make sure it's up before proceeding start_service "freescout" "nc -z 172.99.0.37 80 &> /dev/null" "7" - docker exec pdns pdnsutil add-record $DOMAIN freescout A 86400 $EXTERNALIP + docker exec pdns pdnsutil add-record $DOMAIN freescout A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for freescout" kill -9 $SPINPID &> /dev/null - echo -ne "done." + echo -ne "done.\n" +} +email_freescout() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Freescout is now installed on $DOMAIN

+

+Here is your applications chart with on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Freescoutfreescout.$DOMAINadmin@$DOMAIN
$ADMINPASS
User access is separate from panelClick hereFreeScout is the super lightweight and powerful free open source help desk
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" } diff --git a/lib/msp.sh b/lib/msp.sh index 4158dbe..b9ee71b 100644 --- a/lib/msp.sh +++ b/lib/msp.sh @@ -5,7 +5,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin config_msp() { - echo -ne "\n* Configuring /federated/apps/msp container.." + echo -ne "\n* Configuring msp container.." spin & SPINPID=$! @@ -13,6 +13,7 @@ config_msp() { mkdir -p /federated/apps/msp/data fi +EXTERNALIP=$(get_externalip); ADMINPASS=`cat /federated/apps/panel/.env | grep SMTP_PASSWORD | awk -F= '{ print $2 }'` TRAEFIK_HTTPAUTH_STRING_MSP=$(echo `htpasswd -nb admin@$DOMAIN $ADMINPASS` | sed -e s/\\$/\\$\\$/g) @@ -61,15 +62,93 @@ EOF chmod 600 /federated/apps/msp/.env kill -9 $SPINPID &> /dev/null -echo -ne "done." +echo -ne "done.\n" } start_msp() { # Start service with command to make sure it's up before proceeding start_service "msp" "nc -z 172.99.0.38 3000 &> /dev/null" "7" - docker exec pdns pdnsutil add-record $DOMAIN msp A 86400 $EXTERNALIP + docker exec pdns pdnsutil add-record $DOMAIN msp A 86400 $EXTERNALIP &> /dev/null [ $? -ne 0 ] && fail "Couldn't add dns record for msp" kill -9 $SPINPID &> /dev/null - echo -ne "done." + echo -ne "done.\n" +} +email_msp() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

MSP (Music Side Project) is now installed on $DOMAIN

+

+Here is your applications chart with on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Music Side Projectmsp.$DOMAINadmin@$DOMAIN
$ADMINPASS
User access is separate from panelClick hereMusic Side Project Studio enables you to harness the potential of RSS feeds and the Lightning Network, allowing you to self-host your music and receive direct payment from your fans
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" } diff --git a/lib/pdns.sh b/lib/pdns.sh index d42ca2d..69b2af4 100644 --- a/lib/pdns.sh +++ b/lib/pdns.sh @@ -79,7 +79,7 @@ curl -X PATCH --data '{"rrsets": [ {"name": "$DOMAIN.", "type": "MX", "ttl": 864 curl -X PATCH --data '{"rrsets": [ {"name": "$DOMAIN.", "type": "TXT", "ttl": 86400, "changetype": "REPLACE", "records": [ {"content": "\"v=spf1 mx a:$DOMAIN ~all\"", "disabled": false } ] } ] }' -H 'X-API-Key: $PDNS_APIKEY' http://127.0.0.1:8081/api/v1/servers/localhost/zones/$DOMAIN. # Create the A records for domain -for i in ns1 ns2 pdnsadmin powerdns traefik mail www computer panel nextcloud collabora jitsi matrix element listmonk vaultwarden vpn wireguard baserow gitea blog documentation castopod podcasts caddy; do +for i in ns1 ns2 pdnsadmin powerdns traefik mail computer panel nextcloud collabora jitsi matrix element listmonk vaultwarden vpn wireguard baserow gitea blog documentation castopod podcasts caddy; do curl -X PATCH --data "{\"rrsets\": [ {\"name\": \"\$i.$DOMAIN.\", \"type\": \"A\", \"ttl\": 86400, \"changetype\": \"REPLACE\", \"records\": [ {\"content\": \"$EXTERNALIP\", \"disabled\": false } ] } ] }" -H 'X-API-Key: $PDNS_APIKEY' http://127.0.0.1:8081/api/v1/servers/localhost/zones/$DOMAIN. done diff --git a/lib/wordpress.sh b/lib/wordpress.sh index 1ed606a..05468cc 100644 --- a/lib/wordpress.sh +++ b/lib/wordpress.sh @@ -5,7 +5,7 @@ PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin config_wordpress() { - echo -ne "\n* Configuring /federated/apps/wordpress container.." + echo -ne "\n* Configuring wordpress container.." spin & SPINPID=$! @@ -33,7 +33,7 @@ services: - ./data/bitnami/wordpress:/bitnami/wordpress labels: - "traefik.enable=true" - - "traefik.http.routers.wordpress.rule=Host(\`www.$DOMAIN\`,\`$DOMAIN\`)" + - "traefik.http.routers.wordpress.rule=Host(\`www.$DOMAIN\`,\`$DOMAIN\`,\`wordpress.$DOMAIN\`)" - "traefik.http.routers.wordpress.entrypoints=websecure" - "traefik.http.routers.wordpress.tls.certresolver=letsencrypt" - "traefik.http.services.wordpress.loadbalancer.server.port=8080" @@ -43,9 +43,12 @@ networks: external: true EOF +ADMINPASS=`cat /federated/apps/panel/.env | grep SMTP_PASSWORD | awk -F= '{ print $2 }'` +EXTERNALIP=$(get_externalip); WORDPRESS_SECRET=$(create_password); MYSQL_ROOTPASSWORD=`cat /federated/apps/pdnsmysql/.env | grep MYSQL_ROOT_PASSWORD | awk -F= '{ print $2 }'` -ADMINPASS=`cat /federated/apps/castopod/.env | grep CP_EMAIL_SMTP_PASSWORD | awk -F= '{ print $2 }'` +# Set SMTP user based on if fcore exists +[[ $(docker exec ldap slapcat | grep fcore) ]] && SMTPUSER="fcore" || SMTPUSER="admin" cat > /federated/apps/wordpress/.env < /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e \"CREATE USER 'wordpress'@'%' IDENTIFIED BY '$WORDPRESS_SECRET';\"" &> /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e \"grant all privileges on wordpress.* to 'wordpress'@'%';\"" &> /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e 'flush privileges;'" &> /dev/null kill -9 $SPINPID &> /dev/null -echo -ne "done." +echo -ne "done.\n" } start_wordpress() { # Start service with command to make sure it's up before proceeding @@ -83,6 +86,89 @@ start_wordpress() { chmod -R 755 /federated/apps/wordpress/data/bitnami/wordpress/wp-content chmod 740 /federated/apps/wordpress/data/bitnami/wordpress/wp-config.php + docker exec pdns pdnsutil add-record $DOMAIN www A 86400 $EXTERNALIP &> /dev/null + [ $? -ne 0 ] && fail "Couldn't add dns record for freescout" + docker exec pdns pdnsutil add-record $DOMAIN wordpress A 86400 $EXTERNALIP &> /dev/null + [ $? -ne 0 ] && fail "Couldn't add dns record for freescout" + kill -9 $SPINPID &> /dev/null - echo -ne "done." + echo -ne "done.\n" +} +email_wordpress() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Wordpress is now installed on $DOMAIN

+

+Here is your applications chart with on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Wordpresswww.$DOMAIN/loginadmin@$DOMAIN
$ADMINPASS
User access is separate from panelClick hereWordpress is a dynamic content management solution used by 10s of millions of websites around the globe
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" }