#!/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 # # Get php-fpm version # phpfpm=$(systemctl list-unit-files --type=service | awk '/php[0-9]+\.[0-9]+-fpm\.service/ {sub(".service","",$1); print $1; exit}') if [[ -z "$phpfpm" ]]; then printf "\nUnable to detect php-fpm version. Is PHP-FPM installed?\n\n" ; exit 1 ; fi # # Check if required services are running or not # for svc in nginx "$phpfpm"; do systemctl is-active --quiet "$svc" || { printf "\n%s is not running, cannot continue...\n\n" "${svc^}" ; exit 1 ; }; done # # Define variables and functions # hostname="$1" # # 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" } # # Parse and validate input # if [[ $# -ne 1 ]]; then usage ; printf "ERROR: Exactly one argument (the domain) is required.\n\n" ; exit 1 ; fi hostname="$1" ; hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') if [[ "$hostname" =~ [[:space:]/_] ]]; then printf "ERROR: Domain cannot contain spaces, slashes, or underscores.\n\n" ; exit 1 ; fi if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then printf "ERROR: Invalid domain format.\n" printf "Example of valid input: wiki.example.com\n\n" ; exit 1 fi # # Let's go # clear # # Check if input conditions are met # inputcheck "$hostname" # # Ensure curl is available # for tool in curl unzip wget; do dpkg -s "$tool" &>/dev/null || apt install -y "$tool" ; done # # 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 # printf "\nRestarting services...\n" systemctl restart "$phpfpm" systemctl restart nginx # # Create postinstall script # cat > /tmp/dokuwiki-postinstall <