minor changes
This commit is contained in:
parent
e33855cab2
commit
4c5475ff27
@ -12,15 +12,13 @@ if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo
|
||||
# Are we in the right directory
|
||||
#
|
||||
scriptdir="wordpress-install" && whereami=$(pwd |awk -F'/' '{print $NF}')
|
||||
if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n" ; exit ; fi
|
||||
if [ "$whereami" != "$scriptdir" ]; then printf "\nWrong directory! Script must be run from %s\n\n" "$scriptdir"; exit 1; 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"; }
|
||||
line () { printf -- '-%.0s' {1..50}; 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"
|
||||
phpver=$(php -v |head -1 |awk -F'.' '{print $1"."$2}' |sed 's/PHP //') ; phpfpm="php$phpver-fpm"
|
||||
#
|
||||
# Function title
|
||||
#
|
||||
@ -29,28 +27,28 @@ title () { printf "\nWordpress install script V1.0\n\n"; }
|
||||
# Function usage
|
||||
#
|
||||
usage () { clear ; printf -- "\n"
|
||||
printf -- "${bold}wordpressinstall${normal} \n\n"
|
||||
printf -- "${bold}Usage:${normal} \n"
|
||||
printf -- "wordpressinstall \n\n"
|
||||
printf -- "Usage: \n"
|
||||
printf -- "./wordpressinstall [-n] <wordpress domain> \n"
|
||||
printf -- " [-d] <wordpress database name> \n"
|
||||
printf -- " [-u] <wordpress database user> \n"
|
||||
printf -- " [-p] <wordpress database password> \n"
|
||||
printf -- " [-help] <this screen> \n\n"
|
||||
printf -- "${bold}Examples:${normal} \n"
|
||||
printf -- "Examples: \n"
|
||||
printf -- "./wordpressinstall -n wp.something.xyz -d wpdb -u wpuser -p wppassword \n\n"; }
|
||||
#
|
||||
# Function to check if a service is already running or not
|
||||
#
|
||||
serviceno () { printf "\n$service is not running cannot continue...\n\n"; }
|
||||
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; fi; }
|
||||
#
|
||||
# Function input check
|
||||
#
|
||||
inputcheck () {
|
||||
if [[ -z "$hostname" ]]; then usage ; printf "${bold}Error! ${normal}Hostname Empty...\n\n" ; exit; fi
|
||||
if [[ -z "$wpdbname" ]]; then usage ; printf "${bold}Error! ${normal}Database name Empty...\n\n" ; exit; fi
|
||||
if [[ -z "$wpdbuser" ]]; then usage ; printf "${bold}Error! ${normal}Database username Empty...\n\n" ; exit; fi
|
||||
if [[ -z "$wpdbpass" ]]; then usage ; printf "${bold}Error! ${normal}Database Password Empty...\n\n" ; exit; fi; }
|
||||
if [[ -z "$hostname" ]]; then usage ; printf "Error! Hostname Empty...\n\n" ; exit; fi
|
||||
if [[ -z "$wpdbname" ]]; then usage ; printf "Error! Database name Empty...\n\n" ; exit; fi
|
||||
if [[ -z "$wpdbuser" ]]; then usage ; printf "Error! Database username Empty...\n\n" ; exit; fi
|
||||
if [[ -z "$wpdbpass" ]]; then usage ; printf "Error! Database Password Empty...\n\n" ; exit; fi; }
|
||||
#
|
||||
# If Nginx and MariaDB is not running then die
|
||||
#
|
||||
@ -62,7 +60,10 @@ clear ; title
|
||||
#
|
||||
# Configure command line options
|
||||
#
|
||||
if [[ ! $@ =~ ^\-.+ ]]; then usage; fi
|
||||
|
||||
# Removed due to SC2199 and not really needed start
|
||||
# if [[ ! $@ =~ ^\-.+ ]]; then usage; fi
|
||||
# Removed due to SC2199 and not really needed stop
|
||||
|
||||
while getopts "n:d:u:p:h:" option; do
|
||||
case $option in
|
||||
@ -83,13 +84,13 @@ while getopts "n:d:u:p:h:" option; do
|
||||
usage ; exit;;
|
||||
|
||||
\?) # invalid option
|
||||
printf "Type $0 -help for help\n\n" ; exit;;
|
||||
printf "\nType sudo " ; printf "%s" "$0" ; printf " -help for help\n\n" ; exit;;
|
||||
esac
|
||||
done
|
||||
#
|
||||
# Check if input conditions are met
|
||||
#
|
||||
inputcheck $hostname $wpdbname $wpdbuser $wpdbpass
|
||||
inputcheck "$hostname" "$wpdbname" "$wpdbuser" "$wpdbpass"
|
||||
#
|
||||
# Download Wordpress
|
||||
#
|
||||
@ -102,10 +103,10 @@ cp wordpress/wp-config-sample.php wordpress/wp-config.php
|
||||
sed -i "s/database_name_here/$wpdbname/" wordpress/wp-config.php
|
||||
sed -i "s/username_here/$wpdbuser/" wordpress/wp-config.php
|
||||
sed -i "s/password_here/$wpdbpass/" wordpress/wp-config.php
|
||||
mv wordpress $hostname
|
||||
mv wordpress "$hostname"
|
||||
mkdir -p /var/www/html
|
||||
mv $hostname /var/www/html
|
||||
chown -R www-data: /var/www/html/$hostname
|
||||
mv "$hostname" /var/www/html
|
||||
chown -R www-data: /var/www/html/"$hostname"
|
||||
#
|
||||
# Check if nginxsnippets exist if not download them
|
||||
#
|
||||
@ -127,13 +128,13 @@ mysql < wpsql.sql
|
||||
#
|
||||
# Create a Wordpress Nginx configuration file
|
||||
#
|
||||
curl --silent https://git.x-files.dk/ubuntu-web-server/nginx-install/raw/branch/main/cfg-apps/wordpress.80.conf > /etc/nginx/conf.d/$hostname.conf
|
||||
curl --silent https://git.x-files.dk/ubuntu-web-server/nginx-install/raw/branch/main/cfg-apps/wordpress.80.conf > /etc/nginx/conf.d/"$hostname".conf
|
||||
cp /etc/nginx/nginxsnippets/rate-limit.conf /etc/nginx/conf.d/
|
||||
sed -s -i "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/$hostname.conf
|
||||
sed -i "s/VERSION/$phpver/" /etc/nginx/conf.d/$hostname.conf
|
||||
sed -s -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 nginx && systemctl restart $phpfpm
|
||||
systemctl restart nginx && systemctl restart "$phpfpm"
|
||||
#
|
||||
# Wordpress notice
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user