smeserver-wordpress/root/etc/e-smith/events/actions/wordpress-install.sh

105 lines
2.5 KiB
Bash
Raw Normal View History

#!/bin/bash
# Script Name: WordPress Install Shell Script for SME10 https://koozali.com
# Brian Read brianr@bjsystems.co.uk March 2021
# Based on:
# Script URI: http://www.redbridgenet.com/wordpress/wordpress-upgrade-shell-script/
# Description: Upgrades your WordPress installation following more closely the WordPress guidelines.
# Version: 1.0.0
# Author: Ed Reckers
# Author URI: http://www.redbridgenet.com/
# License: GPL2
#
# Usage ./upgrade.wordpress.sh
#
# Linux bin paths
MYSQLDUMP="$(which mysqldump)"
TAR="$(which tar)"
GZIP="$(which gzip)"
WGET="$(which wget)"
UNZIP="$(which unzip)"
CP="$(which cp)"
RM="$(which rm)"
CD="$(which cd)"
MKDIR="$(which mkdir)"
CHOWN="$(which chown)"
# Set mysql account credentials
MyNAME=$(db configuration getprop wordpress DbName)
MyUSER=$(db configuration getprop wordpress DbUser)
MyPASS=$(db configuration getprop wordpress DbPassword)
MyHOST="localhost"
#Temp working area
TEMPDIR=$(mktemp -d)
# Directory containing your wordpress installation
WEBROOT="/usr/share/wordpress/"
# Get a sortable date like 2011-01-01 for full backups
FULLDATE="$(date +"%Y-%m-%d")"
# Create progress dots function
show_dots() {
while ps $1 >/dev/null ; do
printf "."
sleep 1
done
printf "\n"
}
#Place to find the latest WordPress
LATEST_WP="latest.zip"
URL_FOR_WP_DOWNLOAD="http://wordpress.org/"$LATEST_WP
# Check if Wordpress already here, if so exit
$MKDIR -p $WEBROOT
$CD $WEBROOT
if [[ -d wp-admin && -d wp-includes && -d wp-content ]]; then
echo "Found WordPress in $WEBROOT - exiting"
exit
fi
$CD $TEMPDIR
# Get the latest WordPress package
$RM -f $LATEST_WP
echo "get WordPress package..."
$WGET -qq $URL_FOR_WP_DOWNLOAD &
show_dots $!
#Check download worked
if [ ! -f "$LATEST_WP" ]; then
echo "Unable to download WordPress from $URL_FOR_WP_DOWNLOAD"
exit
fi
# Unzip the files
echo "unzip WordPress package..."
$UNZIP -q latest.zip;
# Remove the zip file
echo "remove WordPress package..."
$RM latest.zip;
# Copy all new files from unziped WordPress package into your installation
echo "copy new WordPress files..."
$CP -r wordpress/* $WEBROOT;
echo "Create link to /etc/wordpress/wp-config.php"
touch /etc/wordpress/wp-config.php
ln -s /etc/wordpress/wp-config.php $WEBROOT/wp-config.php
echo "..and reset ownership"
$CHOWN -R www:root $WEBROOT;
# Remove the unzipped folder
echo "cleanup unzipped WordPress package..."
$RM -r wordpress/;
# And remove Temp dir
$RM -R ${TEMPDIR}
# Output that all steps are complete
echo "Wordpress Successfully Installed";
#exit from script execution