#!/bin/bash # ## Piet's Host ## - ©2017, https://piets-host.de # # Tested on: # CentOS 6.8 & 7.3, # Ubuntu 12.04, 14.04, 16.04, # Debian 7 & 8, # Fedora 23, 24 & 25, # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin # disable user input stty -echo clear ################################## ###### DEFAULT VAR START ##### ################################## url1="http://example.com" ncname="my_nextcloud" dbhost="localhost" dbtype="mysql" rootuser='root' html='/var/www/html' # full installation path folder='nextcloud1' # E-mail email="mail@example.com" smtpauth="LOGIN" smtpport="587" smtpname="admin@example.com" smtpsec="tls" smtppwd="password1234!" smtpauthreq=1 # Others displayname='true' rlchannel='stable' memcache='APCu' maintenance='false' singleuser='false' skeleton='none' default_language='de' enable_avatars='true' rewritebase='false' depend="true" overwrite="true" isconfig="false" config_to_read="default.json" ################################ ###### DEFAULT VAR END ##### ################################ # Set colors for printf output red='\e[31m' green='\e[32m' yellow='\e[33m' reset='\e[0m' redbg='\e[41m' lightred='\e[91m' blue='\e[34m' cyan='\e[36m' ugreen='\e[4;32m' show_help() { cat << EOF Usage: ${0##*/} [-v VERSION] [-n NAME]... You can specify some variables before script run. E.g. you can set the Nextcloud version or the MySQL root password. If no option is set, the script will use default variables and you can set them during script run (you will be asked) :-) -h --help display this help and exit -v --version specify Nextcloud Version (e.g. 10.0.0) -p --password sets the MySQL root password. Type -p "P@s§" -r --root sets the MySQL root user -m --mysqlhost sets the MySQL Host -n --name sets the Nextcloud name, used for Database -u --url sets the URL for Nextcloud installation -d --directory sets the full installation path -f --folder sets the desired folder (example.com/folder). May be empty -s --smtp setup SMTP during script run (Type -s "y" or -s "n") -a --apps setup additionals apps during run (Type -a "y" or -a "n") -c --config path to JSON config file EOF } while :; do case $1 in -h|-\?|--help|\?) # Call "show_help" function , then exit. show_help stty echo exit ;; -v|--version) # Takes an option argument, ensuring it has been specified. if [ -n "$2" ]; then version="$2" shift else printf $redbg'ERROR: "--version" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -p|--password) if [ -n "$2" ]; then database_root="$2" shift else printf $redbg'ERROR: "--password" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -r|--root) if [ -n "$2" ]; then dbruser="$2" shift else printf $redbg'ERROR: "--root" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -m|--mysqlhost) if [ -n "$2" ]; then dbhost="$2" shift else printf $redbg'ERROR: "--mysqlhost" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -n|--name) if [ -n "$2" ]; then ncname="$2" shift else printf $redbg'ERROR: "--name" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -c|--config) if [ -n "$2" ]; then if [ -f "$2" ]; then config_to_read="$2" isconfig="true" else printf $redbg'ERROR: "--config" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi fi ;; -u|--url) if [ -n "$2" ]; then url1="$2" shift else printf $redbg'ERROR: "--url" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -d|--directory) if [ -n "$2" ]; then html="$2" shift else printf $redbg'ERROR: "--directory" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -f|--folder) folder="$2" shift ;; -s|--smtp) if [ -n "$2" ]; then smtp="$2" shift else printf $redbg'ERROR: "--smtp" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; -a|--apps) if [ -n "$2" ]; then appsinstall="$2" shift else printf $redbg'ERROR: "--apps" requires a non-empty option argument.' >&2 printf $reset"\n" stty echo exit 1 fi ;; --) # End of all options. shift break ;; -?*) printf $redbg'Invalid option: %s' "$1" >&2 printf $reset"\n" stty echo exit 0 ;; *) # Default case: If no more options then break out of the loop. break esac shift done # Set Header header=' _____ _ _ _ _ _ | __ (_) | | | | | | | | | |__) | ___| |_ ___ | |__| | ___ ___| |_ | ___/ |/ _ \ __/ __| | __ |/ _ \/ __| __| +-+-+-+-+ | | | | __/ |_\__ \ | | | | (_) \__ \ |_ | v 1.7 | |_| |_|\___|\__|___/ |_| |_|\___/|___/\__| +-+-+-+-+' # Set color for Status check_ok=$green" OK "$reset check_miss=$redbg"MISSING"$reset # Define latest Nextcloud version ncrepo="https://download.nextcloud.com/server/releases" # Must be root [[ `id -u` -eq 0 ]] || { echo "Root privileges required, type: sudo -i"; stty echo; exit 1; } # Read JSON config file function jsonconfig { echo "Reading JSON config $config_to_read ..." chmod 0644 $config_to_read sleep 0.5 # General - SQL dbhost=$(json -f "$config_to_read" general.sql.dbhost) dbruser=$(json -f "$config_to_read" general.sql.dbruser) dbtype=$(json -f "$config_to_read" general.sql.dbtype) database_root=$(json -f "$config_to_read" general.sql.database_root) # General - HTML url1=$(json -f "$config_to_read" general.html.url1) ncname=$(json -f "$config_to_read" general.html.ncname) html=$(json -f "$config_to_read" general.html.html) folder=$(json -f "$config_to_read" general.html.folder) # General - Perm rootuser=$(json -f "$config_to_read" general.perm.rootuser) htuser=$(json -f "$config_to_read" general.perm.htuser) htgroup=$(json -f "$config_to_read" general.perm.htgroup) # General - Other depend=$(json -f "$config_to_read" general.other.depend) rebootsrv=$(json -f "$config_to_read" general.other.rebootsrv) overwrite=$(json -f "$config_to_read" general.other.overwrite) adminuser=$(json -f "$config_to_read" general.other.adminuser) smtp=$(json -f "$config_to_read" general.other.smtp) appsinstall=$(json -f "$config_to_read" general.other.appsinstall) version=$(json -f "$config_to_read" general.other.version) # General - E-mail email=$(json -f "$config_to_read" general.mail.email) smtpauth=$(json -f "$config_to_read" general.mail.smtpauth) smtpport=$(json -f "$config_to_read" general.mail.smtpport) smtpname=$(json -f "$config_to_read" general.mail.smtpname) smtpsec=$(json -f "$config_to_read" general.mail.smtpsec) smtppwd=$(json -f "$config_to_read" general.mail.smtppwd) smtpauthreq=$(json -f "$config_to_read" general.mail.smtpauthreq) smtphost=$(json -f "$config_to_read" general.mail.smtphost) smtpdomain=$(json -f "$config_to_read" general.mail.smtpdomain) # Config - Custom displayname=$(json -f "$config_to_read" config.custom.displayname) rlchannel=$(json -f "$config_to_read" config.custom.rlchannel) memcache=$(json -f "$config_to_read" config.custom.memcache) maintenance=$(json -f "$config_to_read" config.custom.maintenance) singleuser=$(json -f "$config_to_read" config.custom.singleuser) skeleton=$(json -f "$config_to_read" config.custom.skeleton) default_language=$(json -f "$config_to_read" config.custom.default_language) enable_avatars=$(json -f "$config_to_read" config.custom.enable_avatars) rewritebase=$(json -f "$config_to_read" config.custom.rewritebase) # Config - Apps contactsinstall=$(json -f "$config_to_read" apps.integrated.contactsinstall) calendarinstall=$(json -f "$config_to_read" apps.integrated.calendarinstall) mailinstall=$(json -f "$config_to_read" apps.integrated.mailinstall) notesinstall=$(json -f "$config_to_read" apps.integrated.notesinstall) tasksinstall=$(json -f "$config_to_read" apps.integrated.tasksinstall) galleryinstall=$(json -f "$config_to_read" apps.integrated.galleryinstall) impinstall=$(json -f "$config_to_read" apps.3rdparty.impinstall) echo "" } printf $green"$header"$reset echo "" echo "" # Read JSON config if [[ "$isconfig" = "true" ]]; then begin=$(date +%s) jsonconfig else # Apps contactsinstall='true' calendarinstall='true' mailinstall='false' notesinstall='false' tasksinstall='false' galleryinstall='false' impinstall='false' fi ################################### ###### BEFORE SETUP START ##### ################################### function sleeping { if [[ "$isconfig" = "true" ]]; then sleep 1 else sleep 0.2 fi } function sleeping2 { if [[ "$isconfig" = "true" ]]; then sleep 2 else sleep 0.2 fi } function abort { echo "" stty echo exit 0 } function plesk { dbruser='admin' database_root="`cat /etc/psa/.psa.shadow`" htgroup='psacln' perm='plesk' } printf "Checking minimal system requirements...\n" echo "" sleeping # Ensure the OS is compatible with the installer if [ -f /etc/centos-release ]; then os="CentOs" verfull=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release) ver=${verfull:0:1} elif [ -f /etc/lsb-release ]; then os=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//') ver=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//') elif [ -f /etc/fedora-release ]; then os=$(grep -w ID /etc/os-release | sed 's/^.*=//') ver=$(grep VERSION_ID /etc/os-release | cut -c 12-) elif [ -f /etc/os-release ]; then os=$(grep -w ID /etc/os-release | sed 's/^.*=//') ver=$(grep VERSION_ID /etc/os-release | sed 's/^.*"\(.*\)"/\1/') else os=$(uname -s) ver=$(uname -r) fi arch=$(uname -m) printf $yellow"Detected : $os $ver $arch\n"$reset echo "" sleeping if [[ "$os" = "CentOs" && ("$ver" = "6" || "$ver" = "7" ) || "$os" = "Ubuntu" && ("$ver" = "12.04" || "$ver" = "14.04" || "$ver" = "16.04" ) || "$os" = "debian" && ("$ver" = "7" || "$ver" = "8" ) || "$os" = "fedora" && ("$ver" = "23" || "$ver" = "24" || "$ver" = "25") ]]; then printf $green"Very Good! Your OS is compatible.\n"$reset echo "" sleeping else printf $red"Unfortunately, this OS is not supported by Piet's Host Install-script for Nextcloud.\n"$reset sleeping2 abort fi sleeping if [[ "$os" = "Ubuntu" && ("$ver" = "12.04" || "$ver" = "14.04" || "$ver" = "16.04" ) ]]; then if [[ "$overwrite" = "true" ]]; then #Check for Plesk installation echo "checking additional control panels..." if dpkg -l | grep -q psa; then plesk fi rootuser='root' dbruser='root' htgroup='www-data' htuser='www-data' else if [[ "$isconfig" = "true" ]]; then rootuser=$(json -f "$config_to_read" general.perm.rootuser) dbruser=$(json -f "$config_to_read" general.sql.dbruser) htuser=$(json -f "$config_to_read" general.perm.htuser) htgroup=$(json -f "$config_to_read" general.perm.htgroup) fi fi elif [[ "$os" = "debian" && ("$ver" = "7" || "$ver" = "8" ) ]]; then if [[ "$overwrite" = "true" ]]; then #Check for Plesk installation echo "checking additional control panels..." if dpkg -l | grep -qw psa; then plesk fi rootuser='root' dbruser='root' htgroup='www-data' htuser='www-data' else if [[ "$isconfig" = "true" ]]; then rootuser=$(json -f "$config_to_read" general.perm.rootuser) dbruser=$(json -f "$config_to_read" general.sql.dbruser) htuser=$(json -f "$config_to_read" general.perm.htuser) htgroup=$(json -f "$config_to_read" general.perm.htgroup) fi fi elif [[ "$os" = "CentOs" && ("$ver" = "6" || "$ver" = "7" ) ]]; then if [[ "$overwrite" = "true" ]]; then #Check for Plesk installation echo "checking additional control panels..." if rpm -qa | grep -q psa; then plesk fi rootuser='root' dbruser='root' htgroup='apache' htuser='apache' else if [[ "$isconfig" = "true" ]]; then rootuser=$(json -f "$config_to_read" general.perm.rootuser) dbruser=$(json -f "$config_to_read" general.sql.dbruser) htuser=$(json -f "$config_to_read" general.perm.htuser) htgroup=$(json -f "$config_to_read" general.perm.htgroup) fi fi elif [[ "$os" = "fedora" && ("$ver" = "23" || "$ver" = "25") ]]; then if [[ "$overwrite" = "true" ]]; then #Check for Plesk installation echo "checking additional control panels..." if rpm -qa | grep -qw psa; then plesk fi rootuser='root' dbruser='root' htgroup='apache' htuser='apache' else if [[ "$isconfig" = "true" ]]; then rootuser=$(json -f "$config_to_read" general.perm.rootuser) dbruser=$(json -f "$config_to_read" general.sql.dbruser) htuser=$(json -f "$config_to_read" general.perm.htuser) htgroup=$(json -f "$config_to_read" general.perm.htgroup) fi fi fi if [[ "$depend" = "false" ]]; then printf $yellow"Skipping dependencies check...\n"$reset sleeping else echo "" printf $yellow"Installing dependencies...(may take some time)\n"$reset { if [[ "$os" = "Ubuntu" && ("$ver" = "12.04" || "$ver" = "14.04" || "$ver" = "16.04" ) ]]; then dpkg -l | grep -qw pv || apt-get install pv -y dpkg -l | grep -qw bzip2 || apt-get install bzip2 -y dpkg -l | grep -qw rsync || apt-get install rsync -y dpkg -l | gr