You've already forked dokuwiki-ubuntu
146 lines
3.4 KiB
Bash
Executable File
146 lines
3.4 KiB
Bash
Executable File
#!/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"
|
|
phpver=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') ; phpfpm="php$phpver-fpm"
|
|
|
|
#
|
|
# Function usage
|
|
#
|
|
usage () {
|
|
printf -- "\ndokuwikiinstall\n\n"
|
|
printf -- "Installs DokuWiki on Ubuntu\n\n"
|
|
printf -- "Usage:\n"
|
|
printf -- "sudo ./dokuwikiinstall <domain>\n"
|
|
printf -- "Examples:\n"
|
|
printf -- "sudo ./dokuwikiinstall wiki.something.xyz\n\n"
|
|
}
|
|
|
|
#
|
|
# Function to check if a service is already running or not
|
|
#
|
|
serviceno () { printf "\n%s" "$service" ; printf " is not running cannot continue...\n\n"; }
|
|
servicedead () { status=$(systemctl is-active "$service"); if [[ "$status" != "active" ]]; then serviceno ; exit 1 ; fi; }
|
|
|
|
#
|
|
# Function input check
|
|
#
|
|
inputcheck () { if [[ -z "$1" ]]; then usage ; printf "ERROR: DOMAIN CANNOT BE EMPTY!\n\n" ; exit; fi; }
|
|
|
|
#
|
|
# If Nginx is not running then die
|
|
#
|
|
service="nginx" ; servicedead
|
|
|
|
#
|
|
# 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/VERSION/$phpver/" /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 <<EOF
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Dokiwiki Postinstall Script
|
|
#
|
|
|
|
#
|
|
# Are we root?
|
|
#
|
|
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi
|
|
|
|
#
|
|
# Hardening of Dokuwiki
|
|
#
|
|
sed -i 's/# location /location /g' /etc/nginx/conf.d/"$hostname".conf
|
|
|
|
#
|
|
# Restart Nginx for changes to take effect
|
|
#
|
|
systemctl restart nginx
|
|
|
|
#
|
|
# Cleaning up
|
|
#
|
|
rm -f /tmp/dokuwiki-postinstall
|
|
EOF
|
|
|
|
chmod 755 /tmp/dokuwiki-postinstall
|
|
|
|
#
|
|
# DokuWiki postinstall notice
|
|
#
|
|
wikinotice=$(cat <<EOF
|
|
-----------------------------------------------------------------------------------
|
|
IMPORTANT: Go to http://$hostname/install.php in order to complete the installation:
|
|
|
|
Don't worry about the warning on the right side of the page this will be
|
|
fixed as there still is a post install step to do.
|
|
|
|
Once done run the following command as root or using sudo.
|
|
|
|
sudo /tmp/dokuwiki-postinstall
|
|
-----------------------------------------------------------------------------------
|
|
EOF
|
|
)
|
|
|
|
#
|
|
# Print notice
|
|
#
|
|
printf '%s\n' "$wikinotice"
|
|
|
|
#
|
|
# All done
|
|
#
|
|
printf "\nAll Done...\n"
|
|
|
|
#
|
|
# End of script
|
|
#
|