From 034d6c7e606cf82126b38dc3d8b59018f2d625d0 Mon Sep 17 00:00:00 2001 From: Ze'ev Schurmann Date: Tue, 13 May 2025 22:08:43 +0200 Subject: [PATCH] v1.05 Support for Ubuntu Server added. Only tested on 24.04 LTS... --- VERSION | 2 +- debian-installer.sh | 61 ++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index 11a84ad..993f095 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.04 +1.05 diff --git a/debian-installer.sh b/debian-installer.sh index 3ca4e3b..14484de 100644 --- a/debian-installer.sh +++ b/debian-installer.sh @@ -1,6 +1,6 @@ #!/bin/bash -INSTALLERVERSION="1.04" +INSTALLERVERSION="1.05" if [[ $(whoami) != "root" ]]; then echo "You must be root to run this script!" @@ -988,15 +988,33 @@ declare PHPTIMEZONE declare TURNPASS eval $(grep '^PRETTY_NAME=' /etc/os-release) +eval $(grep '^ID=' /etc/os-release) +eval $(grep '^VERSION_ID=' /etc/os-release) +eval $(grep '^NAME=' /etc/os-release) +NAME_AND_VERSION="$NAME $VERSION_ID" -if [[ "$PRETTY_NAME" != "Debian GNU/Linux 12 (bookworm)" ]]; then +TESTED_ON=("Debian GNU/Linux 12" "Ubuntu 24.04") + +TESTED=false + +for ((n=0; n<${#TESTED_ON[@]}; n++)); do + if [[ "${TESTED_ON[$n]}" == "$NAME_AND_VERSION" ]]; then + TESTED=true + n=${#TESTED_ON[@]} + fi +done + +if [[ "$TESTED" == false ]]; 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 "This installer script has only been tested on:" + for ((n=0; n<${#TESTED_ON[@]}; n++)); do + echo " ${TESTED_ON[$n]}" + done + echo "but it should work on any Debian or Ubuntu based distro." echo - echo "Any distro that is not Debian based may result in a complete failure of the" - echo "installation process." + echo "Any distro that is not Debian or Ubuntu based may result in" + echo "a complete failure of the installation process." echo echo "Press ENTER to continue or CTRL+C to exit..." read input @@ -1122,7 +1140,7 @@ p=$(head -1 position.temp) if [[ $p -lt 2 ]]; then 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..." + apt -y install wget curl rsync screen wget sudo unzip jq cron nano > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to install dependancies..." ((p++)) echo "$p" > position.temp fi @@ -1148,6 +1166,10 @@ fi if [[ $p -lt 4 ]]; then decho "[Step $((p+1))] Installing Apache2 and Certbot for Let's Encrypt... [Current Runtime: $(showTimer $SECONDS)]" + if [[ $ID == "ubuntu" ]]; then + decho "You are running Ubuntu so we must add Sury Apache2 Repo..." + LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/apache2 || failMsg "Sury Apache2 Repo failed to add to Ubuntu..." + fi 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 @@ -1256,8 +1278,12 @@ if [[ $p -lt 11 ]]; then fi if [[ $p -lt 12 ]]; then - 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..." + decho "[Step $((p+1))] Adding Sury PHP Repo to $NAME... [Current Runtime: $(showTimer $SECONDS)]" + if [[ $ID="ubuntu" ]]; then + LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php || failMsg "Sury PHP Repo failed to add to Ubuntu..." + else + 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..." + fi apt update > /dev/null 2>> "$oldpath/installer-errors.log" || failMsg "apt failed to download Sury repo data..." ((p++)) echo "$p" > position.temp @@ -1349,20 +1375,9 @@ if [[ $p -lt 21 ]]; 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..." @@ -1407,6 +1422,7 @@ if [[ $p -lt 23 ]]; then 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..." + echo -n "Cron..." && systemctl restart cron.service > /dev/null 2>> "$oldpath/installer-errors.log" && echo "Success!" || failMsg "Cron failed to restart..." ((p++)) echo "$p" > position.temp fi @@ -1439,6 +1455,11 @@ if [[ $p -lt 24 ]]; then echo "Username: $NCADMIN" echo "Password: $NCPASS" echo + echo "First attempt to login will give a session expired error. Second attempt will be" + echo "successful. Administration settings page may give an error about the Cron. Wait" + echo "five minutes, it only runs once every five minutes so give it some time and the" + echo "error will go away..." + echo echo "A copy of the report has been copied to $NCADMIN's Files app for safe keeping." echo fi