v1.4 Fully Tested on Debian
This commit is contained in:
parent
79956feb74
commit
13dd5bf866
Binary file not shown.
After Width: | Height: | Size: 194 KiB |
|
@ -1,12 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
INSTALLERVERSION="1.03"
|
||||
INSTALLERVERSION="1.04"
|
||||
|
||||
if [[ $(whoami) != "root" ]]; then
|
||||
echo "You must be root to run this script!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
oldpath=$(pwd)
|
||||
|
||||
function compareVersions {
|
||||
if [[ -z "$1" || -z "$2" ]]; then
|
||||
echo "Failed to compare versions..." >&2
|
||||
|
@ -29,19 +31,23 @@ function compareVersions {
|
|||
return 1
|
||||
}
|
||||
|
||||
function decho {
|
||||
echo "$@"
|
||||
echo "$@" >> "$oldpath/installer-errors.log"
|
||||
}
|
||||
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
|
||||
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>> "$oldpath/installer-errors.log" || return 1
|
||||
echo "FLUSH PRIVILEGES;" | mysql > /dev/null 2>> "$oldpath/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>> "$oldpath/installer-errors.log" || return 1
|
||||
echo "DELETE FROM mysql.global_priv WHERE User='';" | mysql > /dev/null 2>> "$oldpath/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>> "$oldpath/installer-errors.log" || return 1
|
||||
echo "DROP DATABASE IF EXISTS test;" | mysql > /dev/null 2>> "$oldpath/installer-errors.log" || return 1
|
||||
echo "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" | mysql > /dev/null 2>> "$oldpath/installer-errors.log" || return 1
|
||||
echo "FLUSH PRIVILEGES;" | mysql > /dev/null 2>> "$oldpath/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..."
|
||||
systemctl stop apache2 > /dev/null 2>> "$oldpath/installer-errors.log" && a2dismod php8.3 > /dev/null 2>> "$oldpath/installer-errors.log" && a2dismod mpm_prefork > /dev/null 2>> "$oldpath/installer-errors.log" && a2enmod mpm_event proxy proxy_fcgi setenvif rewrite > /dev/null 2>> "$oldpath/installer-errors.log" && a2enconf php8.3-fpm > /dev/null 2>> "$oldpath/installer-errors.log" && systemctl restart apache2 > /dev/null 2>> "$oldpath/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
|
||||
|
@ -82,7 +88,7 @@ function doPHP {
|
|||
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..."
|
||||
systemctl restart php8.3-fpm.service > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "PHP FPM failed to load custom settings..."
|
||||
}
|
||||
|
||||
function doREPORT {
|
||||
|
@ -210,7 +216,7 @@ function doREPORT {
|
|||
}
|
||||
|
||||
function doSWAP {
|
||||
wget "https://git.zaks.web.za/thisiszeev/linux-server-tools/releases/download/autoswap-v1.01.01/autoswap-v1.01.01.zip" > /dev/null 2>> installer-errors.log || failMsg "Failed to download Auto SWAP..."
|
||||
wget "https://git.zaks.web.za/thisiszeev/linux-server-tools/releases/download/autoswap-v1.01.01/autoswap-v1.01.01.zip" > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to download Auto SWAP..."
|
||||
mkdir autoswap
|
||||
unzip autoswap-v1.01.01.zip -d ./autoswap
|
||||
mkdir /etc/autoswap
|
||||
|
@ -226,8 +232,8 @@ function doSWAP {
|
|||
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..."
|
||||
systemctl start autoswap.service > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Auto SWAP service failed to start..."
|
||||
systemctl enable autoswap.service > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Auto SWAP service could not be enabled..."
|
||||
}
|
||||
|
||||
function doTimezoneAfrica {
|
||||
|
@ -812,7 +818,7 @@ function doTURN {
|
|||
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..."
|
||||
systemctl restart coturn.service > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "coTURN failed to restart with new settings..."
|
||||
}
|
||||
|
||||
function doVHost {
|
||||
|
@ -858,13 +864,20 @@ function doVHost {
|
|||
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..."
|
||||
a2ensite ${NCWWW}.conf > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable VHost..."
|
||||
a2enmod rewrite > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable the rewrite module..."
|
||||
a2enmod headers > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable the headers module..."
|
||||
a2enmod env > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable the env module..."
|
||||
a2enmod dir > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable the dir module..."
|
||||
a2enmod mime > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable the mime module..."
|
||||
systemctl restart apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to restart..."
|
||||
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.original || failMsg "Failed to backup apache2.conf..."
|
||||
linenum=$(cat /etc/apache2/apache2.conf | grep -n '<Directory /var/www/>' | cut -d: -f1)
|
||||
until sed -n "${linenum}p" /etc/apache2/apache2.conf | grep "AllowOverride"> /dev/null; do
|
||||
((linenum++))
|
||||
done
|
||||
sed -i "${linenum}s/\bNone\b/All/" /etc/apache2/apache2.conf
|
||||
systemctl restart apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to restart Apache2..."
|
||||
}
|
||||
|
||||
function downloadUpdate {
|
||||
|
@ -891,7 +904,8 @@ function downloadUpdate {
|
|||
|
||||
function failMsg {
|
||||
echo "ERROR: $1" >&2
|
||||
echo "ERROR: $1" 2>> installer-errors.log
|
||||
echo "ERROR: $1 [showTimer $SECONDS]" >> "$oldpath/installer-errors.log"
|
||||
echo $((SECONDS+runtime)) > $oldpath/runtime.temp
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -955,6 +969,10 @@ function genPass {
|
|||
fi
|
||||
}
|
||||
|
||||
function showTimer {
|
||||
printf "%02d:%02d:%02d\n" $((${1}/3600)) $((${1}%3600/60)) $((${1}%60))
|
||||
}
|
||||
|
||||
declare DBHOST
|
||||
declare DBNAME
|
||||
declare DBPASS
|
||||
|
@ -996,6 +1014,8 @@ 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
|
||||
echo "WARNING: THIS IS AN UNTESTED VERSION OF THE NEW SCRIPT! USE AT YOUR OWN PERIL!"
|
||||
echo
|
||||
|
||||
if [[ ! -f settings.conf ]]; then
|
||||
CPUCOUNT=$(cat /proc/cpuinfo | grep "^processor" | wc -l)
|
||||
|
@ -1076,8 +1096,11 @@ 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 runtime.temp ]]; then
|
||||
runtime=$(head -1 runtime.temp)
|
||||
else
|
||||
runtime=0
|
||||
fi
|
||||
|
||||
if [[ ! -f position.temp ]]; then
|
||||
echo "1" > position.temp
|
||||
|
@ -1086,26 +1109,36 @@ else
|
|||
echo "This script did not complete the installation in a prior attempt."
|
||||
echo "We will pickup from where it left off..."
|
||||
echo
|
||||
echo "Previous runs account for $(showTimer $runtime) of runtime..."
|
||||
echo
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Starting the timer!"
|
||||
SECONDS=0
|
||||
echo
|
||||
decho "[Step 1] Updating system... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt update > /dev/null 2>> "$oldpath/installer-errors.log" && apt -y upgrade > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to update the system..."
|
||||
|
||||
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 jq > /dev/null 2>> installer-errors.log || failMsg "apt failed to install dependancies..."
|
||||
decho "[Step $((p+1))] Installing tools needed to complete the installation... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y install wget curl rsync screen wget sudo unzip jq > /dev/null 2>> "$oldpath/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..."
|
||||
decho "[Step $((p+1))] Checking if there is a newer version of this installer script... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
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
|
||||
decho "[Step $((p+1))] Already downloaded the latest version of this installer script... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
NEWVERSION="$INSTALLERVERSION"
|
||||
fi
|
||||
if compareVersions "$INSTALLERVERSION" "$NEWVERSION" || [[ $SELF_UPDATED == 1 ]]; then
|
||||
|
@ -1116,16 +1149,16 @@ if [[ $p -lt 3 ]]; then
|
|||
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..."
|
||||
decho "[Step $((p+1))] Installing Apache2 and Certbot for Let's Encrypt... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y install apache2 certbot python3-certbot-apache > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to install Apache2 and Certbot..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 5 ]]; then
|
||||
echo "Testing that Apache2 is accessible from the web..."
|
||||
a2enmod ssl > /dev/null 2>> installer-errors.log && systemctl restart apache2 > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to enable module ssl..."
|
||||
a2ensite default-ssl.conf > /dev/null 2>> installer-errors.log && systemctl reload apache2 > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to activate default SSL configuration..."
|
||||
decho "[Step $((p+1))] Testing that Apache2 is accessible from the web... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
a2enmod ssl > /dev/null 2>> "$oldpath/installer-errors.log" && systemctl restart apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to enable module ssl..."
|
||||
a2ensite default-ssl.conf > /dev/null 2>> "$oldpath/installer-errors.log" && systemctl reload apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to activate default SSL configuration..."
|
||||
json=$(curl -s "http://api.zaks.web.za/testhttp")
|
||||
httpresult=$(echo "$json" | jq -r .http.result)
|
||||
httpsresult=$(echo "$json" | jq -r .https.result)
|
||||
|
@ -1134,20 +1167,20 @@ if [[ $p -lt 5 ]]; then
|
|||
fi
|
||||
echo "HTTP $httpresult"
|
||||
echo "HTTPS $httpsresult"
|
||||
a2dissite default-ssl.conf > /dev/null 2>> installer-errors.log && systemctl reload apache2 > /dev/null 2>> installer-errors.log || failMsg "Apache2 failed to deactivate default SSL configuration..."
|
||||
a2dissite default-ssl.conf > /dev/null 2>> "$oldpath/installer-errors.log" && systemctl reload apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to deactivate default SSL configuration... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 6 ]]; then
|
||||
echo "Configuring Apache2 VHost file..."
|
||||
decho "[Step $((p+1))] Configuring Apache2 and VHost file... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
doVHost || failMsg "Apache2 failed to configure..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 7 ]]; then
|
||||
echo "Testing your domain $FQDN resolves to your server..."
|
||||
decho "[Step $((p+1))] Testing your domain $FQDN resolves to your server... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
json=$(curl -s "http://api.zaks.web.za/testhttp?address=$FQDN&https=false")
|
||||
if [[ "$(echo "$json" | jq -r .status)" == "400" ]]; then
|
||||
failMsg "$(echo "$json" | jq -r .data)"
|
||||
|
@ -1163,17 +1196,21 @@ if [[ $p -lt 7 ]]; then
|
|||
fi
|
||||
|
||||
if [[ $p -lt 8 ]]; 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..."
|
||||
decho "[Step $((p+1))] Requesting SSL Certicate from Let's Encrypt... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
certbot -n -m $EMAIL --agree-tos --apache -d $FQDN > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Certbot failed to get an SSL Certicate from Let's Encrypt..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 9 ]]; 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..."
|
||||
decho "[Step $((p+1))] Installing MariaDB (MySQL)... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y install mariadb-server mariadb-client > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to install MariaDB..."
|
||||
else
|
||||
decho "[Step $((p+1))] Skipping of installing MariaDB (MySQL)... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
pausetimer=$SECONDS
|
||||
echo "Pausing the timer at $(showTimer $pausetimer)..."
|
||||
echo
|
||||
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:"
|
||||
|
@ -1186,8 +1223,13 @@ if [[ $p -lt 9 ]]; then
|
|||
read input
|
||||
input=${input:0:2}
|
||||
if [[ ${input^^} != "GO" ]]; then
|
||||
echo $((runtime+pausetimer)) > runtime.temp
|
||||
exit 0
|
||||
fi
|
||||
echo
|
||||
echo "Unpausing the timer..."
|
||||
SECONDS=$pausetimer
|
||||
echo
|
||||
fi
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
|
@ -1195,10 +1237,10 @@ fi
|
|||
|
||||
if [[ $p -lt 10 ]]; then
|
||||
if [[ "$DBHOST" == "localhost" ]]; then
|
||||
echo "Securing MariaDB (MySQL)..."
|
||||
decho "[Step $((p+1))] Securing MariaDB (MySQL)... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
doMariaDB || failMsg "Securing MariaDB failed..."
|
||||
else
|
||||
echo "Skipping securing of local MySQL..."
|
||||
decho "[Step $((p+1))] Skipping securing of local MySQL... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
fi
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
|
@ -1206,67 +1248,88 @@ fi
|
|||
|
||||
if [[ $p -lt 11 ]]; 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..."
|
||||
decho "[Step $((p+1))] Creating MySQL database for Nextcloud... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
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>> "$oldpath/installer-errors.log" || failMsg "MariaDB failed to setup database for Nextcloud..."
|
||||
else
|
||||
echo "Skipping creation of local MySQL database..."
|
||||
decho "[Step $((p+1))] Skipping creation of local MySQL database... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
fi
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 12 ]]; 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..."
|
||||
decho "[Step $((p+1))] Adding Sury PHP Repo to Debian... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
curl -sSL https://packages.sury.org/php/README.txt | bash -x > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Sury PHP Repo failed to add to Debian..."
|
||||
apt update > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to download Sury repo data..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 13 ]]; 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..."
|
||||
decho "[Step $((p+1))] Installing PHP8.3-FPM and CLI with all recommended extensions... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
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>> "$oldpath/installer-errors.log" || failMsg "apt failed to install PHP..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 14 ]]; then
|
||||
echo "Creating custom PHP config specific for Nextcloud..."
|
||||
decho "[Step $((p+1))] Creating custom PHP config specific for Nextcloud... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
doPHP || failMsg "Custom PHP config failed..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 15 ]]; then
|
||||
echo "Installing coTURN server for Nextcloud Talk..."
|
||||
apt -y install coturn > /dev/null 2>> installer-errors.log || failMsg "apt failed to Install coTURN..."
|
||||
decho "[Step $((p+1))] Installing coTURN server for Nextcloud Talk... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y install coturn > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to Install coTURN..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 16 ]]; then
|
||||
echo "Configuring coTURN server for Nextcloud Talk..."
|
||||
doTURN || failMsg "apt failed to Install coTURN..."
|
||||
decho "[Step $((p+1))] Configuring coTURN server for Nextcloud Talk... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
doTURN || failMsg "Failed to configure coTURN..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 17 ]]; 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
|
||||
decho "[Step $((p+1))] Installing Redis and Memcache Server... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y install redis-server memcached > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to Install Redis and Memcache Server..."
|
||||
systemctl start redis-server > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to start Redis Server..."
|
||||
systemctl enable redis-server > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to enable Redis Server..."
|
||||
systemctl start memcached > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to start Memcache Server..."
|
||||
systemctl enable memcached > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to enable Memcache Server..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 18 ]]; then
|
||||
echo "Downloading and unpacking latest version of Nextcloud..."
|
||||
decho "[Step $((p+1))] Installing SVG support for ImageMagick... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y install librsvg2-bin > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to install librsvg2-bin..."
|
||||
sed -i 's|</policymap>| <policy domain="coder" rights="none" pattern="SVG" />\n</policymap>|' /etc/ImageMagick-6/policy.xml
|
||||
apt -y install libmagickcore-6.q16-6-extra > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to install libmagickcore extras..."
|
||||
systemctl restart apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Apache2 failed to restart..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 19 ]]; then
|
||||
if [[ $AUTOSWAP = "true" ]]; then
|
||||
decho "[Step $((p+1))] Installing SWAP memory management tool... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
doSWAP || failMsg "SWAP memory management tool failed to install..."
|
||||
else
|
||||
decho "[Step $((p+1))] Not installing SWAP memory management tool... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
fi
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 20 ]]; then
|
||||
decho "[Step $((p+1))] Downloading and unpacking latest version of Nextcloud... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
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..."
|
||||
unzip latest.zip -d ./nextcloud > /dev/null 2>> "$oldpath/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"
|
||||
|
@ -1276,31 +1339,108 @@ if [[ $p -lt 18 ]]; then
|
|||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 19 ]]; then
|
||||
echo "Installing Nextcloud... this could take a while..."
|
||||
if [[ $p -lt 21 ]]; then
|
||||
decho "[Step $((p+1))] Installing Nextcloud... this could take a while... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
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..."
|
||||
if [[ ! -f config.original ]]; then
|
||||
cp config.php config.original
|
||||
fi
|
||||
cd ..
|
||||
|
||||
#line=$(grep -n -m1 "0 => 'localhost'," config.original | cut -d: -f1)
|
||||
#headlines=$((line-1))
|
||||
#length=$(cat config.original | wc -l)
|
||||
#taillines=$((length-line))
|
||||
#head -n $headlines config.orginal > config.php 2>> "$oldpath/installer-errors.log" && echo " 0 => '$FQDN'," >> config.php 2>> "$oldpath/installer-errors.log" && echo " 1 => 'localhost'," >> config.php 2>> "$oldpath/installer-errors.log" && tail -n $taillines config.original >> config.php 2>> "$oldpath/installer-errors.log" || failMsg "Failed to set trusted domains in config.php..."
|
||||
|
||||
sudo -u www-data php occ config:system:set trusted_domains 0 --value=$FQDN > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set $FQDN trusted domain..."
|
||||
sudo -u www-data php occ config:system:set trusted_domains 1 --value=localhost > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set localhost as trusted domain..."
|
||||
sudo -u www-data php occ config:system:set overwrite.cli.url --type=string --value=https://$FQDN > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set overwrite.cli.url..."
|
||||
|
||||
#sed -i "s|'overwrite\.cli\.url' => 'http://localhost'|'overwrite.cli.url' => 'https://$FQDN'|" config.php > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to set overwrite.cli.url in config.php..."
|
||||
#cd ..
|
||||
|
||||
sudo -u www-data php occ config:system:set maintenance_window_start --type=integer --value=1 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set maintenance window..."
|
||||
( crontab -u www-data -l 2>/dev/null; echo '*/5 * * * * php -f /var/www/nextcloud/cron.php' ) | crontab -u www-data - || failMsg "Failed to setup crontab..."
|
||||
sudo -u www-data php occ background:cron > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to activate cron for background jobs..."
|
||||
sudo -u www-data php occ config:system:set debug --type=boolean --value=false > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set debug to false..."
|
||||
sed -i '3a<IfModule mod_headers.c>\nHeader always set Strict-Transport-Security "max-age=15552000; includeSubDomains"\n</IfModule>' /etc/apache2/sites-available/${NCWWW}-le-ssl.conf > /dev/null 2>> "$oldpath/installer-errors.log" && systemctl reload apache2 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Failed to set Strict-Transport-Security in /etc/apache2/sites-available/${NCWWW}-le-ssl.conf..."
|
||||
sudo -u www-data php occ config:system:set memcache.local --type=string --value="\OC\Memcache\APCu" > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set local memcache..."
|
||||
sudo -u www-data php occ config:system:set memcache.distributed --type=string --value="\OC\Memcache\Redis" > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set distributed memcache..."
|
||||
sudo -u www-data php occ config:system:set memcache.locking --type=string --value="\OC\Memcache\Redis" > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set locking memcache..."
|
||||
sudo -u www-data php occ config:system:set redis host --type=string --value=localhost > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set Redis host..."
|
||||
sudo -u www-data php occ config:system:set redis port --type=integer --value=6379 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set Redis port..."
|
||||
sudo -u www-data php occ config:system:set redis timeout --type=float --value=0.0 > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed to set Redis Timeout..."
|
||||
echo "Running a full install check and repair..."
|
||||
sudo -u www-data php occ maintenance:repair --include-expensive > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "Nextcloud failed configuration of Mimetypes..."
|
||||
|
||||
##### STILL TO BE ADDED #####
|
||||
#sudo -u www-data php occ config:system:set default_phone_region --type=string --value=CC
|
||||
#sudo -u www-data php occ config:system:set default_language --type=string --value=lc_CC
|
||||
#sudo -u www-data php occ config:system:set default_locale --type=string --value=lc_CC
|
||||
#############################
|
||||
### https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
|
||||
#############################
|
||||
|
||||
echo -e '#!/bin/bash\n\ncd /var/www/nextcloud\nsudo -u www-data php occ $@' > /usr/bin/occ && chmod +x /usr/bin/occ || failMsg "Failed to create /usr/bin/occ..."
|
||||
|
||||
cd "$oldpath"
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 20 ]]; then
|
||||
echo "Removing any redundant packages..."
|
||||
apt -y autoremove > /dev/null 2>> installer-errors.log || failMsg "APT failed to remove redundant packages..."
|
||||
if [[ $p -lt 22 ]]; then
|
||||
decho "[Step $((p+1))] Removing any redundant packages... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
apt -y autoremove > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "APT failed to remove redundant packages..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 21 ]]; then
|
||||
echo "Writing the Installation Report and cleaning up..."
|
||||
if [[ $p -lt 23 ]]; then
|
||||
decho "[Step $((p+1))] Restarting all affected services just for good measure... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
echo -n "Memcached..." && systemctl restart memcached.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "Memcached failed to restart..."
|
||||
echo -n "Redis Server..." && systemctl restart redis-server.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "Redis Server failed to restart..."
|
||||
echo -n "CoTURN..." && systemctl restart coturn.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "CoTurn failed to restart..."
|
||||
echo -n "MariaDB..." && systemctl restart mariadb.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "MariaDB failed to restart..."
|
||||
echo -n "PHP-FPM..." && systemctl restart php8.3-fpm.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "PHP-FPM failed to restart..."
|
||||
echo -n "Apache2..." && systemctl restart apache2.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "Apache2 failed to restart..."
|
||||
((p++))
|
||||
echo "$p" > position.temp
|
||||
fi
|
||||
|
||||
if [[ $p -lt 24 ]]; then
|
||||
decho "[Step $((p+1))] Writing the Installation Report and cleaning up... [Current Runtime: $(showTimer $SECONDS)]"
|
||||
doREPORT
|
||||
cp NEXTCLOUD-REPORT*.md /var/${NCFILES}/${NCADMIN}/files/
|
||||
occ files:scan --all
|
||||
mkdir /etc/nextcloud-installer
|
||||
echo "# THIS FILE WAS CREATED BY THE PERFECT-NEXTCLOUD-INSTALLER SCRIPT BY THISISZEEV" > /etc/nextcloud-installer/settings.conf
|
||||
echo "# DO NOT EDIT OR DELETE THIS FILE AS IT IS NEED FOR WHEN YOU WANT TO USE A" >> /etc/nextcloud-installer/settings.conf
|
||||
echo "# FUTURE VERSION OF THE SCRIPT TO UPDATE THE SYSTEM TO MEET THE DEMANDS OF A" >> /etc/nextcloud-installer/settings.conf
|
||||
echo "# FUTURE VERSION OF NEXTCLOUD..." >> /etc/nextcloud-installer/settings.conf
|
||||
echo "LASTINSTALLERVERSION=$INSTALLERVERSION" >> /etc/nextcloud-installer/settings.conf
|
||||
cat settings.conf >> /etc/nextcloud-installer/settings.conf
|
||||
rm -f position.temp
|
||||
rm -f settings.conf
|
||||
rm -f installer-errors.log
|
||||
rm -f runtime.temp
|
||||
mv "$oldpath/installer-errors.log" /etc/nextcloud-installer/installer-errors.$INSTALLERVERSION.log
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
echo "CONGRATULATIONS!!!"
|
||||
echo
|
||||
echo "Total Runtime was $(showTimer $((runtime+SECONDS)))"
|
||||
echo
|
||||
echo "You can now point your browser to https://$FQDN and start using Nextcloud..."
|
||||
echo
|
||||
echo "Username: $NCADMIN"
|
||||
echo "Password: $NCPASS"
|
||||
echo
|
||||
echo "A copy of the report has been copied to $NCADMIN's Files app for safe keeping."
|
||||
echo
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue