From f1680744f914190d5426ec93c692826548253aba Mon Sep 17 00:00:00 2001 From: ggeorgg Date: Thu, 13 Dec 2018 21:34:03 +0100 Subject: [PATCH] Replace almost all echos by printf function with color (#741) --- apps/adminer.sh | 6 +-- apps/collabora.sh | 22 ++++----- apps/fail2ban.sh | 8 +-- apps/fulltextsearch.sh | 6 +-- apps/netdata.sh | 4 +- apps/nextant.sh | 17 +++---- apps/onlyoffice.sh | 22 ++++----- apps/spreedme.sh | 8 +-- apps/talk.sh | 12 ++--- apps/tmbitwarden.sh | 4 +- apps/webmin.sh | 4 +- lets-encrypt/activate-ssl.sh | 4 +- lets-encrypt/test-new-config.sh | 2 +- lib.sh | 86 +++++++++++++++++---------------- nextcloud-startup-script.sh | 48 +++++++++--------- nextcloud_install_production.sh | 28 +++++------ nextcloud_update.sh | 40 +++++++-------- static/adduser.sh | 2 +- static/change_db_pass.sh | 6 +-- static/docker_overlay2.sh | 30 ++++++------ static/modsecurity.sh | 6 +-- static/security.sh | 4 +- 22 files changed, 184 insertions(+), 185 deletions(-) diff --git a/apps/adminer.sh b/apps/adminer.sh index 24f1c5d9..07668d72 100644 --- a/apps/adminer.sh +++ b/apps/adminer.sh @@ -2,13 +2,13 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing and securing Adminer..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +print_text_in_color "$Cyan" "Installing and securing Adminer..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -24,7 +24,7 @@ http2_warn Adminer # Check that the script can see the external IP (apache fails otherwise) if [ -z "$WANIP4" ] then - echo "WANIP4 is an emtpy value, Apache will fail on reboot due to this. Please check your network and try again" + print_text_in_color "$Red" "WANIP4 is an emtpy value, Apache will fail on reboot due to this. Please check your network and try again." sleep 3 exit 1 fi diff --git a/apps/collabora.sh b/apps/collabora.sh index c4b8be60..bf6115cf 100644 --- a/apps/collabora.sh +++ b/apps/collabora.sh @@ -2,8 +2,6 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing Collabora..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh @@ -11,6 +9,8 @@ NC_UPDATE=1 && COLLABORA_INSTALL=1 . <(curl -sL https://raw.githubusercontent.co unset NC_UPDATE unset COLLABORA_INSTALL +print_text_in_color "$Cyan" "Installing Collabora..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -42,7 +42,7 @@ msg_box "Before you start, please make sure that port 80+443 is directly forward apt update -q4 & spinner_loading # Check if Nextcloud is installed -echo "Checking if Nextcloud is installed..." +print_text_in_color "$Cyan" "Checking if Nextcloud is installed..." if ! curl -s https://"${NCDOMAIN//\\/}"/status.php | grep -q 'installed":true' then msg_box "It seems like Nextcloud is not installed or that you don't use https on: @@ -58,8 +58,7 @@ sudo bash collabora.sh" fi # Check if $SUBDOMAIN exists and is reachable -echo -echo "Checking if $SUBDOMAIN exists and is reachable..." +print_text_in_color "$Cyan" "Checking if $SUBDOMAIN exists and is reachable..." if wget -q -T 10 -t 2 --spider "$SUBDOMAIN"; then sleep 0.1 elif wget -q -T 10 -t 2 --spider --no-check-certificate "https://$SUBDOMAIN"; then @@ -162,11 +161,11 @@ HTTPS_CREATE if [ -f "$HTTPS_CONF" ]; then - echo "$HTTPS_CONF was successfully created" + print_text_in_color "$Green" "$HTTPS_CONF was successfully created." sleep 1 else - echo "Unable to create vhost, exiting..." - echo "Please report this issue here $ISSUES" + print_text_in_color "$Red" "Unable to create vhost, exiting..." + print_text_in_color "$Red" "Please report this issue here $ISSUES" exit 1 fi fi @@ -188,7 +187,7 @@ then # Install Collabora App occ_command app:install richdocuments else - printf "%b" "${IRed}It seems like no certs were generated, please report this issue here: $ISSUES\n${Color_Off}" + print_text_in_color "$Red" "It seems like no certs were generated, please report this issue here: $ISSUES" any_key "Press any key to continue... " restart_webserver fi @@ -209,11 +208,10 @@ then } > "$SCRIPTS/dockerprune.sh" chmod a+x "$SCRIPTS/dockerprune.sh" crontab -u root -l | { cat; echo "@weekly $SCRIPTS/dockerprune.sh"; } | crontab -u root - - echo "Docker automatic prune job added." - echo + print_text_in_color "$Cyan" "Docker automatic prune job added." service docker restart docker restart code - echo "Collabora is now successfully installed." + print_text_in_color "$Green" "Collabora is now successfully installed." any_key "Press any key to continue... " fi diff --git a/apps/fail2ban.sh b/apps/fail2ban.sh index 427a3a40..0fd698d7 100644 --- a/apps/fail2ban.sh +++ b/apps/fail2ban.sh @@ -3,14 +3,14 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ # Inspired by https://github.com/nextcloud/nextcloudpi/blob/master/etc/nextcloudpi-config.d/fail2ban.sh -echo "Installing Fail2ban..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) unset NC_UPDATE +print_text_in_color "$Cyan" "Installing Fail2ban..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -39,8 +39,8 @@ check_command update-rc.d fail2ban disable if [ -z "$NCLOG" ] then - echo "nextcloud.log not found" - echo "Please add your logpath to $NCPATH/config/config.php and restart this script." + print_text_in_color "$Red" "nextcloud.log not found" + print_text_in_color "$Red" "Please add your logpath to $NCPATH/config/config.php and restart this script." exit 1 else chown www-data:www-data "$NCLOG" diff --git a/apps/fulltextsearch.sh b/apps/fulltextsearch.sh index 4003b5d6..c076142e 100644 --- a/apps/fulltextsearch.sh +++ b/apps/fulltextsearch.sh @@ -3,8 +3,6 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ # SwITNet Ltd © - 2018, https://switnet.net/ -echo "Installing Elastic Search & Full Text Search on Nextcloud..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh @@ -12,6 +10,8 @@ NC_UPDATE=1 && ES_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextc unset NC_UPDATE unset ES_INSTALL +print_text_in_color "$Cyan" "Installing Elastic Search & Full Text Search on Nextcloud..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -51,7 +51,7 @@ fi # Reset Full Text Search to be able to index again, and also remove the app to be able to install it again if [ -d $NC_APPS_PATH/fulltextsearch ] then - echo "Removing old version of Full Text Search and resetting the app..." + print_text_in_color "$Cyan" "Removing old version of Full Text Search and resetting the app..." occ_command fulltextsearch:reset occ_command app:disable fulltextsearch rm -rf $NC_APPS_PATH/fulltextsearch diff --git a/apps/netdata.sh b/apps/netdata.sh index 3f195a28..d76d07f8 100644 --- a/apps/netdata.sh +++ b/apps/netdata.sh @@ -2,13 +2,13 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing Netdata..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +print_text_in_color "$Cyan" "Installing Netdata..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF diff --git a/apps/nextant.sh b/apps/nextant.sh index 7788e6af..ce536bea 100644 --- a/apps/nextant.sh +++ b/apps/nextant.sh @@ -41,28 +41,27 @@ Please report any bugs regarding the script to $ISSUES" # Make sure there is an Nextcloud installation if ! [ "$(occ_command -V)" ] then - echo "It seems there is no Nextcloud server installed, please check your installation." + print_text_in_color "$Red" "It seems there is no Nextcloud server installed, please check your installation." exit 1 fi # Check if it's a clean install if [ -d "$SOLR_HOME" ] then - echo - echo "It seems like $SOLR_HOME already exists. Have you already run this script?" - echo "If yes, revert all the settings and try again, it must be a clean install." + print_text_in_color "$Red" "It seems like $SOLR_HOME already exists. Have you already run this script?" + print_text_in_color "$Red" "If yes, revert all the settings and try again, it must be a clean install." exit 1 fi -echo "Starting to setup Solr & Nextant on Nextcloud..." +print_text_in_color "$Cyan" "Starting to setup Solr & Nextant on Nextcloud..." # Installing requirements apt update -q4 & spinner_loading apt install default-jre -y # Getting and installing Apache Solr -echo "Installing Apache Solr" -echo "It might take some time depending on your bandwith, please be patient..." +print_text_in_color "$Cyan" "Installing Apache Solr" +print_text_in_color "$Cyan" "It might take some time depending on your bandwith, please be patient..." mkdir -p "$SOLR_HOME" check_command cd "$SOLR_HOME" wget -q "$SOLR_DL" --show-progress @@ -72,7 +71,7 @@ then rm -rf "${SOLR_HOME:?}/$SOLR_RELEASE" wget -q https://raw.githubusercontent.com/apache/lucene-solr/master/solr/bin/install_solr_service.sh -P $SCRIPTS/ else - echo "Solr failed to install, something is wrong with the Solr installation" + print_text_in_color "$Red" "Solr failed to install, something is wrong with the Solr installation" exit 1 fi @@ -89,7 +88,7 @@ if service solr start then sudo -u solr /opt/solr/bin/solr create -c nextant else - echo "Solr failed to start, something is wrong with the Solr installation" + print_text_in_color "$Red" "Solr failed to start, something is wrong with the Solr installation" exit 1 fi diff --git a/apps/onlyoffice.sh b/apps/onlyoffice.sh index 2b706eea..9f3610a9 100644 --- a/apps/onlyoffice.sh +++ b/apps/onlyoffice.sh @@ -1,7 +1,5 @@ #!/bin/bash -echo "Installing OnlyOffice..." - # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ # shellcheck disable=2034,2059 @@ -11,6 +9,8 @@ NC_UPDATE=1 && OO_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextc unset NC_UPDATE unset OO_INSTALL +print_text_in_color "$Cyan" "Installing OnlyOffice..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -42,7 +42,7 @@ msg_box "Before you start, please make sure that port 80+443 is directly forward apt update -q4 & spinner_loading # Check if Nextcloud is installed -echo "Checking if Nextcloud is installed..." +print_text_in_color "$Cyan" "Checking if Nextcloud is installed..." if ! curl -s https://"${NCDOMAIN//\\/}"/status.php | grep -q 'installed":true' then msg_box "It seems like Nextcloud is not installed or that you don't use https on: @@ -57,8 +57,7 @@ sudo bash onlyoffice.sh" fi # Check if $SUBDOMAIN exists and is reachable -echo -echo "Checking if $SUBDOMAIN exists and is reachable..." +print_text_in_color "$Cyan" "Checking if $SUBDOMAIN exists and is reachable..." if wget -q -T 10 -t 2 --spider "$SUBDOMAIN"; then sleep 0.1 elif wget -q -T 10 -t 2 --spider --no-check-certificate "https://$SUBDOMAIN"; then @@ -151,11 +150,11 @@ HTTPS_CREATE if [ -f "$HTTPS_CONF" ]; then - echo "$HTTPS_CONF was successfully created" + print_text_in_color "$Green" "$HTTPS_CONF was successfully created." sleep 1 else - echo "Unable to create vhost, exiting..." - echo "Please report this issue here $ISSUES" + print_text_in_color "$Red" "Unable to create vhost, exiting..." + print_text_in_color "$Red" "Please report this issue here $ISSUES" exit 1 fi fi @@ -178,7 +177,7 @@ then cd "$NC_APPS_PATH" check_command git clone https://github.com/ONLYOFFICE/onlyoffice-nextcloud.git onlyoffice else - printf "%b" "${IRed}It seems like no certs were generated, please report this issue here: $ISSUES\n${Color_Off}" + print_text_in_color "$Red" "It seems like no certs were generated, please report this issue here: $ISSUES" any_key "Press any key to continue... " restart_webserver fi @@ -199,11 +198,10 @@ then } > "$SCRIPTS/dockerprune.sh" chmod a+x "$SCRIPTS/dockerprune.sh" crontab -u root -l | { cat; echo "@weekly $SCRIPTS/dockerprune.sh"; } | crontab -u root - - echo "Docker automatic prune job added." - echo + print_text_in_color "$Cyan" "Docker automatic prune job added." service docker restart docker restart onlyoffice - echo "OnlyOffice is now successfully installed." + print_text_in_color "$Green" "OnlyOffice is now successfully installed." any_key "Press any key to continue... " fi diff --git a/apps/spreedme.sh b/apps/spreedme.sh index 40f9bf1c..56edbf94 100644 --- a/apps/spreedme.sh +++ b/apps/spreedme.sh @@ -2,14 +2,14 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing Spreed.ME..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) unset NC_UPDATE +print_text_in_color "$Cyan" "Installing Spreed.ME..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -36,7 +36,7 @@ install_if_not snapd # Install Nextcloud Spreed.ME Snap if [ -d "$SNAPDIR" ] then - echo "Spreed.ME Snap already seems to be installed and will now be re-installed..." + print_text_in_color "$Cyan" "Spreed.ME Snap already seems to be installed and will now be re-installed..." snap remove spreedme rm -rf "$SNAPDIR" snap install --edge spreedme @@ -49,7 +49,7 @@ if [ -d "$NC_APPS_PATH/spreedme" ] then # Remove occ_command app:disable spreedme - echo "Spreed.ME app already seems to be installed and will now be re-installed..." + print_text_in_color "$Cyan" "Spreed.ME app already seems to be installed and will now be re-installed..." rm -R "$NC_APPS_PATH/spreedme" # Reinstall occ_command app:install spreedme diff --git a/apps/talk.sh b/apps/talk.sh index a152c2c1..ed62f9ee 100644 --- a/apps/talk.sh +++ b/apps/talk.sh @@ -2,8 +2,6 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing Nextcloud Talk..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh @@ -11,6 +9,8 @@ NC_UPDATE=1 && TURN_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nex unset NC_UPDATE unset TURN_INSTALL +print_text_in_color "$Cyan" "Installing Nextcloud Talk..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -24,7 +24,7 @@ root_check lowest_compatible_nc 13 # Check if Nextcloud is installed -echo "Checking if Nextcloud is installed..." +print_text_in_color "$Cyan" "Checking if Nextcloud is installed..." if ! curl -s https://"${TURN_DOMAIN//\\/}"/status.php | grep -q 'installed":true' then msg_box "It seems like Nextcloud is not installed or that you don't use https on: @@ -110,10 +110,10 @@ log-file=/var/log/turnserver.log TURN_CREATE if [ -f "$TURN_CONF" ]; then - echo "$TURN_CONF was successfully created" + print_text_in_color "$Green" "$TURN_CONF was successfully created." else - echo "Unable to create $TURN_CONF, exiting..." - echo "Please report this issue here $ISSUES" + print_text_in_color "$Red" "Unable to create $TURN_CONF, exiting..." + print_text_in_color "$Red" "Please report this issue here $ISSUES" exit 1 fi diff --git a/apps/tmbitwarden.sh b/apps/tmbitwarden.sh index d486c83a..d955451f 100644 --- a/apps/tmbitwarden.sh +++ b/apps/tmbitwarden.sh @@ -2,13 +2,13 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing Bitwarden password manager..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +print_text_in_color "$Cyan" "Installing Bitwarden password manager..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF diff --git a/apps/webmin.sh b/apps/webmin.sh index c9b6743c..06d39965 100644 --- a/apps/webmin.sh +++ b/apps/webmin.sh @@ -2,13 +2,13 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing Webmin..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +print_text_in_color "$Cyan" "Installing Webmin..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF diff --git a/lets-encrypt/activate-ssl.sh b/lets-encrypt/activate-ssl.sh index b81a089e..133d9dcf 100644 --- a/lets-encrypt/activate-ssl.sh +++ b/lets-encrypt/activate-ssl.sh @@ -90,7 +90,7 @@ check_command download_le_script test-new-config # Check if $domain exists and is reachable echo -echo "Checking if $domain exists and is reachable..." +print_text_in_color "$Cyan" "Checking if $domain exists and is reachable..." if wget -q -T 10 -t 2 --spider "$domain"; then sleep 1 elif wget -q -T 10 -t 2 --spider --no-check-certificate "https://$domain"; then @@ -124,7 +124,7 @@ fi if [ ! -f "$ssl_conf" ] then touch "$ssl_conf" - echo "$ssl_conf was successfully created" + print_text_in_color "$Green" "$ssl_conf was successfully created." sleep 2 cat << SSL_CREATE > "$ssl_conf" diff --git a/lets-encrypt/test-new-config.sh b/lets-encrypt/test-new-config.sh index 0f374923..7c97875b 100644 --- a/lets-encrypt/test-new-config.sh +++ b/lets-encrypt/test-new-config.sh @@ -37,7 +37,7 @@ Feel free to contribute to this project: https://goo.gl/3fQD65" FQDOMAIN=$(grep -m 1 "ServerName" "/etc/apache2/sites-enabled/$1" | awk '{print $2}') if [ "$(hostname)" != "$FQDOMAIN" ] then - echo "Setting hostname to $FQDOMAIN..." + print_text_in_color "$Cyan" "Setting hostname to $FQDOMAIN..." sudo sh -c "echo 'ServerName $FQDOMAIN' >> /etc/apache2/apache2.conf" sudo hostnamectl set-hostname "$FQDOMAIN" # Change /etc/hosts as well diff --git a/lib.sh b/lib.sh index 19240b6d..2e3be7ed 100644 --- a/lib.sh +++ b/lib.sh @@ -133,7 +133,7 @@ APACHE2=/etc/apache2/apache2.conf # then # # do stuff # else -# echo "You are not root..." +# print_text_in_color "$Red" "You are not root..." # exit 1 # fi # @@ -202,7 +202,7 @@ do if [ "${RESULT:-null}" = null ]; then break else - echo "${PROCESS} is running. Waiting for it to stop..." + print_text_in_color "$Cyan" "${PROCESS} is running. Waiting for it to stop..." sleep 10 fi done @@ -234,7 +234,7 @@ average_php_memory_requirement=50 available_memory=$(awk '/MemAvailable/ {printf "%d", $2/1024}' /proc/meminfo) export PHP_FPM_MAX_CHILDREN=$((available_memory/average_php_memory_requirement)) -echo "Automatically configures pm.max_children for php-fpm..." +print_text_in_color "$Cyan" "Automatically configures pm.max_children for php-fpm..." if [ $PHP_FPM_MAX_CHILDREN -lt 8 ] then msg_box "The current max_children value available to set is $PHP_FPM_MAX_CHILDREN, and with that value PHP-FPM won't function properly. @@ -256,7 +256,7 @@ The installation was not successful, sorry for the inconvenience. If you think this is a bug, please report it to $ISSUES" exit 1 else - echo "pm.max_children was set to $PHP_FPM_MAX_CHILDREN" + print_text_in_color "$Green" "pm.max_children was set to $PHP_FPM_MAX_CHILDREN" fi } @@ -282,19 +282,19 @@ ip link set "$IFACE" down sleep 2 ip link set "$IFACE" up sleep 2 -echo "Checking connection..." +print_text_in_color "$Cyan" "Checking connection..." check_command service network-manager restart sleep 2 if nslookup github.com then - echo "Online!" + print_text_in_color "$Green" "Online!" elif ! nslookup github.com then - echo "Trying to restart networking service..." + print_text_in_color "$Cyan" "Trying to restart networking service..." check_command service networking restart && sleep 2 if nslookup github.com then - echo "Online!" + print_text_in_color "$Green" "Online!" fi else if ! nslookup github.com @@ -323,7 +323,7 @@ if [ $LE_IS_AVAILABLE -eq 0 ] then certbot --version 2> /dev/null else - echo "Installing certbot (Let's Encrypt)..." + print_text_in_color "$Cyan" "Installing certbot (Let's Encrypt)..." apt update -q4 & spinner_loading install_if_not software-properties-common add-apt-repository ppa:certbot/certbot -y @@ -352,7 +352,7 @@ fi apt update -q4 & spinner_loading if [ "$NMAPSTATUS" = "preinstalled" ] then - echo "nmap is already installed..." + print_text_in_color "$Cyan" "nmap is already installed..." else apt install nmap -y fi @@ -363,7 +363,7 @@ then printf "${Green}Port $1 is open on $WANIP4!${Color_Off}\n" if [ "$NMAPSTATUS" = "preinstalled" ] then - echo "nmap was previously installed, not removing." + print_text_in_color "$Cyan" "nmap was previously installed, not removing." else apt remove --purge nmap -y fi @@ -374,7 +374,7 @@ else printf "${Green}Port $1 is open on $2!${Color_Off}\n" if [ "$NMAPSTATUS" = "preinstalled" ] then - echo "nmap was previously installed, not removing." + print_text_in_color "$Cyan" "nmap was previously installed, not removing." else apt remove --purge nmap -y fi @@ -383,7 +383,7 @@ else any_key "Press any key to exit... " if [ "$NMAPSTATUS" = "preinstalled" ] then - echo "nmap was previously installed, not removing." + print_text_in_color "$Cyan" "nmap was previously installed, not removing." else apt remove --purge nmap -y fi @@ -394,7 +394,7 @@ fi check_distro_version() { # Check Ubuntu version -echo "Checking server OS and version..." +print_text_in_color "$Cyan" "Checking server OS and version..." if lsb_release -c | grep -ic "bionic" &> /dev/null then OS=1 @@ -427,7 +427,7 @@ fi configure_max_upload() { # Increase max filesize (expects that changes are made in $PHP_INI) # Here is a guide: https://www.techandme.se/increase-max-file-size/ -echo "Setting max_upload size in PHP..." +print_text_in_color "$Cyan" "Setting max_upload size in PHP..." # Copy settings from .htaccess to user.ini. beacuse we run php-fpm. Documented here: https://docs.nextcloud.com/server/13/admin_manual/installation/source_installation.html#php-fpm-configuration-notes cp -fv "$NCPATH/.htaccess" "$NCPATH/.user.ini" # Do the acutal change @@ -440,7 +440,7 @@ sed -i 's/ php_value memory_limit.*/# php_value memory_limit 512M/g' "$NCPATH"/ is_this_installed() { if [ "$(dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed")" == "1" ] then - echo "${1} is installed, it must be a clean server." + print_text_in_color "$Red" "${1} is installed, it must be a clean server." exit 1 fi } @@ -493,8 +493,8 @@ fi check_command() { if ! "$@"; then - printf "${IRed}Sorry but something went wrong. Please report this issue to $ISSUES and include the output of the error message. Thank you!${Color_Off}\n" - echo "$* failed" + print_text_in_color "$Cyan" "Sorry but something went wrong. Please report this issue to $ISSUES and include the output of the error message. Thank you!" + print_text_in_color "$Red" "$* failed" exit 1 fi } @@ -505,7 +505,7 @@ check_command sudo -u www-data php "$NCPATH"/occ "$@"; } network_ok() { - echo "Testing if network is OK..." + print_text_in_color "$Cyan" "Testing if network is OK..." if ! service network-manager restart > /dev/null then service networking restart > /dev/null @@ -538,7 +538,7 @@ install_and_enable_app() { # Download and install $1 if [ ! -d "$NC_APPS_PATH/$1" ] then - echo "Installing $1..." + print_text_in_color "$Cyan" "Installing $1..." # occ_command not possible here because it uses check_command and will exit if occ_command fails result=$(sudo -u www-data php ${NCPATH}/occ app:install "$1") if [ "$result" = "Error: Could not download app $1" ] @@ -580,9 +580,9 @@ download_static_script() { rm -f "${SCRIPTS}/${1}.sh" "${SCRIPTS}/${1}.php" "${SCRIPTS}/${1}.py" if ! { wget -q "${STATIC}/${1}.sh" -P "$SCRIPTS" || wget -q "${STATIC}/${1}.php" -P "$SCRIPTS" || wget -q "${STATIC}/${1}.py" -P "$SCRIPTS"; } then - echo "{$1} failed to download. Please run: 'sudo wget ${STATIC}/${1}.sh|.php|.py' again." - echo "If you get this error when running the nextcloud-startup-script then just re-run it with:" - echo "'sudo bash $SCRIPTS/nextcloud-startup-script.sh' and all the scripts will be downloaded again" + print_text_in_color "$Red" "{$1} failed to download. Please run: 'sudo wget ${STATIC}/${1}.sh|.php|.py' again." + print_text_in_color "$Cyan" "If you get this error when running the nextcloud-startup-script then just re-run it with:" + print_text_in_color "$Cyan" "'sudo bash $SCRIPTS/nextcloud-startup-script.sh' and all the scripts will be downloaded again" exit 1 fi } @@ -594,9 +594,9 @@ download_le_script() { rm -f "${SCRIPTS}/${1}.sh" "${SCRIPTS}/${1}.php" "${SCRIPTS}/${1}.py" if ! { wget -q "${LETS_ENC}/${1}.sh" -P "$SCRIPTS" || wget -q "${LETS_ENC}/${1}.php" -P "$SCRIPTS" || wget -q "${LETS_ENC}/${1}.py" -P "$SCRIPTS"; } then - echo "{$1} failed to download. Please run: 'sudo wget ${STATIC}/${1}.sh|.php|.py' again." - echo "If you get this error when running the nextcloud-startup-script then just re-run it with:" - echo "'sudo bash $SCRIPTS/nextcloud-startup-script.sh' and all the scripts will be downloaded again" + print_text_in_color "$Red" "{$1} failed to download. Please run: 'sudo wget ${STATIC}/${1}.sh|.php|.py' again." + print_text_in_color "$Cyan" "If you get this error when running the nextcloud-startup-script then just re-run it with:" + print_text_in_color "$Cyan" "'sudo bash $SCRIPTS/nextcloud-startup-script.sh' and all the scripts will be downloaded again" exit 1 fi } @@ -618,9 +618,9 @@ run_main_script() { python "${SCRIPTS}/${1}.py" rm -f "${SCRIPTS}/${1}.py" else - echo "Downloading ${1} failed" - echo "Script failed to download. Please run: 'sudo wget ${GITHUB_REPO}/${1}.sh|php|py' again." - sleep 3 + print_text_in_color "$Red" "Downloading ${1} failed" + print_text_in_color "$Cyan" "Script failed to download. Please run: 'sudo wget ${GITHUB_REPO}/${1}.sh|php|py' again." + exit 1 fi } @@ -642,9 +642,9 @@ run_static_script() { python "${SCRIPTS}/${1}.py" rm -f "${SCRIPTS}/${1}.py" else - echo "Downloading ${1} failed" - echo "Script failed to download. Please run: 'sudo wget ${STATIC}/${1}.sh|php|py' again." - sleep 3 + print_text_in_color "$Red" "Downloading ${1} failed" + print_text_in_color "$Cyan" "Script failed to download. Please run: 'sudo wget ${STATIC}/${1}.sh|php|py' again." + exit 1 fi } @@ -665,9 +665,9 @@ run_app_script() { python "${SCRIPTS}/${1}.py" rm -f "${SCRIPTS}/${1}.py" else - echo "Downloading ${1} failed" - echo "Script failed to download. Please run: 'sudo wget ${APP}/${1}.sh|php|py' again." - sleep 3 + print_text_in_color "$Red" "Downloading ${1} failed" + print_text_in_color "$Cyan" "Script failed to download. Please run: 'sudo wget ${APP}/${1}.sh|php|py' again." + exit fi } @@ -762,7 +762,7 @@ check_universe() { UNIV=$(apt-cache policy | grep http | awk '{print $3}' | grep universe | head -n 1 | cut -d "/" -f 2) if [ "$UNIV" != "universe" ] then - echo "Adding required repo (universe)." + print_text_in_color "$Cyan" "Adding required repo (universe)." add-apt-repository universe fi } @@ -772,14 +772,14 @@ check_multiverse() { MULTIV=$(apt-cache policy | grep http | awk '{print $3}' | grep multiverse | head -n 1 | cut -d "/" -f 2) if [ "$MULTIV" != "multiverse" ] then - echo "Adding required repo (multiverse)." + print_text_in_color "$Cyan" "Adding required repo (multiverse)." add-apt-repository multiverse fi } set_max_count() { if grep -F 'vm.max_map_count=262144' /etc/sysctl.conf ; then - echo "Max map count already set, skipping..." + print_text_in_color "$Cyan" "Max map count already set, skipping..." else sysctl -w vm.max_map_count=262144 { @@ -793,7 +793,7 @@ fi install_docker() { if ! docker -v &> /dev/null then - echo "Installing Docker CE..." + print_text_in_color "$Cyan" "Installing Docker CE..." install_if_not curl curl -fsSL get.docker.com | sh fi @@ -810,7 +810,7 @@ systemctl restart docker # Remove all dockers excluding one # docker_prune_except_this fts_esror 'Full Text Search' docker_prune_except_this() { -echo "Checking if there are any old images and removing them..." +print_text_in_color "$Cyan" "Checking if there are any old images and removing them..." DOCKERPS=$(docker ps -a | grep -v "$1" | awk 'NR>1 {print $1}') if [ "$DOCKERPS" != "" ] then @@ -861,7 +861,7 @@ fi # countdown 'message looks like this' 10 countdown() { -echo "$1" +print_text_in_color "$Cyan" "$1" secs="$(($2))" while [ $secs -gt 0 ]; do echo -ne "$secs\033[0K\r" @@ -870,6 +870,10 @@ while [ $secs -gt 0 ]; do done } +print_text_in_color() { + printf "%b%s%b\n" "$1" "$2" "$Color_Off" +} + ## bash colors # Reset Color_Off='\e[0m' # Text Reset diff --git a/nextcloud-startup-script.sh b/nextcloud-startup-script.sh index 1c5fb0a6..7c26d920 100644 --- a/nextcloud-startup-script.sh +++ b/nextcloud-startup-script.sh @@ -46,7 +46,7 @@ fi } network_ok() { - echo "Testing if network is OK..." + print_text_in_color "$Cyan" "Testing if network is OK..." service network-manager restart if wget -q -T 20 -t 2 http://github.com -O /dev/null then @@ -59,8 +59,8 @@ network_ok() { check_command() { if ! "$@"; then - printf "${IRed}Sorry but something went wrong. Please report this issue to $ISSUES and include the output of the error message. Thank you!${Color_Off}\n" - echo "$* failed" + print_text_in_color "$Cyan" "Sorry but something went wrong. Please report this issue to $ISSUES and include the output of the error message. Thank you!" + print_text_in_color "$Red" "$* failed" exit 1 fi } @@ -75,7 +75,7 @@ if network_ok then printf "${Green}Online!${Color_Off}\n" else - echo "Setting correct interface..." + print_text_in_color "$Cyan" "Setting correct interface..." [ -z "$IFACE" ] && IFACE=$(lshw -c network | grep "logical name" | awk '{print $3; exit}') # Set correct interface cat <<-SETDHCP > "/etc/netplan/01-netcfg.yaml" @@ -94,7 +94,7 @@ SETDHCP ip link set "$IFACE" up wait check_command service network-manager restart - echo "Checking connection..." + print_text_in_color "$Cyan" "Checking connection..." sleep 1 if ! nslookup github.com then @@ -188,8 +188,8 @@ lowest_compatible_nc 13 # Check that this run on the PostgreSQL VM if ! which psql > /dev/null then - echo "This script is intended to be run on then PostgreSQL VM but PostgreSQL is not installed." - echo "Aborting..." + print_text_in_color "$Red" "This script is intended to be run on then PostgreSQL VM but PostgreSQL is not installed." + print_text_in_color "$Red" "Aborting..." exit 1 fi @@ -230,7 +230,7 @@ is_process_running apt is_process_running dpkg echo -echo "Getting scripts from GitHub to be able to run the first setup..." +print_text_in_color "$Cyan" "Getting scripts from GitHub to be able to run the first setup..." # Scripts in static (.sh, .php, .py) download_static_script temporary-fix download_static_script update @@ -289,10 +289,10 @@ It will also do the following: clear # Set keyboard layout -echo "Current keyboard layout is $(localectl status | grep "Layout" | awk '{print $3}')" +print_text_in_color "$Cyan" "Current keyboard layout is $(localectl status | grep "Layout" | awk '{print $3}')" if [[ "no" == $(ask_yes_or_no "Do you want to change keyboard layout?") ]] then - echo "Not changing keyboard layout..." + print_text_in_color "$Cyan" "Not changing keyboard layout..." sleep 1 clear else @@ -301,10 +301,10 @@ else fi # Change Timezone -echo "Current timezone is $(cat /etc/timezone)" +print_text_in_color "$Cyan" "Current timezone is $(cat /etc/timezone)" if [[ "no" == $(ask_yes_or_no "Do you want to change the timezone?") ]] then - echo "Not changing timezone..." + print_text_in_color "$Cyan" "Not changing timezone..." sleep 1 clear else @@ -317,15 +317,15 @@ msg_box "To make downloads as fast as possible when updating you should have mir This VM comes with mirrors based on servers in that where used when the VM was released and packaged. If you are located outside of Europe, we recomend you to change the mirrors so that downloads are faster." -echo "Checking current mirror..." -printf "Your current server repository is: ${Cyan}$REPO${Color_Off}\n" +print_text_in_color "$Cyan" "Checking current mirror..." +print_text_in_color "$Cyan" "Your current server repository is: $REPO" if [[ "no" == $(ask_yes_or_no "Do you want to try to find a better mirror?") ]] then - echo "Keeping $REPO as mirror..." + print_text_in_color "$Cyan" "Keeping $REPO as mirror..." sleep 1 else - echo "Locating the best mirrors..." + print_text_in_color "$Cyan" "Locating the best mirrors..." apt update -q4 & spinner_loading apt install python-pip -y pip install \ @@ -341,7 +341,7 @@ fi clear # Pretty URLs -echo "Setting RewriteBase to \"/\" in config.php..." +print_text_in_color "$Cyan" "Setting RewriteBase to \"/\" in config.php..." chown -R www-data:www-data $NCPATH occ_command config:system:set overwrite.cli.url --value="http://localhost/" occ_command config:system:set htaccess.RewriteBase --value="/" @@ -354,7 +354,7 @@ rm -v /etc/ssh/ssh_host_* dpkg-reconfigure openssh-server # Generate new PostgreSQL password -echo "Generating new PostgreSQL password..." +print_text_in_color "$Cyan" "Generating new PostgreSQL password..." check_command bash "$SCRIPTS/change_db_pass.sh" sleep 3 clear @@ -374,7 +374,7 @@ then bash $SCRIPTS/activate-ssl.sh else echo - echo "OK, but if you want to run it later, just type: sudo bash $SCRIPTS/activate-ssl.sh" + print_text_in_color "$Cyan" "OK, but if you want to run it later, just type: sudo bash $SCRIPTS/activate-ssl.sh" any_key "Press any key to continue..." fi clear @@ -448,7 +448,7 @@ clear # Change password printf "${Color_Off}\n" -echo "For better security, change the system user password for [$(getent group sudo | cut -d: -f4 | cut -d, -f1)]" +print_text_in_color "$Cyan" "For better security, change the system user password for [$(getent group sudo | cut -d: -f4 | cut -d, -f1)]" any_key "Press any key to change password for system user..." while true do @@ -458,8 +458,8 @@ echo clear NCADMIN=$(occ_command user:list | awk '{print $3}') printf "${Color_Off}\n" -echo "For better security, change the Nextcloud password for [$NCADMIN]" -echo "The current password for $NCADMIN is [$NCPASS]" +print_text_in_color "$Cyan" "For better security, change the Nextcloud password for [$NCADMIN]" +print_text_in_color "$Cyan" "The current password for $NCADMIN is [$NCPASS]" any_key "Press any key to change password for Nextcloud..." while true do @@ -583,14 +583,14 @@ mesg n ROOTNEWPROFILE # Download all app scripts -echo "Downloading all the latest app scripts to $SCRIPTS/apps..." +print_text_in_color "$Cyan" "Downloading all the latest app scripts to $SCRIPTS/apps..." mkdir -p $SCRIPTS/apps cd $SCRIPTS/apps check_command curl -s https://codeload.github.com/nextcloud/vm/tar.gz/master | tar -xz --strip=2 vm-master/apps # Upgrade system clear -echo "System will now upgrade..." +print_text_in_color "$Cyan" "System will now upgrade..." bash $SCRIPTS/update.sh # Cleanup 2 diff --git a/nextcloud_install_production.sh b/nextcloud_install_production.sh index a9293ab3..3d5a7951 100644 --- a/nextcloud_install_production.sh +++ b/nextcloud_install_production.sh @@ -17,7 +17,7 @@ is_process_running dpkg # Install curl if not existing if [ "$(dpkg-query -W -f='${Status}' "curl" 2>/dev/null | grep -c "ok installed")" == "1" ] then - echo "curl OK" + print_text_in_color "$Green" "curl OK" else apt update -q4 & spinner_loading apt install curl -y @@ -26,7 +26,7 @@ fi # Install lshw if not existing if [ "$(dpkg-query -W -f='${Status}' "lshw" 2>/dev/null | grep -c "ok installed")" == "1" ] then - echo "lshw OK" + print_text_in_color "$Green" "lshw OK" else apt update -q4 & spinner_loading apt install lshw -y @@ -35,7 +35,7 @@ fi # Install net-tools if not existing if [ "$(dpkg-query -W -f='${Status}' "net-tools" 2>/dev/null | grep -c "ok installed")" == "1" ] then - echo "net-tools OK" + print_text_in_color "$Green" "net-tools OK" else apt update -q4 & spinner_loading apt install net-tools -y @@ -125,10 +125,10 @@ echo printf "Your current server repository is: ${Cyan}%s${Color_Off}\n" "$REPO" if [[ "no" == $(ask_yes_or_no "Do you want to try to find a better mirror?") ]] then - echo "Keeping $REPO as mirror..." + print_text_in_color "$Cyan" "Keeping $REPO as mirror..." sleep 1 else - echo "Locating the best mirrors..." + print_text_in_color "$Cyan" "Locating the best mirrors..." apt update -q4 & spinner_loading apt install python-pip -y pip install \ @@ -144,10 +144,10 @@ fi clear # Set keyboard layout -echo "Current keyboard layout is $(localectl status | grep "Layout" | awk '{print $3}')" +print_text_in_color "$Cyan" "Current keyboard layout is $(localectl status | grep "Layout" | awk '{print $3}')" if [[ "no" == $(ask_yes_or_no "Do you want to change keyboard layout?") ]] then - echo "Not changing keyboard layout..." + print_text_in_color "$Cyan" "Not changing keyboard layout..." sleep 1 clear else @@ -212,14 +212,14 @@ check_command apt install -y \ a2enconf php7.2-fpm # Enable HTTP/2 server wide -echo "Enabling HTTP/2 server wide..." +print_text_in_color "$Cyan" "Enabling HTTP/2 server wide..." cat << HTTP2_ENABLE > "$HTTP2_CONF" Protocols h2 h2c http/1.1 H2Direct on HTTP2_ENABLE -echo "$HTTP2_CONF was successfully created" +print_text_in_color "$Green" "$HTTP2_CONF was successfully created" a2enmod http2 restart_webserver @@ -291,7 +291,7 @@ occ_command maintenance:install \ --admin-user="$NCUSER" \ --admin-pass="$NCPASS" echo -echo "Nextcloud version:" +print_text_in_color "$Cyan" "Nextcloud version:" occ_command status sleep 3 echo @@ -339,7 +339,7 @@ echo "opcache.validate_timestamps=1" } >> $PHP_INI # Fix https://github.com/nextcloud/vm/issues/714 -echo "Optimizing Nextcloud..." +print_text_in_color "$Cyan" "Optimizing Nextcloud..." yes | occ_command db:convert-filecache-bigint occ_command db:add-missing-indices @@ -403,7 +403,7 @@ then HTTP_CREATE - echo "$HTTP_CONF was successfully created" + print_text_in_color "$Green" "$HTTP_CONF was successfully created." fi # Generate $SSL_CONF @@ -466,7 +466,7 @@ then SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key SSL_CREATE - echo "$SSL_CONF was successfully created" + print_text_in_color "$Green" "$SSL_CONF was successfully created." fi # Enable new config @@ -557,5 +557,5 @@ bash $SECURE & spinner_loading sudo /usr/lib/update-notifier/update-motd-updates-available --force # Reboot -echo "Installation done, system will now reboot..." +print_text_in_color "$Cyan" "Installation done, system will now reboot..." reboot diff --git a/nextcloud_update.sh b/nextcloud_update.sh index de4dc651..78019672 100644 --- a/nextcloud_update.sh +++ b/nextcloud_update.sh @@ -34,8 +34,8 @@ if [ -f /etc/systemd/system/docker.service ] then if grep -q "devicemapper" /etc/systemd/system/docker.service then - echo "Changing to Overlay2 for Docker CE..." - echo "Please report any issues to $ISSUES." + print_text_in_color "$Cyan" "Changing to Overlay2 for Docker CE..." + print_text_in_color "$Cyan" "Please report any issues to $ISSUES." run_static_script docker_overlay2 elif grep -q "aufs" /etc/default/docker then @@ -50,7 +50,7 @@ if which mysql > /dev/null then apt-mark unhold mariadb* echo -echo "If you want to upgrade MariaDB, please run 'sudo apt update && sudo apt dist-upgrade -y'" +print_text_in_color "$Cyan" "If you want to upgrade MariaDB, please run 'sudo apt update && sudo apt dist-upgrade -y'" sleep 2 fi @@ -64,7 +64,7 @@ then fi # Update Redis PHP extension -echo "Trying to upgrade the Redis PECL extenstion..." +print_text_in_color "$Cyan" "Trying to upgrade the Redis PECL extenstion..." if ! pecl list | grep redis >/dev/null 2>&1 then if dpkg -l | grep php7.2 > /dev/null 2>&1 @@ -96,7 +96,7 @@ fi # Update adminer if [ -d $ADMINERDIR ] then - echo "Updating Adminer..." + print_text_in_color "$Cyan" "Updating Adminer..." rm -f "$ADMINERDIR"/latest.php "$ADMINERDIR"/adminer.php wget -q "http://www.adminer.org/latest.php" -O "$ADMINERDIR"/latest.php ln -s "$ADMINERDIR"/latest.php "$ADMINERDIR"/adminer.php @@ -171,16 +171,16 @@ fi # Check if new version is larger than current version installed. if version_gt "$NCVERSION" "$CURRENTVERSION" then - echo "Latest release is: $NCVERSION. Current version is: $CURRENTVERSION." - printf "${Green}New version available! Upgrade continues...${Color_Off}\n" + print_text_in_color "$Cyan" "Latest release is: $NCVERSION. Current version is: $CURRENTVERSION." + print_text_in_color "$Green" "New version available! Upgrade continues..." else - echo "Latest version is: $NCVERSION. Current version is: $CURRENTVERSION." - echo "No need to upgrade, this script will exit..." + print_text_in_color "$Cyan" "Latest version is: $NCVERSION. Current version is: $CURRENTVERSION." + print_text_in_color "$Cyan" "No need to upgrade, this script will exit..." exit 0 fi # Upgrade Nextcloud -echo "Checking latest released version on the Nextcloud download server and if it's possible to download..." +print_text_in_color "$Cyan" "Checking latest released version on the Nextcloud download server and if it's possible to download..." if ! wget -q --show-progress -T 10 -t 2 "$NCREPO/$STABLEVERSION.tar.bz2" then msg_box "Nextcloud does not exist. You were looking for: $NCVERSION @@ -208,10 +208,10 @@ then cd /tmp if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCCONFIGDB'" | grep "1 row" > /dev/null then - echo "Doing pgdump of $NCCONFIGDB..." + print_text_in_color "$Cyan" "Doing pgdump of $NCCONFIGDB..." check_command sudo -u postgres pg_dump "$NCCONFIGDB" > "$BACKUP"/nextclouddb.sql else - echo "Doing pgdump of all databases..." + print_text_in_color "$Cyan" "Doing pgdump of all databases..." check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.sql fi fi @@ -249,10 +249,10 @@ fi # Backup MariaDB if mysql -u root -p"$MARIADBMYCNFPASS" -e "SHOW DATABASES LIKE '$NCCONFIGDB'" > /dev/null then - echo "Doing mysqldump of $NCCONFIGDB..." + print_text_in_color "$Cyan" "Doing mysqldump of $NCCONFIGDB..." check_command mysqldump -u root -p"$MARIADBMYCNFPASS" -d "$NCCONFIGDB" > "$BACKUP"/nextclouddb.sql else - echo "Doing mysqldump of all databases..." + print_text_in_color "$Cyan" "Doing mysqldump of all databases..." check_command mysqldump -u root -p"$MARIADBMYCNFPASS" -d --all-databases > "$BACKUP"/alldatabases.sql fi } @@ -264,7 +264,7 @@ then fi # Check if backup exists and move to old -echo "Backing up data..." +print_text_in_color "$Cyan" "Backing up data..." DATE=$(date +%Y-%m-%d-%H%M%S) if [ -d $BACKUP ] then @@ -310,7 +310,7 @@ check_command download_verify_nextcloud_stable if [ -f "$HTML/$STABLEVERSION.tar.bz2" ] then - echo "$HTML/$STABLEVERSION.tar.bz2 exists" + print_text_in_color "$Cyan" "$HTML/$STABLEVERSION.tar.bz2 exists" else msg_box "Aborting, something went wrong with the download" exit 1 @@ -318,7 +318,7 @@ fi if [ -d $BACKUP/config/ ] then - echo "$BACKUP/config/ exists" + print_text_in_color "$Cyan" "$BACKUP/config/ exists" else msg_box "Something went wrong with backing up your old nextcloud instance Please check in $BACKUP if config/ folder exist." @@ -327,7 +327,7 @@ fi if [ -d $BACKUP/apps/ ] then - echo "$BACKUP/apps/ exists" + print_text_in_color "$Cyan" "$BACKUP/apps/ exists" echo printf "${Green}All files are backed up.${Color_Off}\n" occ_command maintenance:mode --on @@ -340,7 +340,7 @@ then occ_command maintenance:mode --off occ_command upgrade # Optimize - echo "Optimizing Nextcloud..." + print_text_in_color "$Cyan" "Optimizing Nextcloud..." yes | occ_command db:convert-filecache-bigint occ_command db:add-missing-indices else @@ -375,7 +375,7 @@ fi chown -R root:root "$BACKUP" # Pretty URLs -echo "Setting RewriteBase to \"/\" in config.php..." +print_text_in_color "$Cyan" "Setting RewriteBase to \"/\" in config.php..." chown -R www-data:www-data "$NCPATH" occ_command config:system:set htaccess.RewriteBase --value="/" occ_command maintenance:update:htaccess diff --git a/static/adduser.sh b/static/adduser.sh index a94d1bbb..05081716 100644 --- a/static/adduser.sh +++ b/static/adduser.sh @@ -23,7 +23,7 @@ Please create a user with sudo permissions if you want an optimal installation. The preferred user is 'ncadmin'." if [[ "no" == $(ask_yes_or_no "Do you want to create a new user?") ]] then - echo "Not adding another user..." + print_text_in_color "$Cyan" "Not adding another user..." sleep 1 else read -r -p "Enter name of the new user: " NEWUSER diff --git a/static/change_db_pass.sh b/static/change_db_pass.sh index 49f2bb8d..118778cc 100644 --- a/static/change_db_pass.sh +++ b/static/change_db_pass.sh @@ -19,10 +19,10 @@ sudo -u www-data php "$NCPATH"/occ config:system:set dbpassword --value="$NEWPGP if [ "$(sudo -u postgres psql -c "ALTER USER $NCUSER WITH PASSWORD '$NEWPGPASS'";)" == "ALTER ROLE" ] then - echo -e "${Green}Your new PosgreSQL Nextcloud password is: $NEWPGPASS${Color_Off}" + sleep 1 else - echo "Changing PostgreSQL Nextcloud password failed." + print_text_in_color "$Red" "Changing PostgreSQL Nextcloud password failed." sed -i "s| 'dbpassword' =>.*| 'dbpassword' => '$NCCONFIGDBPASS',|g" /var/www/nextcloud/config/config.php - echo "Nothing is changed. Your old password is: $NCCONFIGDBPASS" + print_text_in_color "$Red" "Nothing is changed. Your old password is: $NCCONFIGDBPASS" exit 1 fi diff --git a/static/docker_overlay2.sh b/static/docker_overlay2.sh index 4084e3a2..2aa550ad 100644 --- a/static/docker_overlay2.sh +++ b/static/docker_overlay2.sh @@ -30,15 +30,15 @@ readonly DB_FILE="$DOCKERBACKUP/images.db" readonly IMG_DIR="$DOCKERBACKUP/images" save_images() { - echo "Create ${IMG_DIR}" + print_text_in_color "$Cyan" "Create ${IMG_DIR}" if [[ ! -d "${IMG_DIR}" ]]; then mkdir "${IMG_DIR}" fi - echo "Create ${DB_FILE}" + print_text_in_color "$Cyan" "Create ${DB_FILE}" docker images|grep -v 'IMAGE ID'|awk '{printf("%s %s %s\n", $1, $2, $3)}'|column -t > "${DB_FILE}" - echo "Read ${DB_FILE}" + print_text_in_color "$Cyan" "Read ${DB_FILE}" local images while read -r image; do images+=("$image"); @@ -54,10 +54,10 @@ save_images() { local imgPath="${IMG_DIR}/${id}.dim" if [[ ! -f "${imgPath}" ]] ; then - echo "[DEBUG] save ${id} ${name}:${tag} to ${imgPath}" + print_text_in_color "$Cyan" "[DEBUG] save ${id} ${name}:${tag} to ${imgPath}" (time docker save -o "${imgPath}" "${name}":"${tag}") 2>&1 | grep real else - echo "[DEBUG] ${id} ${name}:${tag} already saved" + print_text_in_color "$Cyan" "[DEBUG] ${id} ${name}:${tag} already saved" fi fi done @@ -65,16 +65,16 @@ save_images() { load_images() { if [[ ! -f "${DB_FILE}" ]]; then - echo "No ${DB_FILE} to read" + print_text_in_color "$Cyan" "No ${DB_FILE} to read" exit 0 fi if [[ ! -d "${IMG_DIR}" ]]; then - echo "No ${IMG_DIR} to load images" + print_text_in_color "$Cyan" "No ${IMG_DIR} to load images" exit 0 fi - echo "Read ${DB_FILE}" + print_text_in_color "$Cyan" "Read ${DB_FILE}" local images while read -r image; do images+=("$image"); @@ -91,14 +91,14 @@ load_images() { if [[ "$(docker images|grep "${id}" | grep "${name}" | grep "${tag}")" == "" ]]; then if [[ "$(docker images|grep "${id}")" == "" ]]; then - echo "[DEBUG] load ${id} ${name}:${tag} from ${imgPath}" + print_text_in_color "$Cyan" "[DEBUG] load ${id} ${name}:${tag} from ${imgPath}" docker load -i "${imgPath}" else - echo "[DEBUG] tag ${id} as ${name}:${tag}" + print_text_in_color "$Cyan" "[DEBUG] tag ${id} as ${name}:${tag}" docker tag "${id}" "${name}":"${tag}" fi else - echo "[DEBUG] ${id} ${name}:${tag} already loaded" + print_text_in_color "$Cyan" "[DEBUG] ${id} ${name}:${tag} already loaded" fi fi done @@ -116,7 +116,7 @@ It may take a while so please be patient." check_command save_images # Set overlay2 -echo "Setting overlay2 in /etc/docker/daemon.json" +print_text_in_color "$Cyan" "Setting overlay2 in /etc/docker/daemon.json" cat << OVERLAY2 > /etc/docker/daemon.json { @@ -125,9 +125,9 @@ cat << OVERLAY2 > /etc/docker/daemon.json OVERLAY2 rm -f /etc/systemd/system/docker.service systemctl restart docker.service -echo "Reloading daemon" +print_text_in_color "$Cyan" "Reloading daemon" systemctl daemon-reload -echo "Restarting the docker service" +print_text_in_color "$Cyan" "Restarting the docker service" check_command systemctl restart docker apt-mark unhold docker-ce @@ -142,7 +142,7 @@ apt update -q4 & spinner_loading apt upgrade docker-ce -y # Load docker images back -echo "Importing saved docker images to overlay2..." +print_text_in_color "$Cyan" "Importing saved docker images to overlay2..." check_command load_images msg_box "Your Docker images are now imported to overlay2, but not yet running. diff --git a/static/modsecurity.sh b/static/modsecurity.sh index 9028775e..c9fffa35 100644 --- a/static/modsecurity.sh +++ b/static/modsecurity.sh @@ -2,13 +2,13 @@ # T&M Hansson IT AB © - 2018, https://www.hanssonit.se/ -echo "Installing ModSecurity..." - # shellcheck disable=2034,2059 true # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +print_text_in_color "$Cyan" "Installing ModSecurity..." + # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF @@ -93,6 +93,6 @@ check_command sed -i 's|# SecDefaultAction "phase:2,nolog,auditlog,pass"|SecDefa if [ -f /etc/modsecurity/whitelist.conf ] then - echo "ModSecurity activated!" + print_text_in_color "$Green" "ModSecurity activated!" restart_webserver fi diff --git a/static/security.sh b/static/security.sh index 3de1c61b..512ff96b 100644 --- a/static/security.sh +++ b/static/security.sh @@ -17,7 +17,7 @@ debug_mode # Check if root root_check -echo "Installing Extra Security..." +print_text_in_color "$Cyan" "Installing Extra Security..." # Based on: http://www.techrepublic.com/blog/smb-technologist/secure-your-apache-server-from-ddos-slowloris-and-dns-injection-attacks/ @@ -116,6 +116,6 @@ check_command bash "$SCRIPTS"/spamhaus_cronjob.sh # Enable $SPAMHAUS if sed -i "s|#MS_WhiteList /etc/spamhaus.wl|MS_WhiteList $SPAMHAUS|g" /etc/apache2/mods-enabled/spamhaus.conf then - echo "Security added!" + print_text_in_color "$Green" "Security added!" restart_webserver fi