From 639ba941f3a1c223c481f03b4dfc41c9fa52ddd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 3 Nov 2017 20:39:58 +0100 Subject: [PATCH] [Helper] Nextcloud helper script (wip) --- helper-scripts/nextcloud.sh | 116 ++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 helper-scripts/nextcloud.sh diff --git a/helper-scripts/nextcloud.sh b/helper-scripts/nextcloud.sh new file mode 100755 index 00000000..175f3cd5 --- /dev/null +++ b/helper-scripts/nextcloud.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +[[ -z ${1} ]] && { echo "No parameters given"; exit 1; } + +for bin in curl dirmngr; do + if [[ -z $(which ${bin}) ]]; then echo "Cannot find ${bin}, exiting..."; exit 1; fi +done + +while [ "$1" != '' ]; do + case "${1}" in + -p|--purge) NC_PURGE=y && shift;; + -i|--install) NC_INSTALL=y && shift;; + *) echo "Unknown parameter: ${1}" && shift;; + esac +done + +[[ ${NC_PURGE} == "y" ]] && [[ ${NC_INSTALL} == "y" ]] && { echo "Cannot use -p and -i at the same time"; } + +source ./mailcow.conf + +if [[ ${NC_PURGE} == "y" ]]; then + + docker exec -it $(docker ps -f name=mysql-mailcow -q) mysql -uroot -p${DBROOT} -e \ + "$(docker exec -it $(docker ps -f name=mysql-mailcow -q) mysql -uroot -p${DBROOT} -e "SELECT GROUP_CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME SEPARATOR ';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'nc_%' AND TABLE_SCHEMA = '${DBNAME}';" -BN)" + docker exec -it $(docker ps -f name=redis-mailcow -q) /bin/sh -c 'redis-cli KEYS "*nextcloud*" | xargs redis-cli DEL' + if [ -d ./data/web/nextcloud/config ]; then + mv ./data/web/nextcloud/config/ ./data/conf/nextcloud-config-folder-$(date +%s).bak + fi + [[ -d ./data/web/nextcloud ]] && rm -rf ./data/web/nextcloud + + [[ -f ./data/conf/nginx/site.nextcloud.custom ]] && mv ./data/conf/nginx/site.nextcloud.custom ./data/conf/nginx/site.nextcloud.custom-$(date +%s).bak + [[ -f ./data/conf/nginx/nextcloud.conf ]] && mv ./data/conf/nginx/nextcloud.conf ./data/conf/nginx/nextcloud.conf-$(date +%s).bak + + docker-compose restart nginx-mailcow + +elif [[ ${NC_INSTALL} == "y" ]]; then + + NC_TYPE= + while [[ ! ${NC_TYPE} =~ ^subfolder$|^subdomain$ ]]; do + read -p "Configure as subdomain or subfolder? [subdomain/subfolder] " NC_TYPE + done + + + if [[ ${NC_TYPE} == "subdomain" ]]; then + NC_SUBD= + while [[ -z ${NC_SUBD} ]]; do + read -p "Which subdomain? [format: nextcloud.domain.tld] " NC_SUBD + done + if ! ping -q -c2 ${NC_SUBD} > /dev/null 2>&1 ; then + read -p "Cannot ping subdomain, continue anyway? [y|N] " NC_CONT_FAIL + [[ ! ${NC_CONT_FAIL,,} =~ ^(yes|y)$ ]] && { echo "Ok, exiting..."; exit 1; } + fi + fi + + ADMIN_NC_PASS=$(