#!/usr/bin/env bash exec > >(tee /root/nextcloudDeploy.log) if [ -d /var/www/html ]; then if [ "$(ls -A /var/www/html)" ]; then echo "Error: /var/www/html is not empty. Please clean it up" ls -A /var/www/html exit 1 else wget https://download.nextcloud.com/server/releases/latest.zip -O /var/www/latest.zip && unzip /var/www/latest.zip -d /var/www/ && mv /var/www/nextcloud/* /var/www/html/ && rm -rf /var/www/nextcloud/ nginxUser="$(awk '/user / {print $NF}' /etc/nginx/nginx.conf | sed 's#;##g')" nginxGroup="$(id -Gn www-data)" chown -R ${nginxUser}:${nginxGroup} /var/www/html /var/www/latest.zip fi fi read -p "Do you need database details? [N/y] " prompt < /dev/tty echo ${prompt,,} if [ "${prompt,,}" == "y" ]; then dbName="nextcl0ud" dbUser="nextcl0ud" dbPass=$(openssl rand -base64 12) query="CREATE OR REPLACE USER '${dbName}'@'localhost' IDENTIFIED BY '${dbPass}'; CREATE DATABASE IF NOT EXISTS ${dbName}; GRANT ALL ON ${dbName}.* TO '${dbName}'@'localhost'; FLUSH PRIVILEGES;" if [ "$(mariadb-admin ping)" == "mysqld is alive" ]; then mariadb -B -N -e "${query}" echo "Executed..." else echo "Sorry. I don't have database access" echo "You can run this query:" echo "" echo "${query}" echo "" fi echo "Database host: localhost" echo "Database user: ${dbUser}" echo "Database pass: ${dbPass}" echo "Database name: ${dbName}" fi unset prompt