#!/bin/bash INSTALLERVERSION="1.01.02" if [[ $(whoami) != "root" ]]; then echo "You must be root to run this script!" exit 1 fi function compareVersions { if [[ -z "$1" || -z "$2" ]]; then echo "Failed to compare versions..." >&2 return 1 fi IFS='.' read -ra versionold <<< "$1" IFS='.' read -ra versionnew <<< "$2" for ((n=0; n<${#versionnew[@]}; n++)); do versionnew[$n]=$((10#${versionnew[$n]})) done for ((n=0; n<${#versionold[@]}; n++)); do versionold[$n]=$((10#${versionold[$n]})) done while [[ ${#versionold[@]} -lt ${#versionnew[@]} ]]; do versionold+=(0); done while [[ ${#versionnew[@]} -lt ${#versionold[@]} ]]; do versionnew+=(0); done for ((n=0; n<${#versionnew[@]}; n++)); do if (( versionnew[n] > versionold[n] )); then return 0; fi if (( versionnew[n] < versionold[n] )); then return 1; fi done return 1 } function doMariaDB { echo "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root';" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "FLUSH PRIVILEGES;" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "UPDATE mysql.global_priv SET priv=json_set(priv, '$.plugin', 'mysql_native_password', '$.authentication_string', PASSWORD('basic_single_escape \"$DBROOTPASS\"')) WHERE User='root';" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "DELETE FROM mysql.global_priv WHERE User='';" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "DELETE FROM mysql.global_priv WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "DROP DATABASE IF EXISTS test;" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" | mysql > /dev/null 2>> installer-errors.log || return 1 echo "FLUSH PRIVILEGES;" | mysql > /dev/null 2>> installer-errors.log || return 1 } function doPHP { systemctl stop apache2 > /dev/null 2>> installer-errors.log && a2dismod php8.3 > /dev/null 2>> installer-errors.log && a2dismod mpm_prefork > /dev/null 2>> installer-errors.log && a2enmod mpm_event proxy proxy_fcgi setenvif rewrite > /dev/null 2>> installer-errors.log && a2enconf php8.3-fpm > /dev/null 2>> installer-errors.log && systemctl restart apache2 > /dev/null 2>> installer-errors.log || failMsg "PHP FPM failed to start..." echo ";;;;;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; Resource Limits ;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "max_execution_time = 240" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "memory_limit = 512M" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; Data Handling ;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "post_max_size = 512M" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; File Uploads ;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "upload_max_filesize = 2048M" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; Module Settings ;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo ";;;;;;;;;;;;;;;;;;;" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "[Date]" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; Defines the default timezone used by the date functions" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; https://php.net/date.timezone" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "date.timezone = $PHPTIMEZONE" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "[opcache]" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; Determines if Zend OPCache is enabled" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.enable=1" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; The OPcache shared memory storage size." >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.memory_consumption=1024" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; The amount of memory for interned strings in Mbytes." >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.interned_strings_buffer=128" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; The maximum number of keys (scripts) in the OPcache hash table." >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; Only numbers between 200 and 1000000 are allowed." >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.max_accelerated_files=50000" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; When disabled, you must reset the OPcache manually or restart the" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; webserver for changes to the filesystem to take effect." >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.validate_timestamps=0" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; How often (in seconds) to check file timestamps for changes to the shared" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; memory storage allocation. ("1" means validate once per second, but only" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; once per request. "0" means always validate)" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.revalidate_freq=60" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; If disabled, all PHPDoc comments are dropped from the code to reduce the" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "; size of the optimized code." >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini echo "opcache.save_comments=1" >> /etc/php/8.3/fpm/conf.d/99-nextcloud.ini systemctl restart php8.3-fpm.service > /dev/null 2>> installer-errors.log || failMsg "PHP FPM failed to load custom settings..." } function doREPORT { TODAY="$(date "+%Y-%m-%d")" touch "NEXTCLOUD-REPORT-$TODAY.md" echo "# NEXTCLOUD INSTALLATION REPORT" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Install Date:** $(date "+%B %-d, %Y")" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Installer Version:** $INSTALLERVERSION" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Installer Author:** Ze'ev Schurmann" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Installer License:** GPL 3.0 or later" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Installer Website:** https://git.zaks.web.za/thisiszeev/perfect-nextcloud-installer" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "## Logging onto Nextcloud" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "Open your browser to https://$FQDN" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Admin Username:** $NCADMIN" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Admin Password:** $NCPASS" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "## Setting up Talk App to use coTURN" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "1. Install the Talk App, then go to the Admin Settings and navigate to the section for Talk." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "2. Scroll down the page until you find the settings for the TURN server." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "3. Add a server." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "4. Use both turn: and turns:." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "5. The server URL is $FQDN." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "6. The secret is $TURNPASS." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "7. And set both UDP and TCP." >> "NEXTCLOUD-REPORT-$TODAY.md" echo "8. Now click on the wavey line and it will shortly change to a green tick." >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "If your server is behind a NAT Router or Firewall, you need to forward the following ports on your router to your server." >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "- 80, 443 (TCP)" >> "NEXTCLOUD-REPORT-$TODAY.md" echo "- 3478, 3479, 5349, 5350 (TCP & UDP)" >> "NEXTCLOUD-REPORT-$TODAY.md" echo "- 60000 to 61999 (TCP & UDP)" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "## MariaDB/MySQL Information:" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" if [[ $DBHOST == "localhost" ]]; then IFS=' ' read -ra temparray <<< $(mysql -V) echo "**MariaDB Server Version:** ${temparray[2]}" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**MySQL Root Password:** $DBROOTPASS" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" fi echo "**MySQL Server:** $DBHOST" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**MySQL Database Name:** $DBNAME" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**MySQL Database Username:** $DBUSER" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**MySQL Database Password:** $DBPASS" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "## Apache2 Information" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" IFS=' ' read -ra temparray <<< $(apache2 -v) IFS='/' read -ra temparray <<< $(echo ${temparray[2]}) echo "**Apache2 Version:** ${temparray[1]}" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Loaded Apache2 Modules:** $(apache2ctl -M 2>/dev/null | awk '/_module/ {print $1}' | sed 's/_module$//' | sort | paste -sd, - | sed 's/,/, /g')" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Apache2 VHost File (http):** /etc/apache2/sites-available/$NCWWW.conf" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Apache2 VHost File (https):** /etc/apache2/sites-available/$NCWWW-le-ssl.conf" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**NextCloud WebRoot:** /var/www/$NCWWW/" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**NextCloud Files:** /var/$NCFILES/" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "## PHP Information" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**PHP Version:** $(php-fpm8.3 -v | grep "^PHP 8.3")" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Loaded PHP Modules:** $(php-fpm8.3 -m | grep "^[[:alnum:]]\+" | sort | uniq | paste -sd, - | sed 's/,/, /g')" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" if [[ $AUTOSWAP == "true" ]]; then echo "## AutoSWAP Information" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "AutoSWAP is a free tool licensed under GPL 3.0 or later. It monitors your system for memory usage, and when free system memory drops below a threshold it will create additional SWAP memory using a SWAP file in the root folder. When sufficient memory frees up, it will remove the SWAP file. It can do extra SWAP files if your system gets really hungry for memory. You can learn more at https://git.zaks.web.za/thisiszeev/linux-server-tools/src/branch/main/swap-management" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Location of AutoSWAP configuration file:** /etc/autoswap/autoswap.conf" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" source /etc/autoswap/autoswap.conf echo "**Free system memory threshold:** $threshold_minimum MB" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**SWAP files size:** $swap_file_size MB" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Number of SWAP files that will permanently exist:** $required_swap_files" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**Minimum amount of harddrive space that must always exist:** $minimum_free_storage MB" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "**How often system memory is checked:** $check_interval seconds" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "These settings can be edited in the /etc/autoswap/autoswap.conf file. Run `systemctl restart autoswap.service` to activate the new settings." >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" fi echo "## Did I miss something?" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "If you have any suggestion to make this script better, please send me a chat request on Reddit u/thisiszeev" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "I am always open to ideas and suggestions to make this better. I have a lot more I still want to add to this script but as it stands this script is $(wc -l < "$0") lines of code and took me $(($(wc -l < "$0")/250+1)) energy drinks worth of time to create." >> "NEXTCLOUD-REPORT-$TODAY.md" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "One of the features that I am planning is a way to \"top-up\" and existing Nextcloud installation. In other words, it brings your server inline with the latest requirements of version of Nextcloud you have installed. Ie, change the PHP version, or install additional required modules, or tweak PHP configuration and Apache2 configuration. So keep an eye on https://git.zaks.web.za/thisiszeev/perfect-nextcloud-installer for updates." >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "I am an active participant on the unofficial Nextcloud subreddit https://www.reddit.com/r/NextCloud/" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "## Did you find this script helpful?" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "Please consider sending me a donation via https://paypal.me/thisiszeev" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "- \$5 buys me a beer" >> "NEXTCLOUD-REPORT-$TODAY.md" echo "- \$10 buys me a nice burger" >> "NEXTCLOUD-REPORT-$TODAY.md" echo "- \$20 buys me a bottle of wine" >> "NEXTCLOUD-REPORT-$TODAY.md" echo >> "NEXTCLOUD-REPORT-$TODAY.md" echo "If you do send a donation, please send me a chat request on Reddit: https://reddit.com/u/thisiszeev" >> "NEXTCLOUD-REPORT-$TODAY.md" echo echo "Your installation report is saved in this folder as NEXTCLOUD-REPORT-$TODAY.md" echo "It has all your important passwords and other information. Don't lose it." } function doSWAP { wget "https://git.zaks.web.za/thisiszeev/linux-server-tools/releases/download/autoswap/autoswap-v1.01.01.zip" > /dev/null 2>> installer-errors.log || failMsg "Failed to download Auto SWAP..." mkdir autoswap unzip autoswap-v1.01.01.zip -d ./autoswap mkdir /etc/autoswap mv ./autoswap/autoswap.conf /etc/autoswap/autoswap.conf mv ./autoswap/autoswap.sh /autoswap.sh chmod +x /autoswap.sh mv ./autoswap/addswap.sh /addswap.sh chmod +x /addswap.sh mv ./autoswap/remswap.sh /remswap.sh chmod +x /remswap.sh mv ./autoswap/README.md /etc/autoswap/README.md mv ./autoswap/LICENSE /etc/autoswap/LICENSE mv ./autoswap/autoswap.service /etc/systemd/system/autoswap.service rm -R ./autoswap rm autoswap-v1.01.01.zip systemctl start autoswap.service > /dev/null 2>> installer-errors.log || failMsg "Auto SWAP service failed to start..." systemctl enable autoswap.service > /dev/null 2>> installer-errors.log || failMsg "Auto SWAP service could not be enabled..." } function doTimezoneAfrica { local TZONES=("Africa/Abidjan" "Africa/Accra" "Africa/Addis_Ababa" "Africa/Algiers" "Africa/Asmara" "Africa/Bamako" "Africa/Bangui" "Africa/Banjul" "Africa/Bissau" "Africa/Blantyre" "Africa/Brazzaville" "Africa/Bujumbura" "Africa/Cairo" "Africa/Casablanca" "Africa/Ceuta" "Africa/Conakry" "Africa/Dakar" "Africa/Dar_es_Salaam" "Africa/Djibouti" "Africa/Douala" "Africa/El_Aaiun" "Africa/Freetown" "Africa/Gaborone" "Africa/Harare" "Africa/Johannesburg" "Africa/Juba" "Africa/Kampala" "Africa/Khartoum" "Africa/Kigali" "Africa/Kinshasa" "Africa/Lagos" "Africa/Libreville" "Africa/Lome" "Africa/Luanda" "Africa/Lubumbashi" "Africa/Lusaka" "Africa/Malabo" "Africa/Maputo" "Africa/Maseru" "Africa/Mbabane" "Africa/Mogadishu" "Africa/Monrovia" "Africa/Nairobi" "Africa/Ndjamena" "Africa/Niamey" "Africa/Nouakchott" "Africa/Ouagadougou" "Africa/Porto-Novo" "Africa/Sao_Tome" "Africa/Tripoli" "Africa/Tunis" "Africa/Windhoek") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneAmerica { local TZONES=("America/Adak" "America/Anchorage" "America/Anguilla" "America/Antigua" "America/Araguaina" "America/Argentina/Buenos_Aires" "America/Argentina/Catamarca" "America/Argentina/Cordoba" "America/Argentina/Jujuy" "America/Argentina/La_Rioja" "America/Argentina/Mendoza" "America/Argentina/Rio_Gallegos" "America/Argentina/Salta" "America/Argentina/San_Juan" "America/Argentina/San_Luis" "America/Argentina/Tucuman" "America/Argentina/Ushuaia" "America/Aruba" "America/Asuncion" "America/Atikokan" "America/Bahia" "America/Bahia_Banderas" "America/Barbados" "America/Belem" "America/Belize" "America/Blanc-Sablon" "America/Boa_Vista" "America/Bogota" "America/Boise" "America/Cambridge_Bay" "America/Campo_Grande" "America/Cancun" "America/Caracas" "America/Cayenne" "America/Cayman" "America/Chicago" "America/Chihuahua" "America/Ciudad_Juarez" "America/Costa_Rica" "America/Coyhaique" "America/Creston" "America/Cuiaba" "America/Curacao" "America/Danmarkshavn" "America/Dawson" "America/Dawson_Creek" "America/Denver" "America/Detroit" "America/Dominica" "America/Edmonton" "America/Eirunepe" "America/El_Salvador" "America/Fort_Nelson" "America/Fortaleza" "America/Glace_Bay" "America/Goose_Bay" "America/Grand_Turk" "America/Grenada" "America/Guadeloupe" "America/Guatemala" "America/Guayaquil" "America/Guyana" "America/Halifax" "America/Havana" "America/Hermosillo" "America/Indiana/Indianapolis" "America/Indiana/Knox" "America/Indiana/Marengo" "America/Indiana/Petersburg" "America/Indiana/Tell_City" "America/Indiana/Vevay" "America/Indiana/Vincennes" "America/Indiana/Winamac" "America/Inuvik" "America/Iqaluit" "America/Jamaica" "America/Juneau" "America/Kentucky/Louisville" "America/Kentucky/Monticello" "America/Kralendijk" "America/La_Paz" "America/Lima" "America/Los_Angeles" "America/Lower_Princes" "America/Maceio" "America/Managua" "America/Manaus" "America/Marigot" "America/Martinique" "America/Matamoros" "America/Mazatlan" "America/Menominee" "America/Merida" "America/Metlakatla" "America/Mexico_City" "America/Miquelon" "America/Moncton" "America/Monterrey" "America/Montevideo" "America/Montserrat" "America/Nassau" "America/New_York" "America/Nome" "America/Noronha" "America/North_Dakota/Beulah" "America/North_Dakota/Center" "America/North_Dakota/New_Salem" "America/Nuuk" "America/Ojinaga" "America/Panama" "America/Paramaribo" "America/Phoenix" "America/Port-au-Prince" "America/Port_of_Spain" "America/Porto_Velho" "America/Puerto_Rico" "America/Punta_Arenas" "America/Rankin_Inlet" "America/Recife" "America/Regina" "America/Resolute" "America/Rio_Branco" "America/Santarem" "America/Santiago" "America/Santo_Domingo" "America/Sao_Paulo" "America/Scoresbysund" "America/Sitka" "America/St_Barthelemy" "America/St_Johns" "America/St_Kitts" "America/St_Lucia" "America/St_Thomas" "America/St_Vincent" "America/Swift_Current" "America/Tegucigalpa" "America/Thule" "America/Tijuana" "America/Toronto" "America/Tortola" "America/Vancouver" "America/Whitehorse" "America/Winnipeg" "America/Yakutat") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneAntartica { local TZONES=("Antarctica/Casey" "Antarctica/Davis" "Antarctica/DumontDUrville" "Antarctica/Macquarie" "Antarctica/Mawson" "Antarctica/McMurdo" "Antarctica/Palmer" "Antarctica/Rothera" "Antarctica/Syowa" "Antarctica/Troll" "Antarctica/Vostok") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneArctic { local TZONES=("Arctic/Longyearbyen") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneAsia { local TZONES=("Asia/Aden" "Asia/Almaty" "Asia/Amman" "Asia/Anadyr" "Asia/Aqtau" "Asia/Aqtobe" "Asia/Ashgabat" "Asia/Atyrau" "Asia/Baghdad" "Asia/Bahrain" "Asia/Baku" "Asia/Bangkok" "Asia/Barnaul" "Asia/Beirut" "Asia/Bishkek" "Asia/Brunei" "Asia/Chita" "Asia/Colombo" "Asia/Damascus" "Asia/Dhaka" "Asia/Dili" "Asia/Dubai" "Asia/Dushanbe" "Asia/Famagusta" "Asia/Gaza" "Asia/Hebron" "Asia/Ho_Chi_Minh" "Asia/Hong_Kong" "Asia/Hovd" "Asia/Irkutsk" "Asia/Jakarta" "Asia/Jayapura" "Asia/Jerusalem" "Asia/Kabul" "Asia/Kamchatka" "Asia/Karachi" "Asia/Kathmandu" "Asia/Khandyga" "Asia/Kolkata" "Asia/Krasnoyarsk" "Asia/Kuala_Lumpur" "Asia/Kuching" "Asia/Kuwait" "Asia/Macau" "Asia/Magadan" "Asia/Makassar" "Asia/Manila" "Asia/Muscat" "Asia/Nicosia" "Asia/Novokuznetsk" "Asia/Novosibirsk" "Asia/Omsk" "Asia/Oral" "Asia/Phnom_Penh" "Asia/Pontianak" "Asia/Pyongyang" "Asia/Qatar" "Asia/Qostanay" "Asia/Qyzylorda" "Asia/Riyadh" "Asia/Sakhalin" "Asia/Samarkand" "Asia/Seoul" "Asia/Shanghai" "Asia/Singapore" "Asia/Srednekolymsk" "Asia/Taipei" "Asia/Tashkent" "Asia/Tbilisi" "Asia/Tehran" "Asia/Thimphu" "Asia/Tokyo" "Asia/Tomsk" "Asia/Ulaanbaatar" "Asia/Urumqi" "Asia/Ust-Nera" "Asia/Vientiane" "Asia/Vladivostok" "Asia/Yakutsk" "Asia/Yangon" "Asia/Yekaterinburg" "Asia/Yerevan") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneAtlantic { local TZONES=("Atlantic/Azores" "Atlantic/Bermuda" "Atlantic/Canary" "Atlantic/Cape_Verde" "Atlantic/Faroe" "Atlantic/Madeira" "Atlantic/Reykjavik" "Atlantic/South_Georgia" "Atlantic/St_Helena" "Atlantic/Stanley") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneAustralia { local TZONES=("Australia/Adelaide" "Australia/Brisbane" "Australia/Broken_Hill" "Australia/Darwin" "Australia/Eucla" "Australia/Hobart" "Australia/Lindeman" "Australia/Lord_Howe" "Australia/Melbourne" "Australia/Perth" "Australia/Sydney") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneEurope { local TZONES=("Europe/Amsterdam" "Europe/Andorra" "Europe/Astrakhan" "Europe/Athens" "Europe/Belgrade" "Europe/Berlin" "Europe/Bratislava" "Europe/Brussels" "Europe/Bucharest" "Europe/Budapest" "Europe/Busingen" "Europe/Chisinau" "Europe/Copenhagen" "Europe/Dublin" "Europe/Gibraltar" "Europe/Guernsey" "Europe/Helsinki" "Europe/Isle_of_Man" "Europe/Istanbul" "Europe/Jersey" "Europe/Kaliningrad" "Europe/Kirov" "Europe/Kyiv" "Europe/Lisbon" "Europe/Ljubljana" "Europe/London" "Europe/Luxembourg" "Europe/Madrid" "Europe/Malta" "Europe/Mariehamn" "Europe/Minsk" "Europe/Monaco" "Europe/Moscow" "Europe/Oslo" "Europe/Paris" "Europe/Podgorica" "Europe/Prague" "Europe/Riga" "Europe/Rome" "Europe/Samara" "Europe/San_Marino" "Europe/Sarajevo" "Europe/Saratov" "Europe/Simferopol" "Europe/Skopje" "Europe/Sofia" "Europe/Stockholm" "Europe/Tallinn" "Europe/Tirane" "Europe/Ulyanovsk" "Europe/Vaduz" "Europe/Vatican" "Europe/Vienna" "Europe/Vilnius" "Europe/Volgograd" "Europe/Warsaw" "Europe/Zagreb" "Europe/Zurich") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneIndian { local TZONES=("Indian/Antananarivo" "Indian/Chagos" "Indian/Christmas" "Indian/Cocos" "Indian/Comoro" "Indian/Kerguelen" "Indian/Mahe" "Indian/Maldives" "Indian/Mauritius" "Indian/Mayotte" "Indian/Reunion") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezonePacific { local TZONES=("Pacific/Apia" "Pacific/Auckland" "Pacific/Bougainville" "Pacific/Chatham" "Pacific/Chuuk" "Pacific/Easter" "Pacific/Efate" "Pacific/Fakaofo" "Pacific/Fiji" "Pacific/Funafuti" "Pacific/Galapagos" "Pacific/Gambier" "Pacific/Guadalcanal" "Pacific/Guam" "Pacific/Honolulu" "Pacific/Kanton" "Pacific/Kiritimati" "Pacific/Kosrae" "Pacific/Kwajalein" "Pacific/Majuro" "Pacific/Marquesas" "Pacific/Midway" "Pacific/Nauru" "Pacific/Niue" "Pacific/Norfolk" "Pacific/Noumea" "Pacific/Pago_Pago" "Pacific/Palau" "Pacific/Pitcairn" "Pacific/Pohnpei" "Pacific/Port_Moresby" "Pacific/Rarotonga" "Pacific/Saipan" "Pacific/Tahiti" "Pacific/Tarawa" "Pacific/Tongatapu" "Pacific/Wake" "Pacific/Wallis") local page=0 local options=${#TZONES[@]} local pages=$((options/10)) if [[ $((pages%10)) == 0 ]]; then ((pages--)) fi while true; do echo "Please select a Timezone:" if [[ $page == $pages ]] && [[ $((pages%10)) != 0 ]]; then for ((n=0; n<$((pages%10)); n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done else for ((n=0; n<10; n++)); do echo " ${n}. ${TZONES[$((n+(page*10)))]}" done fi if [[ $page -lt $pages ]]; then echo " N. Next Page" fi if [[ $page -gt 0 ]]; then echo " P. Previous Page" fi echo "Enter the digit beside your Timezone or enter the" echo "letters N or P for Next Page or Previous Page if" echo "available... Or press ENTER to return to the" echo "Regions menu." read input input="${input:0:1}" if [[ ${input} =~ ^[0-9]$ ]]; then if [[ -z "${TZONES[$((input+(page*10)))]}" ]]; then return 1 else PHPTIMEZONE="${TZONES[$((input+(page*10)))]}" return 0 fi elif [[ $page -lt $pages ]] && [[ ${input^^} == "N" ]]; then ((page++)) elif [[ $page -gt 0 ]] && [[ ${input^^} == "P" ]]; then ((page--)) else return 1 fi done } function doTimezoneRegions { result=1 while [[ $result == 1 ]]; do echo "Please select a Region:" echo " 0. AFRICA" echo " 1. AMERICAS" echo " 2. ANTARTICA" echo " 3. ARCTIC CIRCLE" echo " 4. ASIA" echo " 5. ATLANTIC OCEAN" echo " 6. AUSTRALIA" echo " 7. EUROPE" echo " 8. INDIAN OCEAN" echo " 9. PACIFIC OCEAN" echo "Enter the digit beside the Region for your Timezone..." echo "Or press ENTER to quit the install. You can restart" echo "later and the Installer will continue from this step." read input input="${input:0:1}" if [[ ${input} == "0" ]]; then doTimezoneAfrica result=$? elif [[ ${input} == "1" ]]; then doTimezoneAmerica result=$? elif [[ ${input} == "2" ]]; then doTimezoneAntartica result=$? elif [[ ${input} == "3" ]]; then doTimezoneArctic result=$? elif [[ ${input} == "4" ]]; then doTimezoneAsia result=$? elif [[ ${input} == "5" ]]; then doTimezoneAtlantic result=$? elif [[ ${input} == "6" ]]; then doTimezoneAustralia result=$? elif [[ ${input} == "7" ]]; then doTimezoneEurope result=$? elif [[ ${input} == "8" ]]; then doTimezoneIndian result=$? elif [[ ${input} == "9" ]]; then doTimezonePacific result=$? else exit fi done } function doTURN { echo "###############################" >> /etc/turnserver.conf echo "# Custom Config for Nextcloud #" >> /etc/turnserver.conf echo "###############################" >> /etc/turnserver.conf echo "listening-port=3478" >> /etc/turnserver.conf echo "tls-listening-port=5349" >> /etc/turnserver.conf echo "alt-listening-port=0" >> /etc/turnserver.conf echo "alt-tls-listening-port=0" >> /etc/turnserver.conf echo "min-port=60000" >> /etc/turnserver.conf echo "max-port=61999" >> /etc/turnserver.conf echo "fingerprint" >> /etc/turnserver.conf echo "use-auth-secret" >> /etc/turnserver.conf echo "static-auth-secret=$TURNPASS" >> /etc/turnserver.conf echo "realm=$FQDN" >> /etc/turnserver.conf echo "total-quota=0" >> /etc/turnserver.conf echo "bps-capacity=0" >> /etc/turnserver.conf echo "no-multicast-peers" >> /etc/turnserver.conf systemctl restart coturn.service > /dev/null 2>> installer-errors.log || failMsg "coTURN failed to restart with new settings..." } function doVHost { if [[ -f /etc/apache2/sites-available/${NCWWW}.conf ]]; then echo "VHost file already exists..." echo -n "Press ENTER to view it or type GO to replace it... " read input input=${input:0:2} if [[ ${input^^} != "GO" ]]; then echo "------" cat /etc/apache2/sites-available/${NCWWW}.conf echo "------" echo "Press ENTER to exit and edit the settings.conf file," echo -n "or type GO to replace the above file... " read input input=${input:0:2} if [[ ${input^^} != "GO" ]]; then echo "You can edit the settings.conf file and change the" echo "value for NCWWW then restart the install. It will" echo "continue from this step..." exit 0 fi fi rm -f /etc/apache2/sites-available/${NCWWW}.conf fi touch /etc/apache2/sites-available/${NCWWW}.conf echo "" >> /etc/apache2/sites-available/${NCWWW}.conf echo " ServerName $FQDN" >> /etc/apache2/sites-available/${NCWWW}.conf echo " ServerAdmin $EMAIL" >> /etc/apache2/sites-available/${NCWWW}.conf echo " DocumentRoot /var/www/${NCWWW}/" >> /etc/apache2/sites-available/${NCWWW}.conf echo " ErrorLog ${APACHE_LOG_DIR}/error.log" >> /etc/apache2/sites-available/${NCWWW}.conf echo " CustomLog ${APACHE_LOG_DIR}/access.log combined" >> /etc/apache2/sites-available/${NCWWW}.conf echo " " >> /etc/apache2/sites-available/${NCWWW}.conf echo " Require all granted" >> /etc/apache2/sites-available/${NCWWW}.conf echo " AllowOverride All" >> /etc/apache2/sites-available/${NCWWW}.conf echo " Options FollowSymLinks MultiViews" >> /etc/apache2/sites-available/${NCWWW}.conf echo " " >> /etc/apache2/sites-available/${NCWWW}.conf echo " Dav off" >> /etc/apache2/sites-available/${NCWWW}.conf echo " " >> /etc/apache2/sites-available/${NCWWW}.conf echo " " >> /etc/apache2/sites-available/${NCWWW}.conf echo "" >> /etc/apache2/sites-available/${NCWWW}.conf mkdir "/var/${NCFILES}" chown -R www-data:www-data "/var/${NCFILES}" mkdir "/var/www/${NCWWW}" chown -R www-data:www-data "/var/www/${NCWWW}" a2ensite ${NCWWW}.conf > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable VHost..." a2enmod rewrite > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable the rewrite module..." a2enmod headers > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable the headers module..." a2enmod env > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable the env module..." a2enmod dir > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable the dir module..." a2enmod mime > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable the mime module..." systemctl restart apache2 > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to restart..." } function downloadUpdate { if [[ -z "$SELF_UPDATED" ]]; then TMPFILE=$(mktemp) echo "Downloading updated script..." curl -sSL "https://git.zaks.web.za/thisiszeev/perfect-nextcloud-installer/raw/branch/main/debian-installer.sh" -o "$TMPFILE" || { echo "Download failed... Continuing with current version..." >&2 return } chmod +x "$TMPFILE" echo "Launching updated version..." exec env SELF_UPDATED=1 ORIGINALSCRIPT="$(readlink -f "$0")" ORIGINALVERSION="$VERSION" "$TMPFILE" "$@" fi SCRIPT="$ORIGINALSCRIPT" BACKUP="${SCRIPT%.sh}.${ORIGINALVERSION}.sh" echo "Creating backup of original script at $BACKUP" cp "$SCRIPT" "$BACKUP" || echo "Backup failed..." >&2 echo "Overwriting $SCRIPT with updated version..." cp "$0" "$ORIGINALSCRIPT" || echo "Overwrite failed..." >&2 echo "Script updated successfully. Continuing execution..." sleep 2s } function failMsg { echo "ERROR: $1" >&2 exit 1 } function genPass { if [[ -z $1 ]] || [[ $1 == "" ]]; then failMsg "Function passGen requires an integer between 12 and 64" fi local LAST3CHAR=(- - -) local LAST3SET=(9 9 9) local LCHARSET=(x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c) local NCHARSET=(7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2) local STRING="" local UCHARSET=(X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C) local i local n local newset local safe if [[ $1 -ge 8 ]] && [[ $1 -le 64 ]]; then for ((n=0; n<$1; n++)); do safe=false while [[ $safe == false ]]; do newset=$((RANDOM%3)) if [[ $newset != ${LAST3SET[0]} ]] || [[ $newset != ${LAST3SET[1]} ]] || [[ $newset != ${LAST3SET[2]} ]]; then LAST3SET[2]=${LAST3SET[1]} LAST3SET[1]=${LAST3SET[0]} LAST3SET[0]=$newset safe=true fi done safe=false while [[ $safe == false ]]; do if [[ $newset == 2 ]]; then i=$(((RANDOM%10)+3)) if [[ ${NCHARSET[$i]} != ${LAST3CHAR[0]} ]] && [[ ${NCHARSET[$i]} != ${LAST3CHAR[1]} ]] && [[ ${NCHARSET[$i]} != ${LAST3CHAR[2]} ]] && [[ ${NCHARSET[$((i-1))]} != ${LAST3CHAR[0]} ]] && [[ ${NCHARSET[$((i+1))]} != ${LAST3CHAR[0]} ]]; then LAST3CHAR[2]=${LAST3CHAR[1]} LAST3CHAR[1]=${LAST3CHAR[0]} LAST3CHAR[0]=${NCHARSET[$i]} STRING="${STRING}${NCHARSET[$i]}" safe=true fi else i=$(((RANDOM%26)+3)) if [[ ${UCHARSET[$i]} != ${LAST3CHAR[0]} ]] && [[ ${UCHARSET[$i]} != ${LAST3CHAR[1]} ]] && [[ ${UCHARSET[$i]} != ${LAST3CHAR[2]} ]] && [[ ${UCHARSET[$((i-1))]} != ${LAST3CHAR[0]} ]] && [[ ${UCHARSET[$((i+1))]} != ${LAST3CHAR[0]} ]] && [[ ${LCHARSET[$i]} != ${LAST3CHAR[0]} ]] && [[ ${LCHARSET[$i]} != ${LAST3CHAR[1]} ]] && [[ ${LCHARSET[$i]} != ${LAST3CHAR[2]} ]] && [[ ${LCHARSET[$((i-1))]} != ${LAST3CHAR[0]} ]] && [[ ${LCHARSET[$((i+1))]} != ${LAST3CHAR[0]} ]]; then LAST3CHAR[2]=${LAST3CHAR[1]} LAST3CHAR[1]=${LAST3CHAR[0]} if [[ $newset == 1 ]]; then LAST3CHAR[0]=${LCHARSET[$i]} STRING="${STRING}${LCHARSET[$i]}" else LAST3CHAR[0]=${UCHARSET[$i]} STRING="${STRING}${UCHARSET[$i]}" fi safe=true fi fi done done echo -n $STRING else failMsg "Function passGen requires an integer between 12 and 64" fi } declare DBHOST declare DBNAME declare DBPASS declare DBROOTPASS declare DBUSER declare EMAIL declare FQDN declare NCADMIN declare NCFILES declare NCPASS declare NCWWW declare PHPTIMEZONE declare TURNPASS eval $(grep '^PRETTY_NAME=' /etc/os-release) if [[ "$PRETTY_NAME" != "Debian GNU/Linux 12 (bookworm)" ]]; then echo "Your installed distro is $PRETTY_NAME" echo echo "This installer script has only been tested on Debian GNU/Linux 12 (bookworm)" echo "but it should work on any Debian based distro such as Ubuntu." echo echo "Any distro that is not Debian based may result in a complete failure of the" echo "installation process." echo echo "Press ENTER to continue or CTRL+C to exit..." read input echo fi echo "Welcome to the Perfect Nextcloud Installer Script version $INSTALLERVERSION" echo echo "This script is FREE software and is licensed under the GPL 3.0 or later license." echo "If you want to view the license, you can read it by visiting the associated Git" echo "repo at https://git.zaks.web.za/thisiszeev/perfect-nextcloud-installer" echo echo "If this script fails at any point, feel free to send me a chat request on" echo "Reddit u/thisiszeev, and I will try my best to assist you. The script is" echo "designed that if we can resolve the reason for the failure, you can rerun" echo "the script and it will pickup from where it left off." echo if [[ ! -f settings.conf ]]; then CPUCOUNT=$(cat /proc/cpuinfo | grep "^processor" | wc -l) temp=($(cat /proc/meminfo | grep "^MemTotal")) temp=${temp[1]} SYSTEMRAM=$((temp/1000000)) echo "Detected CPUs : $CPUCOUNT (Recommended 4 or more)" echo " Detected RAM : $SYSTEMRAM GB (Recommended 8 GB or more)" echo if [[ $CPUCOUNT -lt 4 ]] || [[ $SYSTEMRAM -lt 8 ]]; then echo "You do not meet the minimum recommended values for CPUs and RAM." echo "You can still install Nextcloud but performance will be poor." echo fi echo "What is the fully qualified domain name for this installation?" echo -n "(excluding http:// or https://) " read FQDN echo "What is the email address you want to use for SSL Certificate notifications" echo -n "and the admin user account? " read EMAIL doTimezoneRegions echo "Do you want to install AutoSWAP? This is a background systemd service," echo "that automatically adds SWAP memory when your server is under load, and" echo "then automatically removes unneeded SWAP memory when your server is idle." echo "Can be useful if your server has some extra busy times with a lot of http" echo "hits. Visit:" echo "https://git.zaks.web.za/thisiszeev/linux-server-tools/src/branch/main/swap-management" echo -n "for more info. Press ENTER for Yes or type NO for No. " read input input=${input:0:1} if [[ ${input^^} == "N" ]]; then AUTOSWAP="false" else AUTOSWAP="true" fi echo "Writing settings.conf file..." touch settings.conf echo "DBHOST=\"localhost\"" >> settings.conf echo "DBNAME=\"nextcloud\"" >> settings.conf echo "DBPASS=\"$(genPass 24)\"" >> settings.conf echo "DBROOTPASS=\"$(genPass 32)\"" >> settings.conf echo "DBUSER=\"nextcloud\"" >> settings.conf echo "EMAIL=\"$EMAIL\"" >> settings.conf echo "FQDN=\"$FQDN\"" >> settings.conf echo "NCADMIN=\"ncadmin\"" >> settings.conf echo "NCFILES=\"nextcloudfiles\"" >> settings.conf echo "NCPASS=\"$(genPass 24)\"" >> settings.conf echo "NCWWW=\"nextcloud\"" >> settings.conf echo "TURNPASS=\"$(genPass 64)\"" >> settings.conf echo "PHPTIMEZONE=\"$PHPTIMEZONE\"" >> settings.conf echo "AUTOSWAP=\"$AUTOSWAP\"" >> settings.conf else echo "File settings.conf already exists..." echo fi source settings.conf echo "Going to install with the following settings..." echo " Domain Name : https://$FQDN" echo " Database Name : $DBNAME" echo " Database User : $DBUSER" echo " Database Pass : $DBPASS" echo " Database Host : $DBHOST" echo " MySQL Root Pass : $DBROOTPASS" echo " Admin Username : $NCADMIN" echo " Admin Password : $NCPASS" echo " Admin Email : $EMAIL" echo " Webroot Directory : /var/www/$NCWWW" echo "NC Files Directory : /var/$NCFILES" echo "TURN Server Secret : $TURNPASS" echo " PHP Timezone : $PHPTIMEZONE" echo " Install AutoSWAP : $AUTOSWAP" echo echo "If you want to customize any of the above settings, then" echo "press CTRL+C to exit, then edit the file settings.conf" echo "and restart this installer script. Alternatively, press" echo "ENTER to continue..." read input echo "Updating system..." apt update > /dev/null 2>> installer-errors.log && apt -y upgrade > /dev/null 2>> installer-errors.log || failMsg "apt failed to update the system..." if [[ ! -f position.temp ]]; then echo "1" > position.temp else echo echo "This script did not complete the installation in a prior attempt." echo "We will pickup from where it left off..." echo fi p=$(head -1 position.temp) if [[ $p -lt 2 ]]; then echo "Installing tools needed to complete the installation..." apt -y install wget curl rsync screen wget sudo unzip > /dev/null 2>> installer-errors.log || failMsg "apt failed to install dependancies..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 3 ]]; then if [[ $SELF_UPDATED != 1 ]]; then echo "Checking if there is a newer version of this installer script..." NEWVERSION=$(curl -sSL "https://git.zaks.web.za/thisiszeev/perfect-nextcloud-installer/raw/branch/main/VERSION") if [[ ! "$NEWVERSION" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then echo "Remote version could not be retrieved." >&2 NEWVERSION="$INSTALLERVERSION" fi else NEWVERSION="$INSTALLERVERSION" fi if compareVersions "$INSTALLERVERSION" "$NEWVERSION" || [[ $SELF_UPDATED == 1 ]]; then downloadUpdate fi fi if [[ $p -lt 4 ]]; then echo "Installing Apache2 and Certbot for Let's Encrypt..." apt -y install apache2 certbot python3-certbot-apache > /dev/null 2>> installer-errors.log || failMsg "apt failed to install Apache2 and Certbot..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 5 ]]; then echo "Configuring Apache2 VHost file..." doVHost || failMsg "Apache2 failed to configure..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 6 ]]; then echo "Requesting SSL Certicate from Let's Encrypt..." certbot -n -m $EMAIL --agree-tos --apache -d $FQDN > /dev/null 2>> installer-errors.log || failMsg "Certbot failed to get an SSL Certicate from Let's Encrypt..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 7 ]]; then if [[ "$DBHOST" == "localhost" ]]; then echo "Installing MariaDB (MySQL)..." apt -y install mariadb-server mariadb-client > /dev/null 2>> installer-errors.log || failMsg "apt failed to install MariaDB..." else echo "You have defined an external (remote) server for MariaDB/MySQL." echo "Please ensure that the MariaDB/MySQL remote server at $DBHOST" echo "is configured with the following settings:" echo " Remote Server Host : $DBHOST" echo " Database Name : $DBNAME" echo " Database Username : $DBUSER" echo " Database Password : $DBPASS" echo "Type GO to continue or press ENTER to stop this installation." echo "You can restart it later and it will continue from this step." read input input=${input:0:2} if [[ ${input^^} != "GO" ]]; then exit 0 fi fi ((p++)) echo "$p" > position.temp fi if [[ $p -lt 8 ]]; then if [[ "$DBHOST" == "localhost" ]]; then echo "Securing MariaDB (MySQL)..." doMariaDB || failMsg "Securing MariaDB failed..." else echo "Skipping securing of local MySQL..." fi ((p++)) echo "$p" > position.temp fi if [[ $p -lt 9 ]]; then if [[ "$DBHOST" == "localhost" ]]; then echo "Creating MySQL database for Nextcloud..." echo "CREATE DATABASE $DBNAME; CREATE USER $DBUSER@localhost IDENTIFIED BY '$DBPASS'; GRANT ALL PRIVILEGES ON $DBNAME.* TO $DBUSER@localhost; FLUSH PRIVILEGES;" | mysql > /dev/null 2>> installer-errors.log || failMsg "MariaDB failed to setup database for Nextcloud..." else echo "Skipping creation of local MySQL database..." fi ((p++)) echo "$p" > position.temp fi if [[ $p -lt 10 ]]; then echo "Adding Sury PHP Repo to Debian..." curl -sSL https://packages.sury.org/php/README.txt | bash -x > /dev/null 2>> installer-errors.log || failMsg "Sury PHP Repo failed to add to Debian..." apt update > /dev/null 2>> installer-errors.log || failMsg "apt failed to download Sury repo data..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 11 ]]; then echo "Installing PHP8.3-FPM and CLI with all recommended extensions..." apt -y install php8.3-{ctype,curl,dom,gd,common,mysql,mbstring,opcache,posix,simplexml,xmlreader,xmlwriter,xmlrpc,xml,cli,zip,bz2,fpm,intl,ldap,smbclient,ftp,imap,bcmath,gmp,exif,apcu,memcached,redis,imagick} libapache2-mod-php8.3 libapache2-mod-fcgid libxml2 > /dev/null 2>> installer-errors.log || failMsg "apt failed to install PHP..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 12 ]]; then echo "Creating custom PHP config specific for Nextcloud..." doPHP || failMsg "Custom PHP config failed..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 13 ]]; then echo "Installing coTURN server for Nextcloud Talk..." apt -y install coturn > /dev/null 2>> installer-errors.log || failMsg "apt failed to Install coTURN..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 14 ]]; then echo "Configuring coTURN server for Nextcloud Talk..." doTURN || failMsg "apt failed to Install coTURN..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 15 ]]; then if [[ $AUTOSWAP = "true" ]]; then echo "Installing SWAP memory management tool..." doSWAP || failMsg "SWAP memory management tool failed to install..." else echo "Not installing SWAP memory management tool..." fi ((p++)) echo "$p" > position.temp fi if [[ $p -lt 16 ]]; then echo "Downloading and unpacking latest version of Nextcloud..." wget "https://download.nextcloud.com/server/releases/latest.zip" || failMsg "Nextcloud failed to download..." mkdir nextcloud unzip latest.zip -d ./nextcloud > /dev/null 2>> installer-errors.log || failMsg "Nextcloud failed to unpack..." mv ./nextcloud/nextcloud/* "/var/www/$NCWWW/" mv ./nextcloud/nextcloud/.* "/var/www/$NCWWW/" chown -R www-data:www-data "/var/www/$NCWWW" rm -R ./nextcloud rm -R latest.zip ((p++)) echo "$p" > position.temp fi if [[ $p -lt 17 ]]; then echo "Installing Nextcloud... this could take a while..." oldpath=$(pwd) cd "/var/www/$NCWWW" sudo -u www-data php occ maintenance:install --database="mysql" --database-host="$DBHOST" --database-name="$DBNAME" --database-user="$DBUSER" --database-pass="$DBPASS" --admin-user="$NCADMIN" --admin-pass="$NCPASS" --data-dir="/var/$NCFILES" > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to install..." sudo -u www-data php occ user:enable $NCADMIN > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to enable user $NCADMIN..." sudo -u www-data php occ user:setting $NCADMIN settings email $EMAIL > /dev/null 2>> "$oldpath/installer-errors.log" || "Nextcloud failed to set email address $EMAIL for user $NCADMIN..." cd config sed -i -e "s/0 => 'localhost'/0 => '$FQDN'/" -e "s|'overwrite\.cli\.url' => 'http://localhost'|'overwrite.cli.url' => 'https://$FQDN'|" config.php > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to set domain $FQDN in config.php..." cd "$oldpath" ((p++)) echo "$p" > position.temp fi if [[ $p -lt 18 ]]; then echo "Removing any redundant packages..." apt -y autoremove > /dev/null 2>> installer-errors.log || failMsg "APT failed to remove redundant packages..." ((p++)) echo "$p" > position.temp fi if [[ $p -lt 19 ]]; then echo "Writing the Installation Report and cleaning up..." doREPORT rm -f position.temp rm -f settings.conf rm -f installer-errors.log fi