From 6d18d4916db51032d3a0fef14accb26a0af18462 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 26 Feb 2024 16:09:46 +0000 Subject: [PATCH] Added jitsi, gitea, caddy, to support installapp and uninstallapp --- lib/caddy.sh | 93 +++++++ lib/caddy.sh.old | 116 +++++++++ lib/gitea.sh | 107 +++++++- lib/gitea.sh.old | 186 ++++++++++++++ lib/jitsi.sh | 98 +++++++- lib/jitsi.sh.old | 622 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1216 insertions(+), 6 deletions(-) create mode 100644 lib/caddy.sh.old create mode 100644 lib/gitea.sh.old create mode 100644 lib/jitsi.sh.old diff --git a/lib/caddy.sh b/lib/caddy.sh index ab7b951..aeb9847 100644 --- a/lib/caddy.sh +++ b/lib/caddy.sh @@ -3,6 +3,7 @@ # Caddy Service PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +get_appvars config_caddy() { echo -ne "\n* Configuring /federated/apps/caddy container.." @@ -107,6 +108,98 @@ EOF kill -9 $SPINPID &> /dev/null echo -ne "done." } +email_caddy() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Caddy is now installed on $DOMAIN

+

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

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Caddycaddy.$DOMAINNo login/td> + No loginClick hereCaddy is a powerful, enterprise-ready, open source web server
+

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" +} +uninstall_caddy() { + echo -ne "* Uninstalling caddy container.." + spin & + SPINPID=$! + + # First stop the service + cd /federated/apps/caddy && docker-compose -f docker-compose.yml -p caddy down &> /dev/null + + # Delete the app directory + rm -rf /federated/apps/caddy + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} start_caddy() { # Start service with command and retry amount to make sure it's up before proceeding start_service "caddy" "nc -z 172.99.0.31 80 &> /dev/null" "7" diff --git a/lib/caddy.sh.old b/lib/caddy.sh.old new file mode 100644 index 0000000..ab7b951 --- /dev/null +++ b/lib/caddy.sh.old @@ -0,0 +1,116 @@ +#!/bin/bash +# +# Caddy Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +config_caddy() { + echo -ne "\n* Configuring /federated/apps/caddy container.." + spin & + SPINPID=$! + + if [ ! -d "/federated/apps/caddy" ]; then + mkdir -p /federated/apps/caddy/data/data + mkdir -p /federated/apps/caddy/data/srv + mkdir -p /federated/apps/caddy/data/etc/caddy + fi + +cat > /federated/apps/caddy/docker-compose.yml < /federated/apps/caddy/.env < /federated/apps/caddy/data/etc/caddy/Caddyfile < /dev/null +echo -ne "done." +} +start_caddy() { + # Start service with command and retry amount to make sure it's up before proceeding + start_service "caddy" "nc -z 172.99.0.31 80 &> /dev/null" "7" + + kill -9 $SPINPID &> /dev/null + echo -ne "done." +} diff --git a/lib/gitea.sh b/lib/gitea.sh index 721fa32..5815984 100644 --- a/lib/gitea.sh +++ b/lib/gitea.sh @@ -15,6 +15,7 @@ config_gitea() { touch /federated/apps/gitea/data/data/git/.ssh/authorized_keys chmod 600 /federated/apps/gitea/data/data/git/.ssh/authorized_keys fi + get_appvars cat > /federated/apps/gitea/docker-compose.yml < /federated/apps/gitea/.env < /federated/apps/gitea/data/creategitea.sh < /dev/null +docker exec postgresql psql -U postgres -c "CREATE DATABASE gitea" &> /dev/null +docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE gitea TO gitea" &> /dev/null kill -9 $SPINPID &> /dev/null echo -ne "done." } +email_gitea() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Gitea is now installed on $DOMAIN

