112 lines
3.7 KiB
Bash
Executable File
112 lines
3.7 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"
|
|
phpver=$(php -v |head -1 |awk -F'.' '{print $1"."$2}' |sed 's/PHP //')
|
|
phpfpm="php$phpver-fpm" ; phpclidir="/etc/php/$phpver/cli" ; phpfpmdir="/etc/php/$phpver/fpm" ; socket="php$phpver"
|
|
#
|
|
# 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 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-web-server/nginx-install.git ; cp -R nginx-install/nginxsnippets /etc/nginx
|
|
fi
|
|
#
|
|
# Download the latest 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-web-server/nginx-install/raw/branch/main/cfg-apps/dokuwiki.80.conf > /etc/nginx/conf.d/$1.conf
|
|
sed -s -i "s/DOMAIN/$1/g" /etc/nginx/conf.d/$1.conf
|
|
sed -i "s/VERSION/$phpver/" /etc/nginx/conf.d/$1.conf
|
|
#
|
|
# Restarting Nginx and Phpfpm for changes to take effect
|
|
systemctl restart nginx && systemctl restart $phpfpm
|
|
#
|
|
# 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.
|
|
|
|
Once done go back to \"dokuwiki-install\" and run the following as root or using sudo.
|
|
|
|
./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-install
|
|
#
|
|
# End of script
|
|
#
|