dokuwiki-install/dokuwikiinstall

107 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
##########################################################################################
# First Created: 17082021 Author: Allan Desc: Installs DokuWiki on Ubuntu requires Nginx #
##########################################################################################
#
# Are we root
#
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi
#
# Are we in the right directory
#
scriptdir="dokuwiki-install" && whereami=$(pwd |awk -F'/' '{print $NF}')
if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n" ; exit ; fi
#
# Define variables and functions
#
red='\033[0;31m' ; bred='\033[1;31m' ; green='\033[0;92m' ; blue='\033[0;36m' ; bold='\033[1m' ; normal='\033[0m'
line (){ for i in {1..50}; do echo -n "$1"; done && printf "\n"; }
nginxfiles="/etc/nginx/nginxsnippets"
#
# Function title
#
title () { printf "\nDokuwiki install script V1.0\n\n"; }
#
# Function usage
#
usage () { clear ; printf -- "\n"
printf -- "${bold}dokuwikiinstall${normal} \n\n"
printf -- "${bold}Usage:${normal} \n"
printf -- "./dokuwikiinstall <domain> \n"
printf -- "${bold}Examples:${normal} \n"
printf -- "./dokuwikiinstall wiki.something.xyz\n\n"; }
#
# Function to check if a service is already running or not
#
serviceno () { printf "\n$service is not running cannot continue...\n\n"; }
servicedead () { status=$(systemctl is-active $service); if [[ "$status" != "active" ]]; then serviceno ; exit; fi; }
#
# Function input check
#
inputcheck () {
if [[ -z "$1" ]]; then printf "${bold}Error! ${normal}Hostname Empty...\n\n" ; exit; fi; }
#
# If Nginx and MariaDB is not running then die
#
service="nginx" ; servicedead
#
# Check if input conditions are met
#
usage ; inputcheck $1
#
# Display title
#
clear ; title
#
# Check if nginxsnippets exist if not download them
#
if [[ ! -d "$nginxfiles" ]]; then git clone --quiet https://git.x-files.dk/ubuntu-server-files/nginxsnippets.git $nginxfiles; fi
#
# Download Dokuwiki
#
wget --no-verbose https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz
#
# Create a DokuWiki nginx configuration file
#
curl --silent https://git.x-files.dk/ubuntu-server-files/nginx-config-examples/raw/branch/main/dokuwiki.80.conf > /etc/nginx/conf.d/$1.conf
sed -s -i "s/DOMAIN/$1/g" /etc/nginx/conf.d/$1.conf
#
# Restarting Nginx and Phpfpm for changes to take effect
sudo systemctl restart nginx && systemctl restart php8.1-fpm
#
# Extract DokuWiki set permisssions and rename according to input from user
#
mkdir -p /var/www/html
tar zxfp dokuwiki-stable.tgz -C /var/www/html
mv /var/www/html/dokuwiki* /var/www/html/$1
chown -R www-data: /var/www/html/$1
#
# DokuWiki postinstall notice
#
wikinotice="
-----------------------------------------------------------------------------------
IMPORTANT: Go to http://$1/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.
When ready go back to the directory where you installed dokuwiki from and run:
./postinstall
-----------------------------------------------------------------------------------
"
#
# Display post install note
#
clear ; printf '%s\n' "${wikinotice[@]}"
#
# Cleaning up and saving hostname for use with postinstall
echo $1 > hostname
#
rm -Rf dokuwiki-stable.tgz nginx-config-examples
#
# End of script
#