+

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

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Giteagitea.$DOMAINadmin@$DOMAIN
admin password above
User access is separate from panelClick hereGitea is a code repository system similar to GitHub
+

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" +} +uninstall_gitea() { + echo -ne "* Uninstalling gitea container.." + spin & + SPINPID=$! + + # First stop the service + cd /federated/apps/gitea && docker-compose -f docker-compose.yml -p gitea down &> /dev/null + + # Delete database and user in postgresql + docker exec postgresql psql -U postgres -c "DROP DATABASE gitea" &> /dev/null + docker exec postgresql psql -U postgres -c "DROP USER gitea" &> /dev/null + + # Delete the app directory + rm -rf /federated/apps/gitea + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} start_gitea() { # Start service with command to make sure it's up before proceeding start_service "gitea" "nc -z 172.99.0.30 3000 &> /dev/null" "7" @@ -177,6 +279,7 @@ start_gitea() { # Create token to use for Caddy starting up next GITEA_TOKEN_1=`docker exec gitea curl -H "Content-Type: application/json" -d '{"name":"gitea1","scopes":["all"]}' -u gitea:$ADMINPASS http://gitea.$DOMAIN:3000/api/v1/users/gitea/tokens 2>/dev/null | awk -F: '{ print $4 }' | awk -F\" '{ print $2 }'` &> /dev/null [ $? -ne 0 ] && fail "Couldn't run gitea curl to get token inside /federated/apps/gitea container" + echo "$GITEA_TOKEN_1" > /federated/apps/gitea/.gitea.token.1 # Remove creategitea.sh rm /federated/apps/gitea/data/data/creategitea.sh diff --git a/lib/gitea.sh.old b/lib/gitea.sh.old new file mode 100644 index 0000000..721fa32 --- /dev/null +++ b/lib/gitea.sh.old @@ -0,0 +1,186 @@ +#!/bin/bash +# +# Gitea Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +config_gitea() { + echo -ne "\n* Configuring /federated/apps/gitea container.." + spin & + SPINPID=$! + + if [ ! -d "/federated/apps/gitea" ]; then + mkdir -p /federated/apps/gitea/data/data + mkdir -p /federated/apps/gitea/data/data/git/.ssh + touch /federated/apps/gitea/data/data/git/.ssh/authorized_keys + chmod 600 /federated/apps/gitea/data/data/git/.ssh/authorized_keys + fi + +cat > /federated/apps/gitea/docker-compose.yml < /federated/apps/gitea/.env < /federated/apps/gitea/data/creategitea.sh </dev/null | awk -F: '{ print \$4 }' | awk -F\" '{ print \$2 }'\` + +# Create the repository website, blog, and documentation +curl -k -X POST http://gitea.$DOMAIN:3000/api/v1/user/repos -H "content-type: application/json" -H "Authorization: token \$GITEA_TOKEN_2" --data '{"name":"www","auto_init":true,"default_branch":"master","private":true}' +curl -k -X POST http://gitea.$DOMAIN:3000/api/v1/user/repos -H "content-type: application/json" -H "Authorization: token \$GITEA_TOKEN_2" --data '{"name":"blog","auto_init":true,"default_branch":"master","private":true}' +curl -k -X POST http://gitea.$DOMAIN:3000/api/v1/user/repos -H "content-type: application/json" -H "Authorization: token \$GITEA_TOKEN_2" --data '{"name":"documentation","auto_init":true,"default_branch":"master","private":true}' + +# Create the webhook inside the www repository +curl -X 'POST' \ + 'http://gitea.$DOMAIN:3000/api/v1/repos/gitea/www/hooks' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -H "Authorization: token \$GITEA_TOKEN_2" \ + -d '{ + "active": true, + "config": { + "content_type": "json", + "url": "https://caddy.$DOMAIN/webhook", + "secret": "$WEBHOOK_SECRET" + }, + "events": [ + "push" + ], + "type": "gitea" +}' + +# Create the webhook inside the blog repository +curl -X 'POST' \ + 'http://gitea.$DOMAIN:3000/api/v1/repos/gitea/blog/hooks' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -H "Authorization: token \$GITEA_TOKEN_2" \ + -d '{ + "active": true, + "config": { + "content_type": "json", + "url": "https://blog.$DOMAIN/webhook", + "secret": "$WEBHOOK_SECRET" + }, + "events": [ + "push" + ], + "type": "gitea" +}' + +# Create the webhook inside the documentation repository +curl -X 'POST' \ + 'http://gitea.$DOMAIN:3000/api/v1/repos/gitea/documentation/hooks' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -H "Authorization: token \$GITEA_TOKEN_2" \ + -d '{ + "active": true, + "config": { + "content_type": "json", + "url": "https://documentation.$DOMAIN/webhook", + "secret": "$WEBHOOK_SECRET" + }, + "events": [ + "push" + ], + "type": "gitea" +}' +EOF + +chmod +x /federated/apps/gitea/data/creategitea.sh + +kill -9 $SPINPID &> /dev/null +echo -ne "done." +} +start_gitea() { + # Start service with command to make sure it's up before proceeding + start_service "gitea" "nc -z 172.99.0.30 3000 &> /dev/null" "7" + + # Copy creategitea.sh inside gitea container + mv /federated/apps/gitea/data/creategitea.sh /federated/apps/gitea/data/data/creategitea.sh + [ $? -ne 0 ] && fail "Couldn't mv creategitea.sh inside /federated/apps/gitea container" + + # Create admin user gitea + docker exec --user 1000 gitea gitea admin user create --admin --username gitea --password $ADMINPASS --email admin@$DOMAIN &> /dev/null + [ $? -ne 0 ] && fail "Couldn't run gitea user create inside /federated/apps/gitea container" + + # Run creategitea.sh inside gitea container + docker exec gitea /data/creategitea.sh &> /dev/null + [ $? -ne 0 ] && fail "Couldn't run creategitea.sh inside /federated/apps/gitea container" + + # Create token to use for Caddy starting up next + GITEA_TOKEN_1=`docker exec gitea curl -H "Content-Type: application/json" -d '{"name":"gitea1","scopes":["all"]}' -u gitea:$ADMINPASS http://gitea.$DOMAIN:3000/api/v1/users/gitea/tokens 2>/dev/null | awk -F: '{ print $4 }' | awk -F\" '{ print $2 }'` &> /dev/null + [ $? -ne 0 ] && fail "Couldn't run gitea curl to get token inside /federated/apps/gitea container" + + # Remove creategitea.sh + rm /federated/apps/gitea/data/data/creategitea.sh + + kill -9 $SPINPID &> /dev/null + echo -ne "done." +} diff --git a/lib/jitsi.sh b/lib/jitsi.sh index a66fb57..cc7dcff 100644 --- a/lib/jitsi.sh +++ b/lib/jitsi.sh @@ -3,6 +3,7 @@ # Jitsi Service PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +get_appvars config_jitsi() { echo -ne "\n* Configuring /federated/apps/jitsi container.." @@ -379,8 +380,6 @@ networks: external: true EOF -LDAP_SECRET=`cat /federated/apps/ldap/.ldap.secret` - # Create Jitsi .env file cat > /federated/apps/jitsi/.env < /dev/null echo -ne "done." } +email_jitsi() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Jitsi is now installed on $DOMAIN

