#!/usr/bin/env bash # Author : Allan Christensen # First Created : 05012022 (DD-MM-YYYY) # Description : Installs DokuWiki on Ubuntu 24.04 # License : MIT License (see LICENSE file for details) # # Are we root # if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1 ; fi # # Define variables and functions # hostname="$1" # # Get php-fpm version # phpfpm=$(systemctl list-units --type=service --all | awk '/php[0-9]+\.[0-9]+-fpm/ {print $1; exit}' | sed 's/\.service//') if [[ -z "$phpfpm" ]]; then printf "\nUnable to detect php-fpm version. Is PHP-FPM installed?\n\n" ; exit 1 ; fi # # Function usage # usage () { printf -- "\ndokuwikiinstall\n\n" printf -- "Installs DokuWiki on Ubuntu\n\n" printf -- "Usage:\n" printf -- "sudo ./dokuwikiinstall \n" printf -- "Examples:\n" printf -- "sudo ./dokuwikiinstall wiki.something.xyz\n\n" } # # Function check if a service is running or stopped, including php-fpm # checkservice() { local svc="$1" ; local mode="$2" if [[ "$svc" == php*-fpm ]] && ! systemctl list-unit-files --type=service | grep -q "^${svc}.service" ; then svc="php-fpm" fi if [[ "$mode" == "mustberunning" ]]; then if ! systemctl is-active --quiet "$svc" 2>/dev/null; then printf "\nService %s is not running, aborting...\n\n" "$svc" exit 1 fi elif [[ "$mode" == "mustnotberunning" ]]; then if systemctl is-active --quiet "$svc" 2>/dev/null; then printf "\nService %s is already running, aborting...\n\n" "$svc" exit 1 fi fi } # # Function input check # inputcheck () { if [[ -z "$1" ]]; then usage ; printf "ERROR: DOMAIN CANNOT BE EMPTY!\n\n" ; exit; fi; } # # If Nginx or PHP-Fpm is not running then die. # checkservice nginx mustberunning ; checkservice "$phpfpm" mustberunning # # Let's go # clear # # Check if input conditions are met # inputcheck "$hostname" # # Clone nginx-snippets; if nginx-snippets exists then just pull latest changes # nginxsnippets="/etc/nginx/nginx-snippets" repo="https://git.x-files.dk/webserver/nginx-snippets.git" if [[ -d "$nginxsnippets/.git" ]]; then git -C "$nginxsnippets" pull --quiet; else git clone --quiet "$repo" "$nginxsnippets"; fi # # Download the latest Dokuwiki # wikidir="/var/www/html/$hostname" ; mkdir -p "$wikidir" curl -sL https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz | tar -xzf - -C "$wikidir" --strip-components=1 || { echo "Download or extraction failed"; exit 1; } chown -R www-data: "$wikidir" # # Create a DokuWiki nginx configuration file # cp "$nginxsnippets/hostfiles/dokuwiki.80.conf" /etc/nginx/conf.d/"$hostname".conf sed -i -- "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf sed -i "s/PHPVERSION/$phpfpm/" /etc/nginx/conf.d/"$hostname".conf # # Restarting Nginx and Phpfpm for changes to take effect # systemctl restart "$phpfpm" systemctl restart nginx # # Create postinstall script # cat > /tmp/dokuwiki-postinstall <