diff --git a/README.md b/README.md index 21ae5f8688..df9edc7438 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Nextcloud VM +# Nextcloud VM PostgreSQL [![irc](https://img.shields.io/badge/irc%20channel-%23techandme%20on%20freenode-blue.svg)](https://webchat.freenode.net/?channels=techandme) [![Build Status](https://travis-ci.org/nextcloud/vm.svg?branch=master)](https://travis-ci.org/nextcloud/vm) [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) ## Support the development @@ -22,7 +22,7 @@ DigitalOcean example: https://youtu.be/LlqY5Y6P9Oc * A clean Ubuntu Server 16.04.X * OpenSSH (preferred) * 20 GB HDD -* At least 1 vCPU and 2 GB RAM +* At least 1 vCPU and 2 GB RAM (4 GB minimum of you are running OnlyOffice) * A working internet connection (the script needs it to download files and variables) #### Recommended diff --git a/apps/calendar.sh b/apps/calendar.sh index 8c493323c4..1e5a7df21e 100644 --- a/apps/calendar.sh +++ b/apps/calendar.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -CALENDAR_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +CALENDAR_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset CALENDAR_INSTALL # Check for errors + debug code and abort if something isn't right diff --git a/apps/collabora.sh b/apps/collabora.sh index 5adc96c2a1..4c0cd40156 100644 --- a/apps/collabora.sh +++ b/apps/collabora.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -COLLABORA_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +COLLABORA_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset COLLABORA_INSTALL # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/apps/contacts.sh b/apps/contacts.sh index c7e00198b1..7be62ff1b1 100644 --- a/apps/contacts.sh +++ b/apps/contacts.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -CONTACTS_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +CONTACTS_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset CONTACTS_INSTALL # Check for errors + debug code and abort if something isn't right diff --git a/apps/fail2ban.sh b/apps/fail2ban.sh index 05563bed91..84ddc5349d 100644 --- a/apps/fail2ban.sh +++ b/apps/fail2ban.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/apps/nextant.sh b/apps/nextant.sh index 5d05e95e84..5bc095c61a 100644 --- a/apps/nextant.sh +++ b/apps/nextant.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -NEXTANT_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +NEXTANT_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset NEXTANT_INSTALL # Check for errors + debug code and abort if something isn't right diff --git a/apps/onlyoffice.sh b/apps/onlyoffice.sh index 25c2a655fb..113c963dc2 100644 --- a/apps/onlyoffice.sh +++ b/apps/onlyoffice.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -OO_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +OO_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset OO_INSTALL # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/apps/passman.sh b/apps/passman.sh index b066e98993..d2cfe54f83 100644 --- a/apps/passman.sh +++ b/apps/passman.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -PASSMAN_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +PASSMAN_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset PASSMAN_INSTALL # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/apps/phpmyadmin_install_ubuntu16.sh b/apps/phpmyadmin_install_ubuntu16.sh index 7c8ad251b3..1bc66f9935 100644 --- a/apps/phpmyadmin_install_ubuntu16.sh +++ b/apps/phpmyadmin_install_ubuntu16.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -MYCNFPW=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +MYCNFPW=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset MYCNFPW # Check for errors + debug code and abort if something isn't right diff --git a/apps/phppgadmin_install_ubuntu16.sh b/apps/phppgadmin_install_ubuntu16.sh new file mode 100644 index 0000000000..1a099a9c47 --- /dev/null +++ b/apps/phppgadmin_install_ubuntu16.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Tech and Me © - 2017, https://www.techandme.se/ + +# shellcheck disable=2034,2059 +true +# shellcheck source=lib.sh +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) + +# Check for errors + debug code and abort if something isn't right +# 1 = ON +# 0 = OFF +DEBUG=0 +debug_mode + +# Check if root +if ! is_root +then + printf "\n${Red}Sorry, you are not root.\n${Color_Off}You must type: ${Cyan}sudo ${Color_Off}bash %s/phppgadmin_install_ubuntu16.sh\n" "$SCRIPTS" + sleep 3 + exit 1 +fi + +# 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" + sleep 3 + exit 1 +fi + +# Check Ubuntu version +if [ "$OS" != 1 ] +then + echo "Ubuntu Server is required to run this script." + echo "Please install that distro and try again." + sleep 3 + exit 1 +fi + + +if ! version 16.04 "$DISTRO" 16.04.4; then + echo "Ubuntu version seems to be $DISTRO" + echo "It must be between 16.04 - 16.04.4" + echo "Please install that version and try again." + exit 1 +fi + +echo +echo "Installing and securing phpPGadmin..." +echo "This may take a while, please don't abort." +echo + +# Install phpPGadmin +apt update -q4 & spinner_loading +apt install -y -q \ + php-gettext \ + phppgadmin + +# Allow local access +sed -i "s|Require local|Require ip $GATEWAY/24|g" /etc/apache2/conf-available/phppgadmin.conf + +if ! service apache2 restart +then + echo "Apache2 could not restart..." + echo "The script will exit." + exit 1 +fi diff --git a/apps/previewgenerator.sh b/apps/previewgenerator.sh index 8a52d5c427..56cadf43fd 100644 --- a/apps/previewgenerator.sh +++ b/apps/previewgenerator.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -PREVIEW_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +PREVIEW_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset PREVIEW_INSTALL # Check for errors + debug code and abort if something isn't right diff --git a/apps/spreedme.sh b/apps/spreedme.sh index bb15575b20..f15798a5f1 100644 --- a/apps/spreedme.sh +++ b/apps/spreedme.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/apps/webmin.sh b/apps/webmin.sh index 1ea6c1a608..b7d9510fe6 100644 --- a/apps/webmin.sh +++ b/apps/webmin.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/lets-encrypt/activate-ssl.sh b/lets-encrypt/activate-ssl.sh index c0ca385ec0..ebb07d76eb 100644 --- a/lets-encrypt/activate-ssl.sh +++ b/lets-encrypt/activate-ssl.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/lets-encrypt/test-new-config.sh b/lets-encrypt/test-new-config.sh index d3e5cdffde..4c5e8b55df 100644 --- a/lets-encrypt/test-new-config.sh +++ b/lets-encrypt/test-new-config.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/lib.sh b/lib.sh index 3ece5158fe..94c3df3026 100644 --- a/lib.sh +++ b/lib.sh @@ -30,7 +30,7 @@ INTERFACES="/etc/network/interfaces" NETMASK=$($IFCONFIG | grep -w inet |grep -v 127.0.0.1| awk '{print $4}' | cut -d ":" -f 2) GATEWAY=$(route -n|grep "UG"|grep -v "UGH"|cut -f 10 -d " ") # Repo -GITHUB_REPO="https://raw.githubusercontent.com/nextcloud/vm/master" +GITHUB_REPO="https://raw.githubusercontent.com/nextcloud/vm/postgresql" STATIC="$GITHUB_REPO/static" LETS_ENC="$GITHUB_REPO/lets-encrypt" APP="$GITHUB_REPO/apps" @@ -42,15 +42,19 @@ NCUSER=ncadmin UNIXUSER=$SUDO_USER UNIXUSER_PROFILE="/home/$UNIXUSER/.bash_profile" ROOT_PROFILE="/root/.bash_profile" -# MARIADB +# Database SHUF=$(shuf -i 25-29 -n 1) MARIADB_PASS=$(tr -dc "a-zA-Z0-9@#*=" < /dev/urandom | fold -w "$SHUF" | head -n 1) NEWMARIADBPASS=$(tr -dc "a-zA-Z0-9@#*=" < /dev/urandom | fold -w "$SHUF" | head -n 1) +PGDB_PASS=$(tr -dc "a-zA-Z0-9@#*=" < /dev/urandom | fold -w "$SHUF" | head -n 1) +NEWPGPASS=$(tr -dc "a-zA-Z0-9@#*=" < /dev/urandom | fold -w "$SHUF" | head -n 1) [ ! -z "$NCDB" ] && NCCONFIGDB=$(grep "dbname" $NCPATH/config/config.php | awk '{print $3}' | sed "s/[',]//g") +[ ! -z "$NCDBPASS" ] && NCCONFIGDBPASS=$(grep "dbpassword" $NCPATH/config/config.php | awk '{print $3}' | sed "s/[',]//g") MYCNF=/root/.my.cnf [ ! -z "$MYCNFPW" ] && MARIADBMYCNFPASS=$(grep "password" $MYCNF | sed -n "/password/s/^password='\(.*\)'$/\1/p") # Path to specific files PHPMYADMIN_CONF="/etc/apache2/conf-available/phpmyadmin.conf" +PHPMPGDMIN_CONF="/etc/apache2/conf-available/phppgadmin.conf" SECURE="$SCRIPTS/setup_secure_permissions_nextcloud.sh" SSL_CONF="/etc/apache2/sites-available/nextcloud_ssl_domain_self_signed.conf" HTTP_CONF="/etc/apache2/sites-available/nextcloud_http_domain_self_signed.conf" @@ -175,6 +179,15 @@ sed -i 's/ php_value post_max_size.*/# php_value post_max_size 511M/g' "$NCPATH sed -i 's/ php_value memory_limit.*/# php_value memory_limit 512M/g' "$NCPATH"/.htaccess } +# Check if program is installed (is_this_installed apache2) +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." + exit 1 +fi +} + # Test RAM size # Call it like this: ram_check [amount of min RAM in GB] [for which program] # Example: ram_check 2 Nextcloud diff --git a/nextcloud-startup-script.sh b/nextcloud-startup-script.sh index 8ef74995e5..f82a2d80a2 100644 --- a/nextcloud-startup-script.sh +++ b/nextcloud-startup-script.sh @@ -2,10 +2,9 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -NCDB=1 && MYCNFPW=1 && FIRST_IFACE=1 && CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +NCDB=1 && FIRST_IFACE=1 && CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset FIRST_IFACE unset CHECK_CURRENT_REPO -unset MYCNFPW unset NCDB # Tech and Me © - 2017, https://www.techandme.se/ @@ -54,7 +53,7 @@ else mv /etc/network/interfaces.new /etc/network/interfaces service networking restart # shellcheck source=lib.sh - CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) + CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset CHECK_CURRENT_REPO fi @@ -110,7 +109,7 @@ download_static_script trusted download_static_script ip download_static_script test_connection download_static_script setup_secure_permissions_nextcloud -download_static_script change_mysql_pass +download_static_script change_db_pass download_static_script nextcloud download_static_script update-config download_static_script index @@ -135,9 +134,8 @@ echo "| This script will configure your Nextcloud and activate SSL. |" echo "| It will also do the following: |" echo "| |" echo "| - Generate new SSH keys for the server |" -echo "| - Generate new MARIADB password |" -echo "| - Configure UTF8mb4 (4-byte support for MARIADB) |" -echo "| - Install phpMyadmin and make it secure |" +echo "| - Generate new PostgreSQL password |" +echo "| - Install phpPGadmin and make it secure |" echo "| - Install selected apps and automatically configure them |" echo "| - Detect and set hostname |" echo "| - Upgrade your system and Nextcloud to latest version |" @@ -242,44 +240,9 @@ rm -v /etc/ssh/ssh_host_* dpkg-reconfigure openssh-server # Generate new MARIADB password -echo "Generating new MARIADB password..." -if bash "$SCRIPTS/change_mysql_pass.sh" && wait -then - rm "$SCRIPTS/change_mysql_pass.sh" - { - echo - echo "[mysqld]" - echo "innodb_large_prefix=on" - echo "innodb_file_format=barracuda" - echo "innodb_flush_neighbors=0" - echo "innodb_adaptive_flushing=1" - echo "innodb_flush_method = O_DIRECT" - echo "innodb_doublewrite = 0" - echo "innodb_file_per_table = 1" - echo "innodb_flush_log_at_trx_commit=1" - echo "init-connect='SET NAMES utf8mb4'" - echo "collation_server=utf8mb4_unicode_ci" - echo "character_set_server=utf8mb4" - echo "skip-character-set-client-handshake" - - echo "[mariadb]" - echo "innodb_use_fallocate = 1" - echo "innodb_use_atomic_writes = 1" - echo "innodb_use_trim = 1" - } >> /root/.my.cnf -fi - -# Enable UTF8mb4 (4-byte support) -printf "\nEnabling UTF8mb4 support on $NCCONFIGDB....\n" -echo "Please be patient, it may take a while." -sudo /etc/init.d/mysql restart & spinner_loading -RESULT="mysqlshow --user=root --password=$MARIADBMYCNFPASS $NCCONFIGDB| grep -v Wildcard | grep -o $NCCONFIGDB" -if [ "$RESULT" == "$NCCONFIGDB" ]; then - check_command mysql -u root -e "ALTER DATABASE $NCCONFIGDB CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" - wait -fi -check_command sudo -u www-data $NCPATH/occ config:system:set mysql.utf8mb4 --type boolean --value="true" -check_command sudo -u www-data $NCPATH/occ maintenance:repair +echo "Generating new PostgreSQL password..." +check_command bash "$SCRIPTS/change_db_pass.sh" +sleep 3 clear cat << LETSENC @@ -310,7 +273,7 @@ clear whiptail --title "Which apps do you want to install?" --checklist --separate-output "Automatically configure and install selected apps\nSelect by pressing the spacebar" "$WT_HEIGHT" "$WT_WIDTH" 4 \ "Fail2ban" "(Extra Bruteforce protection) " OFF \ -"phpMyadmin" "(*SQL GUI) " OFF \ +"phpPGadmin" "(PostgreSQL GUI) " OFF \ "Collabora" "(Online editing 2GB RAM) " OFF \ "OnlyOffice" "(Online editing 4GB RAM) " OFF \ "Nextant" "(Full text search) " OFF \ @@ -324,8 +287,8 @@ do run_app_script fail2ban ;; - phpMyadmin) - run_app_script phpmyadmin_install_ubuntu16 + phpPGadmin) + run_app_script phppgadmin_install_ubuntu16 ;; OnlyOffice) @@ -467,7 +430,7 @@ printf "| ${Color_Off}Login to Nextcloud in your browser: ${Cyan}\"$ADDR echo "| |" printf "| ${Color_Off}Publish your server online! ${Cyan}https://goo.gl/iUGE2U${Green} |\n" echo "| |" -printf "| ${Color_Off}To login to MARIADB just type: ${Cyan}'mysql -u root'${Green} |\n" +printf "| ${Color_Off}To login to PostgreSQL just type: ${Cyan}'sudo -u postgres psql'${Green} |\n" echo "| |" printf "| ${Color_Off}To update this VM just type: ${Cyan}'sudo bash /var/scripts/update.sh'${Green} |\n" echo "| |" diff --git a/nextcloud_install_production.sh b/nextcloud_install_production.sh index 11c942696b..e6afbf3d45 100644 --- a/nextcloud_install_production.sh +++ b/nextcloud_install_production.sh @@ -8,7 +8,7 @@ sed -i "s|#precedence ::ffff:0:0/96 100|precedence ::ffff:0:0/96 100|g" /etc/g # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -FIRST_IFACE=1 && CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +FIRST_IFACE=1 && CHECK_CURRENT_REPO=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset FIRST_IFACE unset CHECK_CURRENT_REPO @@ -62,30 +62,11 @@ then fi # Check if it's a clean server -echo "Checking if it's a clean server..." -if [ "$(dpkg-query -W -f='${Status}' mysql-common 2>/dev/null | grep -c "ok installed")" == "1" ] -then - echo "MySQL is installed, it must be a clean server." - exit 1 -fi - -if [ "$(dpkg-query -W -f='${Status}' mariadb-server 2>/dev/null | grep -c "ok installed")" == "1" ] -then - echo "MariaDB is installed, it must be a clean server." - exit 1 -fi - -if [ "$(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed")" == "1" ] -then - echo "Apache2 is installed, it must be a clean server." - exit 1 -fi - -if [ "$(dpkg-query -W -f='${Status}' php 2>/dev/null | grep -c "ok installed")" == "1" ] -then - echo "PHP is installed, it must be a clean server." - exit 1 -fi +is_this_installed postgresql +is_this_installed apache2 +is_this_installed php +is_this_installed mysql-common +is_this_installed mariadb-server # Create $SCRIPTS dir if [ ! -d "$SCRIPTS" ] @@ -157,76 +138,19 @@ else clear fi -# Update system +# Install PostgreSQL +sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main'" > $ +wget -nv https://www.postgresql.org/media/keys/ACCC4CF8.asc -O postgres.key +apt-key add - < postgres.key && rm -f postgres.key apt update -q4 & spinner_loading -# Write MARIADB pass to file and keep it safe -cat << LOGIN > "$MYCNF" -[client] -password='$MARIADB_PASS' -default-character-set = utf8mb4 - -[mariadb] -innodb_use_fallocate = 1 -innodb_use_atomic_writes = 1 -innodb_use_trim = 1 - -[mysql] -default-character-set = utf8mb4 - -[mysqld] -innodb_large_prefix=on -innodb_file_format=barracuda -innodb_flush_neighbors=0 -innodb_adaptive_flushing=1 -innodb_flush_method = O_DIRECT -innodb_doublewrite = 0 -innodb_file_per_table = 1 -innodb_flush_log_at_trx_commit=1 -init-connect='SET NAMES utf8mb4' -collation_server=utf8mb4_unicode_ci -character_set_server=utf8mb4 -skip-character-set-client-handshake -LOGIN -chmod 0600 $MYCNF -chown root:root $MYCNF - -# Install MARIADB -apt install software-properties-common -y -sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 -sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.ddg.lth.se/mariadb/repo/10.2/ubuntu xenial main' -sudo debconf-set-selections <<< "mariadb-server-10.2 mysql-server/root_password password $MARIADB_PASS" -sudo debconf-set-selections <<< "mariadb-server-10.2 mysql-server/root_password_again password $MARIADB_PASS" -apt update -q4 & spinner_loading -check_command apt install mariadb-server-10.2 -y - -# Prepare for Nextcloud installation -# https://blog.v-gar.de/2017/02/en-solved-error-1698-28000-in-mysqlmariadb/ -mysql -u root mysql -p"$MARIADB_PASS" -e "UPDATE user SET plugin='' WHERE user='root';" -mysql -u root mysql -p"$MARIADB_PASS" -e "UPDATE user SET password=PASSWORD('$MARIADB_PASS') WHERE user='root';" -mysql -u root -p"$MARIADB_PASS" -e "flush privileges;" - -# mysql_secure_installation -apt -y install expect -SECURE_MYSQL=$(expect -c " -set timeout 10 -spawn mysql_secure_installation -expect \"Enter current password for root (enter for none):\" -send \"$MARIADB_PASS\r\" -expect \"Change the root password?\" -send \"n\r\" -expect \"Remove anonymous users?\" -send \"y\r\" -expect \"Disallow root login remotely?\" -send \"y\r\" -expect \"Remove test database and access to it?\" -send \"y\r\" -expect \"Reload privilege tables now?\" -send \"y\r\" -expect eof -") -echo "$SECURE_MYSQL" -apt -y purge expect +apt install postgresql postgresql-contrib -y +cd /tmp +echo "CREATE USER $NCUSER WITH PASSWORD '$PGDB_PASS';" | sudo -u postgres psql +echo "CREATE DATABASE nextcloud_db TEMPLATE template0 ENCODING 'UNICODE';" | sudo -u postgres psql +echo "ALTER DATABASE nextcloud_db OWNER TO $NCUSER;" | sudo -u postgres psql +echo "GRANT ALL PRIVILEGES ON DATABASE nextcloud_db TO $NCUSER;" | sudo -u postgres psql +service postgresql restart # Install Apache check_command apt install apache2 -y @@ -243,7 +167,6 @@ apt update -q4 & spinner_loading check_command apt install -y \ libapache2-mod-php7.0 \ php7.0-common \ - php7.0-mysql \ php7.0-intl \ php7.0-mcrypt \ php7.0-ldap \ @@ -252,7 +175,6 @@ check_command apt install -y \ php7.0-gd \ php7.0-pgsql \ php7.0-json \ - php7.0-sqlite3 \ php7.0-curl \ php7.0-xml \ php7.0-zip \ @@ -283,17 +205,14 @@ rm "$HTML/$STABLEVERSION.tar.bz2" download_static_script setup_secure_permissions_nextcloud bash $SECURE & spinner_loading -# Create database nextcloud_db -mysql -u root -p"$MARIADB_PASS" -e "CREATE DATABASE IF NOT EXISTS nextcloud_db;" - # Install Nextcloud cd "$NCPATH" check_command sudo -u www-data php occ maintenance:install \ --data-dir "$NCDATA" \ - --database "mysql" \ + --database "pgsql" \ --database-name "nextcloud_db" \ - --database-user "root" \ - --database-pass "$MARIADB_PASS" \ + --database-user "$NCUSER" \ + --database-pass "$PGDB_PASS" \ --admin-user "$NCUSER" \ --admin-pass "$NCPASS" echo diff --git a/nextcloud_update.sh b/nextcloud_update.sh index 8d59f07eae..2760aa2863 100644 --- a/nextcloud_update.sh +++ b/nextcloud_update.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -NCDB=1 && MYCNFPW=1 && NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +NCDB=1 && MYCNFPW=1 && NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset NC_UPDATE unset MYCNFPW unset NCDB @@ -121,35 +121,38 @@ else fi # Make sure old instaces can upgrade as well -if [ ! -f "$MYCNF" ] && [ -f /var/mysql_password.txt ] +if which mysql > /dev/null then - regressionpw=$(cat /var/mysql_password.txt) -cat << LOGIN > "$MYCNF" -[client] -password='$regressionpw' -LOGIN - chmod 0600 $MYCNF - chown root:root $MYCNF - echo "Please restart the upgrade process, we fixed the password file $MYCNF." - exit 1 -elif [ -z "$MARIADBMYCNFPASS" ] && [ -f /var/mysql_password.txt ] -then - regressionpw=$(cat /var/mysql_password.txt) - { - echo "[client]" - echo "password='$regressionpw'" - } >> "$MYCNF" - echo "Please restart the upgrade process, we fixed the password file $MYCNF." - exit 1 -fi + if [ ! -f "$MYCNF" ] && [ -f /var/mysql_password.txt ] + then + regressionpw=$(cat /var/mysql_password.txt) + { + echo "[client]" + echo "password='$regressionpw'" + } > "$MYCNF" + chmod 0600 $MYCNF + chown root:root $MYCNF + echo "Please restart the upgrade process, we fixed the password file $MYCNF." + exit 1 + elif [ -z "$MARIADBMYCNFPASS" ] && [ -f /var/mysql_password.txt ] + then + regressionpw=$(cat /var/mysql_password.txt) + { + echo "[client]" + echo "password='$regressionpw'" + } >> "$MYCNF" + echo "Please restart the upgrade process, we fixed the password file $MYCNF." + exit 1 + fi -if [ -z "$MARIADBMYCNFPASS" ] -then - echo "Something went wrong with copying your mysql password to $MYCNF." - echo "Please report this issue to $ISSUES, thanks!" - exit 1 -else - rm -f /var/mysql_password.txt + if [ -z "$MARIADBMYCNFPASS" ] + then + echo "Something went wrong with copying your mysql password to $MYCNF." + echo "Please report this issue to $ISSUES, thanks!" + exit 1 + else + rm -f /var/mysql_password.txt + fi fi echo "Backing up files and upgrading to Nextcloud $NCVERSION in 10 seconds..." @@ -187,14 +190,29 @@ else printf "${Green}\nBackup OK!${Color_Off}\n" fi -# Backup MARIADB -if mysql -u root -p"$MARIADBMYCNFPASS" -e "SHOW DATABASES LIKE '$NCCONFIGDB'" > /dev/null +# Backup PostgreSQL +if which psql > /dev/null then - echo "Doing mysqldump of $NCCONFIGDB..." - check_command mysqldump -u root -p"$MARIADBMYCNFPASS" -d "$NCCONFIGDB" > "$BACKUP"/nextclouddb.sql -else - echo "Doing mysqldump of all databases..." - check_command mysqldump -u root -p"$MARIADBMYCNFPASS" -d --all-databases > "$BACKUP"/alldatabases.sql + 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..." + check_command sudo -u postgres pg_dump "$NCCONFIGDB" > "$BACKUP"/nextclouddb.sql + else + echo "Doing pgdump of all databases..." + check_command sudo -u postgres psql pgdump_all > "$BACKUP"/alldatabases.sql + fi +elif which mysql > /dev/null +then + # Backup MARIADB + if mysql -u root -p"$MARIADBMYCNFPASS" -e "SHOW DATABASES LIKE '$NCCONFIGDB'" > /dev/null + then + echo "Doing mysqldump of $NCCONFIGDB..." + check_command mysqldump -u root -p"$MARIADBMYCNFPASS" -d "$NCCONFIGDB" > "$BACKUP"/nextclouddb.sql + else + echo "Doing mysqldump of all databases..." + check_command mysqldump -u root -p"$MARIADBMYCNFPASS" -d --all-databases > "$BACKUP"/alldatabases.sql + fi fi # Download and validate Nextcloud package diff --git a/static/adduser.sh b/static/adduser.sh index 64eb9ad2d1..95bc53fe4f 100644 --- a/static/adduser.sh +++ b/static/adduser.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/static/change-ncadmin-profile.sh b/static/change-ncadmin-profile.sh index f88a7a0bf5..88678fb2fb 100644 --- a/static/change-ncadmin-profile.sh +++ b/static/change-ncadmin-profile.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/change-root-profile.sh b/static/change-root-profile.sh index 4b07e03b02..deb00dd5e9 100644 --- a/static/change-root-profile.sh +++ b/static/change-root-profile.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/change_db_pass.sh b/static/change_db_pass.sh new file mode 100644 index 0000000000..179573f1c9 --- /dev/null +++ b/static/change_db_pass.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# shellcheck disable=2034,2059 +true +# shellcheck source=lib.sh +NCDBPASS=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) +unset NCDBPASS + +# Tech and Me © - 2017, https://www.techandme.se/ + +# Check for errors + debug code and abort if something isn't right +# 1 = ON +# 0 = OFF +DEBUG=0 +debug_mode + +# Change PostgreSQL Password +sudo -u www-data php "$NCPATH"/occ config:system:set dbpassword --value="$NEWPGPASS" + +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}" +else + echo "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" + exit 1 +fi diff --git a/static/change_mysql_pass.sh b/static/change_mysql_pass.sh deleted file mode 100644 index c23bd52472..0000000000 --- a/static/change_mysql_pass.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# shellcheck disable=2034,2059 -true -# shellcheck source=lib.sh -MYCNFPW=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) -unset MYCNFPW - -# Tech and Me © - 2017, https://www.techandme.se/ - -# Check for errors + debug code and abort if something isn't right -# 1 = ON -# 0 = OFF -DEBUG=0 -debug_mode - -# Change MARIADB Password -if mysqladmin -u root -p"$MARIADBMYCNFPASS" password "$NEWMARIADBPASS" > /dev/null 2>&1 -then - echo -e "${Green}Your new MARIADB root password is: $NEWMARIADBPASS${Color_Off}" - cat << LOGIN > "$MYCNF" -[client] -password='$NEWMARIADBPASS' -LOGIN - chmod 0600 $MYCNF - exit 0 -else - echo "Changing MARIADB root password failed." - echo "Your old password is: $MARIADBMYCNFPASS" - exit 1 -fi diff --git a/static/instruction.sh b/static/instruction.sh index c2ceded759..a2683846d5 100644 --- a/static/instruction.sh +++ b/static/instruction.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/ip.sh b/static/ip.sh index 2010937aa1..9000c0600e 100644 --- a/static/ip.sh +++ b/static/ip.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -FIRST_IFACE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +FIRST_IFACE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset FIRST_IFACE # Check for errors + debug code and abort if something isn't right diff --git a/static/ip2.sh b/static/ip2.sh index 909b3ddf88..929ef974f0 100644 --- a/static/ip2.sh +++ b/static/ip2.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/nextcloud.sh b/static/nextcloud.sh index 48b63d4c34..49f55a959a 100644 --- a/static/nextcloud.sh +++ b/static/nextcloud.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -LOAD_IP6=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +LOAD_IP6=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) unset LOAD_IP6 # Check for errors + debug code and abort if something isn't right diff --git a/static/ntpdate.sh b/static/ntpdate.sh index 21df547e03..d090deb430 100644 --- a/static/ntpdate.sh +++ b/static/ntpdate.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/redis-server-ubuntu16.sh b/static/redis-server-ubuntu16.sh index 6850c9f9a0..72c95b429e 100644 --- a/static/redis-server-ubuntu16.sh +++ b/static/redis-server-ubuntu16.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/static/security.sh b/static/security.sh index 91fdb6ab12..a898fd8e46 100644 --- a/static/security.sh +++ b/static/security.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/setup_secure_permissions_nextcloud.sh b/static/setup_secure_permissions_nextcloud.sh index 451df76e7e..40f6ad5464 100644 --- a/static/setup_secure_permissions_nextcloud.sh +++ b/static/setup_secure_permissions_nextcloud.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/temporary-fix.sh b/static/temporary-fix.sh index d9d9f96edc..38369191f3 100644 --- a/static/temporary-fix.sh +++ b/static/temporary-fix.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/test_connection.sh b/static/test_connection.sh index 89582213e9..016fff92d4 100644 --- a/static/test_connection.sh +++ b/static/test_connection.sh @@ -2,7 +2,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Tech and Me © - 2017, https://www.techandme.se/ diff --git a/static/trusted.sh b/static/trusted.sh index 85fd8856b2..2ccdd95bfb 100644 --- a/static/trusted.sh +++ b/static/trusted.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON diff --git a/static/update.sh b/static/update.sh index 775d6e5ff7..0a9d890c85 100644 --- a/static/update.sh +++ b/static/update.sh @@ -5,7 +5,7 @@ # shellcheck disable=2034,2059 true # shellcheck source=lib.sh -. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/postgresql/lib.sh) # Check for errors + debug code and abort if something isn't right # 1 = ON