+

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

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Jitsijitsi.$DOMAINadmin
admin password above
All users in panel have access using 'username'Click hereJitsi is a zoom replacement video conferencing solution
+

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" +} +uninstall_jitsi() { + echo -ne "* Uninstalling jitsi container.." + spin & + SPINPID=$! + + # First stop the service + cd /federated/apps/jitsi && docker-compose -f docker-compose.yml -p jitsi down &> /dev/null + + # Delete the app directory + rm -rf /federated/apps/jitsi + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} start_jitsi() { # Start service with command to make sure it's up before proceeding start_service "jitsi" "nc -z 172.99.0.25 443 &> /dev/null" "8" diff --git a/lib/jitsi.sh.old b/lib/jitsi.sh.old new file mode 100644 index 0000000..a66fb57 --- /dev/null +++ b/lib/jitsi.sh.old @@ -0,0 +1,622 @@ +#!/bin/bash +# +# Jitsi Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +config_jitsi() { + echo -ne "\n* Configuring /federated/apps/jitsi container.." + spin & + SPINPID=$! + + if [ ! -d "/federated/apps/jitsi" ]; then + mkdir -p /federated/apps/jitsi +# mkdir -p /federated/apps/jitsi/data/config/keys &> /dev/null +# cp -rf /federated/apps/dns/data/etc/letsencrypt/archive/$DOMAIN/*.pem apps/jitsi/data/config/keys +# mv /federated/apps/jitsi/data/config/keys/fullchain1.pem apps/jitsi/data/config/keys/cert.crt +# mv /federated/apps/jitsi/data/config/keys/privkey1.pem apps/jitsi/data/config/keys/cert.key +# chmod 644 /federated/apps/jitsi/data/config/keys/*.pem + fi + +# Extract Jitsi into /federated/apps/jitsi +tar zxvf /federated/lib/files/jitsi/stable-* --strip-components 1 -C /federated/apps/jitsi &> /dev/null +[ $? -ne 0 ] && fail "Couldn't extract files/jitsi/stable* into /federated/apps/jitsi" + +# Create docker compose file +cat > /federated/apps/jitsi/docker-compose.yml < /federated/apps/jitsi/.env < /dev/null +echo -ne "done." +} + +start_jitsi() { + # Start service with command to make sure it's up before proceeding + start_service "jitsi" "nc -z 172.99.0.25 443 &> /dev/null" "8" + + kill -9 $SPINPID &> /dev/null + echo -ne "done." +}