Skip to content

Instantly share code, notes, and snippets.

@cconversion
Created October 25, 2018 22:33
Show Gist options
  • Save cconversion/970ce97d80d92ff1f5569886367c2a4f to your computer and use it in GitHub Desktop.
Save cconversion/970ce97d80d92ff1f5569886367c2a4f to your computer and use it in GitHub Desktop.
WordPress Bash|Zsh Installer Script - deploy Local WordPress free and easy - Ubuntu18 Tested - HTTPS SINGLE OR MULTISITE - Easy Configure Setup
#!/bin/bash
#
#logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt
#echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
#echo "*****************" >> "$logfile"
#######################################################################################################################################
SHHH=">/dev/null 2>&1"
inval="[-\._ \'\=\&\@\#\%\*\!\~\`\:\$\(\)\[\]\^\~\/\\\ ][0-9]"
urlsafe="[^a-zA-Z0-9_-]"
em_shrug='¯\_(ツ)_/¯'
datetimenow=$(date +%Y-%m-%d_%H:%M)
datenow=$(date +%Y-%m-%d)
#######################################################################################################################################
### Pretty Colours in the Terminal
cb="\033[1;34m"
ccb="\033[1;36m"
gb="\033[1;32m"
rb="\033[1;31m"
wb="\033[1;37m"
endp="\n\033[0m"
nc="\033[0m"
donecmd="[DONE]"
failcmd="[FAIL]"
function inform_return { if [[ $? -eq 0 ]] ; then echo -en "${gb}\b${donecmd}"${endp} ; else echo -en "${rb}\b${failcmd}"${endp} ; fi }
# printf "$rb||<${wb}--------------------------------------------------------------------------------------------------${rb}>||"
# printf $gb.'
# __ __ __
# /) __, , -/- |__) /\ /__` | / `
# _//_(_/(__/_)__/_ & |__) /~~\ .__/ | \__,
# _/
# /)
# `
# '
printf "
${gb} ____ ____ ____ ____ ____ ____ ____ ____ ____
||${rb}I${gb} |||${rb}N${gb} |||${rb}S${gb} |||${rb}T${gb} |||${rb}A${gb} |||${rb}L${gb} |||${rb}L${gb} |||${rb}E${gb} |||${rb}R${gb} ||
||__|||__|||__|||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
"${endp}
#||I |||N |||S |||T |||A |||L |||L |||E |||R ||
printf "Warning: Do not use on a multi-user system unless you have applied the various kernel security patches that prevent users from looking at other users' process information
${rb}Please check installed local environment is setup properly. see 'wp-prov'
${rb}Please read through this installer script first, and edit any default values you need to fit your personal other less 'dynamic' evironment variables.
Otherwise, just comment out these lines with a '${gb}#${rb}' and save the verbosity.
"
####################################################################################### LET ME KNOW TAG
#######################################################################################################################################
WPCLI=$(which wp)
#######################################################################################################################################
####################################################################################### USER DEFAULTS
# DEV_USERS=$(ps aux | grep apache | awk '{print $1;}' | uniq)
APACHE_USER="www-data"
DEV_USER="$USER"
APACH_GROUP_APP="${APACHE_USER}-${DEV_USER}"
APACH_GROUP=${APACH_GROUP_APP}
APP_CLIENT_DEFAULT="zzztmp" #url-safe, dir-safe
GMAIL_ID="myemail" # installer assumes '[email protected]'
DB_HOST_DEFAULT="localhost"
DB_USER_ROOT="root"
DB_PASS_ROOT="root"
#######################################################################################################################################
####################################################################################### PERMISSIONS TEMPLATE
# +------- -u: UserOwner
# |+----- -g: Group
# ||+--- -w: World
# |||
# 777
DIRS_MOD="755"
FILE_MOD="664"
CONF_MOD="640"
DIRS_APP_MOD="775"
FILE_APP_MOD="664"
HTAC_MOD="660"
#######################################################################################################################################
####################################################################################### APACHE SERVER DEFAULT
MY_IP_LOCAL="127.0.0.1"
# inet='inet' && MY_IP_LOCAL_ADD=$(ifconfig | sed -En "s/${MY_IP_LOCAL//\./\\\.}//;s/.*${inet} (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p")
APACHE_PHPINI="$(find /etc/php -type f -name "php.ini" | grep -m 1 "apache2")"
APACHE_WROOT_DIR="/var/www" # Apache web document root (e.g. xampp/htdocs)
APACHE_VHOST_PORT="80"
APACHE_VHOST_PORT_SSL="443"
APACHE_VHOST_IP_LISTEN="*"
APACHE_VHOST_DIR="/etc/apache2/sites-available" # and VirtualHosts
APACHE_SSLDIR="/etc/apache2/ssl" # /certs (pem), /private (key)
SSLDIR_DIR_MOD="700" # Recommended 700; 500 manual update required at renewal time
SSLDIR_FILE_MOD="600" # Recommended 600; 400 if you don't mind having to fiddle with them at renewal time
#######################################################################################################################################
################################################################################################################# - USER INPUT REQUIRED
####################################################################################### SITE|MULTISITE OPTIONS
printf "${ccb}Pick an option (${gb}[1] Recommended${ccb}) and hit ${gb}[ENTER]"${endp}
options=("SINGLE SITE (standard)" "MULTISITE SUB-DOMAIN (pre.url)" "MULTISITE SUB-DIRECTORY (/page-slug)" "Quit") && PS3="[ENTER]: "
select opt in "${options[@]}"; do
case "$REPLY" in
1|single|wp|standard|[yY] ) IS_MULTISITE="false" ; break;;
2|*dom*|cn|ur*|pre* ) IS_MULTISITE="domain" ; break;;
3|*dir*|*slug* ) IS_MULTISITE="directory" ; break;;
4|quit|exit|[qQ]|[xX]) printf "${gb}${em_shrug}"${endp} ; exit 1 ; break;;
*) printf "${gb}${em_shrug}"${endp} ; exit 1 ; break;;
esac
done
printf "${gb}[SET]${wb} ${IS_MULTISITE} "${endp}
####################################################################################### CLIENT DEFAULTS
printf "${ccb}Select which Client/Project directory this install goes in"${endp}
options=("DEFAULT (${APP_CLIENT_DEFAULT//$inval/})" "EXISTING CLIENT" "NEW CLIENT") && PS3="[ENTER]:"
# printf "${gb}"
select opt in "${options[@]}" ; do
case "$REPLY" in
1|[yY]|[dD][eE][fF][aA][uU][lL][tT]|[dD] ) APP_CLIENT="${APP_CLIENT_DEFAULT//$inval/}" ; break;;
2|[eE]|[eE][xX][iI][st]* ) printf "${ccb}Enter an existing Client name : ${endp}"
read -r CLIENT_READ ;
while [ ! -d "${APACHE_WROOT_DIR}/${CLIENT_READ}" ] ; do
printf "${rb}[NO RECORD]${ccb}Enter an existing Client name : ${endp}"
read -r CLIENT_READ
done ; printf "${gb}[FOUND] project folder : ${gb} ${CLIENT_READ//$inval/} ${endp}"
APP_CLIENT="${CLIENT_READ//$inval/}"
break;;
3|[nN][eE][wW]* ) printf "${ccb}Enter a new Client Name : ${endp}"
read -r CLIENT_READ ;
while [ -d "${APACHE_WROOT_DIR}/${CLIENT_READ}" ] ; do
printf "${rb}[TAKEN]${ccb}Enter a new Client Name : ${endp}"
read -r CLIENT_READ
done ; printf "${gb}[SET] project folder : ${gb} ${CLIENT_READ//$inval/} ${endp}"
APP_CLIENT="${CLIENT_READ//$inval/}" ; break;;
* ) echo "Invalid option ${REPLY} ... Try another one." ; continue;;
esac
done
printf "${gb}[SET] ${ccb} ${APP_CLIENT} "${endp}
APP_CLIENT_ALIAS=$(echo "${APP_CLIENT}" | tr -dc '[:alpha:]' | tr '[:upper:]' '[:lower:]')
APP_CLIENT_ALI=$(echo "${APP_CLIENT_ALIAS}" | cut -c1-3)
####################################################################################### INSTALLER DEFAULTS
printf "${ccb}Select which Installation Wizard to run"${endp}
options=("DEFAULT INSTALLER" "CUSTOM INSTALL ('5 Minute WP')") && PS3="[ENTER]:"
# printf "${gb}"
select opt in "${options[@]}" ; do
case "$REPLY" in
1|[dD][eE][fF][aA][uU][lL][tT]|[dD] ) DEFAULT_INSTALL='true' ; break;;
2|[cC][uU][sS][tT][uU][mM]|[cC] ) DEFAULT_INSTALL='false' ; break;;
esac
done
#######################################################################################################################################
####################################################################################### WEBSITE URL DEFAULT NONCE
#### GENERATE UNIQUE URL DEFAULTS
URL_NONCE_STATUS="1"
while [[ "$URL_NONCE_STATUS" == "1" ]] ; do
URL_GENERATED=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 6 | head -n 1)
if [[ "$(find /etc/apache2/sites-available -name "*${URL_GENERATED}*")" == "*${URL_GENERATED}*" ]] ; then
URL_NONCE_STATUS='1'
else URL_FOUND="${URL_GENERATED}"
URL_NONCE_STATUS='0'
fi
done
#### GENERATOR END
####################################################################################### WEBSITE URL DEFAULTS
APP_PROTOCOL='https://'
APP_DOMAIN_CSD_DEFAULT="www"
APP_DOMAIN_URD_DEFAULT="i${URL_FOUND}"
APP_DOMAIN_TLD_DEFAULT=".in" # do not use first dot|'.' , sub-T.L.D,Name dots are fine.
APP_DOMAIN_TLD_DEFAULT=${APP_DOMAIN_TLD_DEFAULT#\.} # just in case you used a dot to prefix TLDname
# e.g. www.igenerated.in
####################################################################################### WEBSITE URL INTERACTIVE
printf "${ccb}Lets create a domain name..."${endp}
printf "${ccb}Hit ${wb}[ENTER]${ccb} to use defaults..."${endp} && URL_NONCE_STATUS="1"
while [[ "$URL_NONCE_STATUS" == "1" ]] ; do
# www
printf "${ccb}Enter a ${wb}CName ${rb}e.g. 'www', 'stage', 'subdomain' ${ccb}: "${endp}
read -r APP_DOMAIN_CSD
if [[ "${APP_DOMAIN_CSD//\./}" == "" ]]; then APP_DOMAIN_CSD=${APP_DOMAIN_CSD_DEFAULT//$urlsafe/} ; fi
printf "${ccb}[CSD] ${wb} : ${gb} '${APP_DOMAIN_CSD}'"${endp}
# domainname
printf "${ccb}Enter a Site ${wb}URL ${rb}(exclude ${APP_PROTOCOL}${wb}sub.${rb} and ${wb}.tld${rb}), they are already assumed)${ccb}: "${endp}
read -r APP_DOMAIN_URD
APP_DOMAIN_URD=${APP_DOMAIN_URD//$urlsafe/}
if [[ "${APP_DOMAIN_URD//\./}" == "" ]]; then APP_DOMAIN_URD=${APP_DOMAIN_URD_DEFAULT//$urlsafe/} ; fi
printf "${ccb}[URD] ${wb} : ${gb} '${APP_DOMAIN_URD}'"${endp}
# domain tlds
printf "${ccb}Enter a ${wb}TLDname"${endp}
printf "${gb}Include${wb} the dots '${gb}.${wb}com', '${gb}.${wb}net${gb}.${wb}au', '${gb}.${wb}etc'"${endp}
read -r APP_DOMAIN_TLD
if [[ "${APP_DOMAIN_TLD//\./}" == "" ]]; then APP_DOMAIN_TLD=${APP_DOMAIN_TLD_DEFAULT} ; fi
printf "${ccb}[TLD] ${wb} : ${gb} '${APP_DOMAIN_TLD#\.}'"${endp}
# sanitise a bit
APP_DOMAIN_CSD=${APP_DOMAIN_CSD//$urlsafe/}
APP_DOMAIN_URD=${APP_DOMAIN_URD//$urlsafe/}
APP_DOMAIN_URD_UPPERCUT=${APP_DOMAIN_URD^^} && APP_DOMAIN_URD_UPPERCUT=${APP_DOMAIN_URD_UPPERCUT:0:4}
APP_DOMAIN_TLD=${APP_DOMAIN_TLD#\.}
APP_URL="${APP_DOMAIN_URD}.${APP_DOMAIN_TLD}"
APP_URL_FULL="${APP_DOMAIN_CSD}.${APP_URL}"
APP_URL_WILD="*.${APP_URL}"
APP_URL_DIRSAFE="${APP_URL_FULL//[^[:alnum:]]/}"
# check domain
if [[ $(find "${APACHE_VHOST_DIR}" -maxdepth 2 -type d -name "${APP_URL_FULL}") ]] ; then
URL_NONCE_STATUS="1"
printf "${rb}[RETRY]${ccb} Domain already taken for ${APP_URL_FULL} "${endp}
else
URL_NONCE_STATUS="0"
printf "${ccb}[SET] '${APP_URL_FULL}'"${endp}
fi
done
####################################################################################### WP SITE SETUP DEFAULTS
APP_TITLE_DEFAULT="${APP_DOMAIN_URD^^} App"
APP_ADMIN_DEFAULT="u0${APP_CLIENT_ALI^^}_${DEV_USER:0:3}"
APP_PASSWORD_DEFAULT="${APP_DOMAIN_URD_UPPERCUT}_${APP_CLIENT_ALI,,}${datenow//[^[:alnum:]]/}"
APP_EMAIL_DEFAULT="${GMAIL_ID}+${APP_URL_DIRSAFE}@gmail.com"
####################################################################################### SITE DATABASE DEFAULTS
# existing ${APP_PROTOCOL}blog.sucuri.net/2015/07/wp-cli-guide-secure-wordpress-backup-update.html
#### GENERATE UNIQUE DATABASE DEFAULTS
DB_NONCE_STATUS="1"
while [[ "$DB_NONCE_STATUS" == "1" ]] ; do
DB_GENERATED=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 3 | head -n 1)
if [[ $(sudo mysql --user=${DB_USER_ROOT} --password=${DB_PASS_ROOT} -e "show databases;" | egrep "${DB_GENERATED}") ]] ; then
DB_NONCE_STATUS='1'
else DB_FOUND_UNIQUE="${DB_GENERATED}"
DB_NONCE_STATUS='0'
fi
done
DB_STATICMARKER="DB0"
DB_NAME_UNCUT="${DB_STATICMARKER}${DB_FOUND_UNIQUE}_${APP_URL_DIRSAFE}"
DB_NAME_DEFAULT="${DB_NAME_UNCUT:0:42}"
DB_USER_DEFAULT="${APP_CLIENT_ALIAS^^}_${DB_FOUND_UNIQUE,,}"
DB_PASS_DEFAULT="${DB_FOUND_UNIQUE}_${DB_STATICMARKER^^}1_${APP_CLIENT_ALI,,}_${datenow//[^[:alnum:]]/}"
DB_TABL_PRE_DEFAULT="${DB_FOUND_UNIQUE}_"
if [[ "${DB_TABL_PRE_DEFAULT}" == "" ]] ; then DB_TABL_PRE_DEFAULT="${APP_CLIENT_ALI,,}_" ; fi
####################################################################################### SITE & CLIENT DIRECTORIES
APP_CLIENT_DIR="${APACHE_WROOT_DIR}/${APP_CLIENT_ALIAS}"
APP_CLIENT_FOLDERS="backup
cgi-bin
log
private
public
scripts
specs
tmp
"
APP_DIR="private/${APP_URL_DIRSAFE}" # rootname
APP_ABSPATH="${APP_CLIENT_DIR}/${APP_DIR}" # var/www/client/private/site
APP_CONTENT_DIR='io' # wp-content
APP_PLUGIN_DIR='ext' # plugins
APP_MUPLUGINS_DIR='extio' # mu-plugins
# @todo https://trickspanda.com/hide-wordpress-admin-url/
APP_UPLOAD_DIR='box' # /uploads
APP_DIR_regex=".*?(/plugins|/wp-plugins|plugin|${APP_PLUGIN_DIR}|${APP_CONTENT_DIR}|${APP_UPLOAD_DIR}|${APP_MUPLUGINS_DIR}).*?"
####################################################################################### BACKUP AND LOGGING
APP_BACKUP_DIR="${APP_CLIENT_DIR}/backup/${APP_URL_DIRSAFE}"
APP_ERROR_LOG="${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}.error.log"
APP_ACCESS_LOG="${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}.access.log"
APP_XFER_LOG="${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}.xfer.log"
DEV_PLUGIN_REPO_DEFAULT="/home/$USER/wp/plugins"
####################################################################################### CONFIG WIZARD
printf "${cb}Starting WordPress Installation Script"${endp}
printf "${ccb}[APP_CLIENT] ${wb} : ${gb} '${APP_CLIENT}' [ ${APP_CLIENT_ALIAS} , ${APP_CLIENT_ALI} ]"${endp}
printf "${ccb}[APP_ABSPATH]${wb} : ${gb} '${APP_ABSPATH}'"${endp}
printf "${ccb}[APP_DIR] ${wb} : ${gb} '${APP_DIR}'"${endp}
printf "${ccb}[APP_DOMAIN] ${wb} : ${gb} '${APP_URL_FULL}'"${endp}
printf "${ccb}[APACH_GROUP]${wb} : ${gb} '${APACH_GROUP}'"${endp}
####################################################################################### DEVELOPER USER
# printf "${ccb}What is your username (not sudo), this might be the dev's username"${endp}
# read -r DEV_USER
# [ -z "$DEV_USER" ] && \
DEV_USER=$USER
# printf "${ccb}[DEV_USER] ${wb} : ${gb} '${DEV_USER}'"${endp}
####################################################################################### DEFAULT DATABASE CONFIGS
DB_NAME=${DB_NAME_DEFAULT}
DB_TABL_PRE=${DB_TABL_PRE_DEFAULT}
DB_USER=${DB_USER_DEFAULT}
DB_PASS=${DB_PASS_DEFAULT}
DB_HOST=${DB_HOST_DEFAULT}
####################################################################################### DEFAULT WP 'FIVE-MINUTE' CONFIGS
APP_TITLE=${APP_TITLE_DEFAULT}
APP_ADMIN=${APP_ADMIN_DEFAULT}
APP_PASSWORD=${APP_PASSWORD_DEFAULT}
APP_EMAIL=${APP_EMAIL_DEFAULT}
####################################################################################### CUSTOM DATABASE CONFIGS
if [ "${DEFAULT_INSTALL}" = "false" ] ; then
printf "${ccb}Enter a name for your MySQL database for the Wordpress install : "${endp}
read -r DB_NAME
[ -z "$DB_NAME" ] && DB_NAME=${DB_NAME_DEFAULT}
DB_NAME_LEN=$(echo -n "$DB_NAME" | wc -m)
if (( $DB_NAME_LEN > 49 )) ; then DB_NAME=${DB_NAME:0:50} ; fi
printf "${ccb}[DB_NAME] ${wb} : ${gb} '${DB_NAME}'"${endp}
#
printf "${ccb}Enter a name your MySQL table prefix for the database : "${endp}
read -r DB_TABL_PRE
[ -z "$DB_TABL_PRE" ] && DB_TABL_PRE=${DB_TABL_PRE_DEFAULT}
DB_TABL_PRE=${DB_TABL_PRE//_}
DB_TABL_PRE="${DB_TABL_PRE}_"
printf "${ccb}[DB_TABL_PRE] ${wb} : ${gb} '${DB_TABL_PRE}'"${endp}
#
printf "${ccb}Enter a new Wordpress Database Username : "${endp}
read -r DB_USER
[ -z "$DB_USER" ] && DB_USER=${DB_USER_DEFAULT}
printf "${ccb}[DB_USER] ${wb} : ${gb} '${DB_USER}'"${endp}
#
printf "${ccb}Enter a new Wordpress Database Password : "${endp}
read -r DB_PASS
[ -z "$DB_PASS" ] && DB_PASS=${DB_PASS_DEFAULT}
printf "${ccb}[DB_PASS] ${wb} : ${gb} '${DB_PASS}'"${endp}
#
printf "${ccb}Enter your Wordpress Database Host (e.g. localhost) : "${endp}
read -r DB_HOST
[ -z "$DB_HOST" ] && DB_HOST=${DB_HOST_DEFAULT}
printf "${ccb}[DB_HOST] ${wb} : ${gb} '${DB_HOST}'"${endp}
#
####################################################################################### CUSTOM WP 'FIVE-MINUTE' CONFIGS
printf "${cb}Now, to Configure and run our WordPress Core we need the basic details... "${endp}
printf "${ccb}Enter a Site Title : "${endp}
read -r APP_TITLE
[ -z "$APP_TITLE" ] && APP_TITLE=${APP_TITLE_DEFAULT}
printf "${ccb}[APP_TITLE] ${wb} : ${gb} '${APP_TITLE}'"${endp}
#
printf "${ccb}Enter a Site Admin Username : "${endp}
read -r APP_ADMIN
[ -z "$APP_ADMIN" ] && APP_ADMIN=${APP_ADMIN_DEFAULT}
printf "${ccb}[APP_ADMIN] ${wb} : ${gb} '${APP_ADMIN}'"${endp}
#
printf "${ccb}Enter a Site Admin Password : "${endp}
read -r APP_PASSWORD
[ -z "$APP_PASSWORD" ] && APP_PASSWORD=${APP_PASSWORD_DEFAULT}
printf "${ccb}[APP_PASS] ${wb} : ${gb} '${APP_PASSWORD}'"${endp}
#
printf "${ccb}Enter a Site Admin Email : "${endp}
read -r APP_EMAIL
[ -z "$APP_EMAIL" ] && APP_EMAIL=${APP_EMAIL_DEFAULT}
printf "${ccb}[APP_EMAIL] ${wb} : ${gb} '${APP_EMAIL}'"${endp}
fi
#######################################################################################################################################
####################################################################################### EASY UNDO SCRIPT
printf "${rb}Creating an 'Easy Uninstaller' before we start making changes"${endp}
UNINSTALL_CONF="#!/bin/bash
# Move this file to root so you can delete project dirs,
# make file executable,
# run the command '${datetimenow//\:\-/}.uninstall'.
#
echo \"# @todo BACKUP BEFORE PROCEEDING! Raw deletion in 3 seconds...
([Ctrl]+[C] to exit)...\" && sleep 5
#
# go to server/vhost-docroot
cd /var/www
# wipe relevant cronjobs|tabs firing
# @todo copy out the relevant contents
crontab -u ${DEV_USER} -l | grep -v \"${APP_URL_FULL}\" | crontab -u ${DEV_USER} -
# delete database site-specific tables
# @todo a2dismod for each
sudo mysql --user=${DB_USER} --password=${DB_PASS} -e \"DROP DATABASE ${DB_NAME}\" || sudo mysql --user=root --password=${DB_PASS_ROOT} -e \"show databases;\" | egrep \"${DB_NAME}\" | xargs -I \"@@\" sudo mysql --user=root --password=${DB_PASS_ROOT} -e \"DROP DATABASE @@\"
# delete database site-specific user
sudo mysql --user=root --password=${DB_PASS_ROOT} -e \"SELECT User,Host FROM mysql.user;DROP USER '${DB_USER}'@'${DB_HOST}';\"
sudo rm -f */*${APP_URL_DIRSAFE}.conf
# remove ACL permissions from app-docroot
# sudo setfacl -x u:${DEV_USER}:rwx ${APP_ABSPATH}
# sudo setfacl -x u:$USER:rwx ${APP_ABSPATH}
# remove apache site-specific configs
# @todo disable via a2dismod for each
sudo find /etc/apache2 -name \"*${APP_URL_DIRSAFE}*\" | while read filename ; do sudo rm -f \"\$filename\" ; done
sudo find ${APP_CLIENT_DIR} -name \"*${APP_URL_DIRSAFE}*\" | while read filename ; do sudo rm -f \"\$filename\" ; done
sudo rm -rf '${APP_ABSPATH}'
# remove DNSmasq site-specific configs
# sudo sed -i 's/.*${APP_URL_FULL}.*\$//g' /etc/dnsmasq.conf
# sudo sed -i 's/address=/${APP_URL_FULL}/.*\$/## address=/${APP_URL_FULL}/${MY_IP_LOCAL}/g' /etc/dnsmasq.conf
sed -i 's/[${APP_ABSPATH}].*[${APP_ABSPATH}]/## REMOVED[${APP_ABSPATH}]/g' /etc/hosts
# remove hosts entries for the site
sudo sed -i 's/${APP_URL_FULL}//g' /etc/hosts
sudo sed -i 's/\*\.${APP_URL}//g' /etc/hosts
sudo sed -i 's/${APP_URL}//g' /etc/hosts
# remove sendmail hosts entries for the site
sudo sed -i 's/${APP_URL_FULL}//g' /etc/mail/local-host-names
sudo sed -i 's/${APP_URL}//g' /etc/mail/local-host-names
#
# @todo client-specific cleanup (migration|deletion)
#
sudo systemctl restart NetworkManager.service || sudo service NetworkManager restart
sudo systemctl restart apache2.service || sudo service apache2 restart
sudo systemctl restart mysql.service || sudo service mysql restart
"
UNINSTALLERSCRIPT="${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}/${datetimenow//\:\-/}.uninstall"
printf "${ccb}Writing the site setup details to${wb} '${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}'${endp}${cb}"
sudo mkdir -p "${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}"
sudo touch "${UNINSTALLERSCRIPT}"
echo "$UNINSTALL_CONF" | sudo tee "${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}/${datetimenow//\:\-/}.uninstall" > /dev/null
sudo chmod +x "${UNINSTALLERSCRIPT}"
#######################################################################################################################################
####################################################################################### HTACCESS FILES
HTACCESS_PHPINI="
<IfModule mod_suphp.c>
suPHP_ConfigPath ${APP_ABSPATH}
</IfModule>"
HTACCESS_UPLOADS='
# FilesMatch directive to specifically deny the following types of files from being accessed
<FilesMatch "\.(php|exe|flv|cgi)$">
Deny from All
</FilesMatch>
# Prevent executable scripts like .pl, .cgi or .php scripts from being executed when requested by a browser.
# This instructs the Web Server to treat them as text files instead of executables, displayed as plain text.
AddType text/plain .pl .cgi .php
# Kill PHP Execution
# <Files ~ "\.ph(?:p[345]?|t|tml)$">
# deny from all
# </Files>
'
####################################################################################### APACHE VIRTUAL HOST VHOST CONFIGS
######################## HTTP
VHOST_HEAD="
#### http://${APP_URL_FULL}
<VirtualHost ${APACHE_VHOST_IP_LISTEN}:${APACHE_VHOST_PORT}>
# PHPINIDir ${APACHE_PHPINI}
# PHPINIDir ${APP_ABSPATH}/php.ini # For Site-specific INI
ServerAdmin ${APP_EMAIL}
ServerName ${APP_URL}
ServerAlias ${APP_URL_FULL}
DirectoryIndex index.php /index.php
DocumentRoot ${APP_ABSPATH}
"
VHOST_FOOT="
ErrorLog ${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.error.log
TransferLog ${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.xfer.log
CustomLog ${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =${APP_URL} [OR]
RewriteCond %{SERVER_NAME} =${APP_URL_FULL}
RewriteRule ^ ${APP_PROTOCOL}%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
"
######################## HTTPS SSL
VHOST_HEAD_SSL="
#### ssl ${APP_PROTOCOL}${APP_URL_FULL}
<VirtualHost ${APACHE_VHOST_IP_LISTEN}:${APACHE_VHOST_PORT_SSL}>
# PHPINIDir ${APACHE_PHPINI}
# PHPINIDir ${APP_ABSPATH}/php.ini # For Site-specific INI
ServerName ${APP_URL}
ServerAlias ${APP_URL_FULL}
Protocols h2 http/1.1
DirectoryIndex index.php /index.php
DocumentRoot ${APP_ABSPATH}
SSLEngine on
SSLCertificateFile ${APACHE_SSLDIR}/certs/${APP_URL_DIRSAFE}.pem
SSLCertificateKeyFile ${APACHE_SSLDIR}/private/${APP_URL_DIRSAFE}.key
"
VHOST_FOOT_SSL="
# Enable RewriteEngine
RewriteEngine on
RewriteOptions inherit
# # Block .svn, .git
# RewriteRule \.(svn|git)(/)?$ - [F]
# # Recommended XSS protection:
# <IfModule mod_headers.c>
# Header set X-XSS-Protection \"1; mode=block\"
# Header always append X-Frame-Options SAMEORIGIN
# </IfModule>
# Site-specific server logs:
ErrorLog ${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.error.log
TransferLog ${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.xfer.log
CustomLog ${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.access.log combined
# # Enable letsencrypt configs:
# SSLCertificateFile /etc/letsencrypt/live/${APP_URL_DIRSAFE}/fullchain.pem
# SSLCertificateKeyFile /etc/letsencrypt/live/${APP_URL_DIRSAFE}/privkey.pem
# Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
"
####################################################################################### HTACCESS - SINGLE SITE
if [ "${IS_MULTISITE}" = "false" ] ; then
HTACCESS_WP='
### BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# <Files wp-config.php>
# Order Allow,Deny
# Deny from all
# </Files>
<Files debug.log>
Order allow,deny
Deny from all
</Files>
### END WordPress
'
####################################################################################### APACHE VIRTUAL HOST VHOST - SINGLE SITE
VHOST_DIR="
######################## WP Single Site
<Directory ${APP_ABSPATH}>
# Require all granted
Options Indexes FollowSymLinks MultiViews
# # Allow local .htaccess to override Apache configuration settings
AllowOverride All
Order allow,deny
Allow from all
</Directory>
"
VHOST_DIR_SSL="
######################## WP Single Site
<Directory ${APP_ABSPATH}>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Satisfy Any
</Directory>
"
fi
####################################################################################### SUBDOMAIN
if [ "${IS_MULTISITE}" = "domain" ] ; then
# 2|domain|subdomain|cn|urd ) IS_MULTISITE="domain"
# WP_CONF_MULTI="
# /**
# * Multisite SUBDOMAIN - ${datetimenow}
# * REPLACE WITH THE COPY FROM WP ADMIN AREA SETTINGS
# */
# define('WP_ALLOW_MULTISITE', true);
# /*
# define( 'MULTISITE', true );
# define( 'SUBDOMAIN_INSTALL', true );
# \$base = '/';
# define( 'DOMAIN_CURRENT_SITE', '${APP_URL_FULL}' );
# define( 'PATH_CURRENT_SITE', '/' );
# define( 'SITE_ID_CURRENT_SITE', 1 );
# define( 'BLOG_ID_CURRENT_SITE', 1 );
# */
# "
HTACCESS_WP="
### BEGIN WordPress Multisite SUB-DOMAIN
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(${APP_CONTENT_DIR}|wp-(content|admin|includes).*) \$1 [L]
RewriteRule ^(.*\.php)$ wp/\$1 [L]
RewriteRule . index.php [L]
<Files debug.log>
Order allow,deny
Deny from all
</Files>
### If you installed WordPress MU in subfolder/subdirectory (not in root folder on your server via ftp) and
### you have problem with image library, where thumbnails and images do not show, you may need to manually add:
# RewriteRule ^([_0-9a-zA-Z-]+/)?siteN/files/(.+) ${APP_CONTENT_DIR}/blogs.dir/N/files/\$2 [L]
### END WordPress Multisite
"
####################################################################################### /ETC/HOSTS FILE CONFIGS DOMAIN NAME
HOSTSLINE=" *.${APP_URL} ${APP_URL_FULL}"
# ETC_HOST="
# ############ [${APP_ABSPATH}][MULTISITE] - first configured [${datetimenow//\:\-/}]
# 127.0.1.1 ${APP_URL} ${APP_URL_FULL} *.${APP_URL} # For local-only override
# ${MY_IP_LOCAL} ${APP_URL} ${APP_URL_FULL} *.${APP_URL} # For Global DNS override
# ::1 ${APP_URL} ${APP_URL_FULL} *.${APP_URL}
# ######### [END] [${APP_ABSPATH}]"
fi
####################################################################################### SUBDIRECTORY
if [ "${IS_MULTISITE}" = "directory" ] ; then
# WP_CONF_MULTI="
# /**
# * Multisite SUBDIRECTORY - ${datetimenow}
# * REPLACE WITH THE COPY FROM WP ADMIN AREA SETTINGS
# */
# define('WP_ALLOW_MULTISITE', true);
# /*
# define('MULTISITE', true);
# define('SUBDOMAIN_INSTALL', false);
# define('DOMAIN_CURRENT_SITE', '${APP_URL_FULL}');
# define('PATH_CURRENT_SITE', '/');
# define('SITE_ID_CURRENT_SITE', 1);
# define('BLOG_ID_CURRENT_SITE', 1);
# */
# "
HTACCESS_WP="
### BEGIN WordPress Multisite SUB-DIRECTORY
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ \$1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(${APP_CONTENT_DIR}|wp-(content|admin|includes).*) \$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ \$2 [L]
RewriteRule . index.php [L]
<Files debug.log>
Order allow,deny
Deny from all
</Files>
### If you installed WordPress MU in subfolder/subdirectory (not in root folder on your server via ftp) and
### you have problem with image library, where thumbnails and images do not show, you may need to manually add:
# RewriteRule ^([_0-9a-zA-Z-]+/)?siteN/files/(.+) ${APP_CONTENT_DIR}/blogs.dir/N/files/\$2 [L]
### END WordPress Multisite
"
fi
if [ "${IS_MULTISITE}" = "domain" ] || [ "${IS_MULTISITE}" = "directory" ] ; then
####################################################################################### APACHE VIRTUAL HOST VHOST MULTISITE
VHOST_DIR="
######################## WP MultiSite
<Directory ${APP_ABSPATH}>
# Options +Indexes +Includes +FollowSymLinks +MultiViews
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
"
VHOST_DIR_SSL="
######################## WP MultiSite
<Directory ${APP_ABSPATH}>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Satisfy Any
</Directory>
"
fi
####################################################################################### BAIL if NONE
# IS_MULTISITE="false"
# IS_MULTISITE="domain"
# IS_MULTISITE="directory"
VHOST_WWW="${VHOST_HEAD}
${VHOST_DIR}
${VHOST_FOOT}"
VHOST_WWW_SSL="${VHOST_HEAD_SSL}
${VHOST_DIR_SSL}
${VHOST_FOOT_SSL}"
####################################################################################### /ETC/HOSTS FILE CONFIGS DOMAIN NAME
if [ "${IS_MULTISITE}" = "false" ] || [ "${IS_MULTISITE}" = "directory" ] ; then HOSTSLINE=" ${APP_URL} ${APP_URL_FULL}"
# ETC_HOST="
# ############ [${APP_ABSPATH}][SINGLESITE] - first configured [${datetimenow//\:\-/}]
# 127.0.1.1 ${APP_URL} ${APP_URL_FULL} # For local-only override
# ${MY_IP_LOCAL} ${APP_URL} ${APP_URL_FULL} # For Global DNS override
# ::1 ${APP_URL} ${APP_URL_FULL}
# ######### [END] [${APP_ABSPATH}]"
fi
#######################################################################################################################################
####################################################################################### PLUGIN SOURCE
# echo " " ### Confirm a source repository to install plugins from
# ########################
# printf "${ccb}Pick a repository to source plugins from and hit ${gb}[ENTER]"${endp}
# options=("DEFAULT [${DEV_PLUGIN_REPO_DEFAULT}]" "NEW custom path" "SKIP and don't install") && PS3="[ENTER]: "
# select opt in "${options[@]}"; do
# case "$REPLY" in
#
# 1|default ) APP_PLUGIN_REPO=${DEV_PLUGIN_REPO_DEFAULT} && IS_PLUGINS='repo' ; break;;
#
# 2|*2|*\/plugin*|*\/wp* )
# APP_PLUGIN_REPO=""
# while [[ "${APP_PLUGIN_REPO}" == "" ]] || [ "${APP_PLUGIN_REPO}" = '/' ] ; do
# printf "${ccb}Please paste {${cb}[CTRL]+[SHIFT]+[V]${ccb}} full path to repo"${endp}
# read APP_PLUGIN_REPO
# if [[ "${APP_PLUGIN_REPO}" != '/' ]] && [[ "${APP_PLUGIN_REPO}" =~ $APP_DIR_regex ]] ; then
# APP_PLUGIN_REPO="${APP_PLUGIN_REPO}"
# else APP_PLUGIN_REPO="${DEV_PLUGIN_REPO_DEFAULT}"
# fi
# done
# IS_PLUGINS='repo'
# break;;
#
# 3|[sS][kK][iI][Pp] ) IS_PLUGINS='false' ; break;;
# * ) echo "Invalid option ${REPLY} ... Try another one." ; continue;;
# esac
# done
# if [ ${IS_PLUGINS} = 'repo' ] || [[ "${IS_PLUGINS}" == "repo" ]] && [[ ${IS_PLUGINS} != 'false' ]] ; then
# printf "${ccb}[PLUGINS] ${wb} : ${gb} '${}'"${endp}
# fi
#######################################################################################################################################
### INSTALL
#######################################################################################################################################
######################################################################################################################################
####################################################################################### CREATE DATABASE
printf "${ccb}Creating database '${DB_NAME}'..."${endp}
sudo mysql -h${DB_HOST} -u${DB_USER_ROOT} -p${DB_PASS_ROOT} -e"CREATE DATABASE ${DB_NAME};"
inform_return $?
printf "${ccb}Adding '${DB_USER}'@'${DB_HOST}' access..."${endp}
sudo mysql -h${DB_HOST} -u${DB_USER_ROOT} -p${DB_PASS_ROOT} -e"GRANT ALL ON ${DB_NAME}.* TO '${DB_USER}'@'${DB_HOST}' IDENTIFIED BY '${DB_PASS}'; FLUSH PRIVILEGES;"
inform_return $?
######################################################################################################################################
####################################################################################### CREATE INSTALL DIRECTORIES
# @see ${APP_PROTOCOL}cdn.speakwithageek.com/Posts/6879.jpg?dm=636654378930747936
# @see # pro/init/case # pro/init/auth
printf "${ccb}Making new app directory "${endp}
sudo mkdir -p "${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}"
sudo touch "${APP_CLIENT_DIR}/private/mynew.feature"
# sudo echo "${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}
# @see ${APP_PROTOCOL}docs.cucumber.io/gherkin/reference/" | sudo tee --append "${APP_CLIENT_DIR}/private/mynew.feature" > /dev/null
printf "${ccb}Creating Client directories... "${endp}
IFS=$'\n'
for clientdir in ${APP_CLIENT_FOLDERS} ; do
sudo mkdir -p "${APP_CLIENT_DIR}/${clientdir}/${APP_URL_DIRSAFE}"
done
inform_return $?
######################################################################################################################################
####################################################################################### BASIC PERMISSIONS FOR INSTALL
printf "${ccb}Templating access, user and group privledges..."${endp}
S_GRP="$(groups ${APACHE_USER})"
U_GRP="$(groups ${DEV_USER})"
A_GRP="${S_GRP#*:}${U_GRP#*:}"
if [[ "${A_GRP}" == "${APACH_GROUP}" ]] || [[ "${A_GRP}" == *"${APACH_GROUP}"* ]] ; then
printf "${ccb}Group '${gb}${APACH_GROUP}${ccb}' already exists..."${endp}
else printf "${gb}[ADD GROUP] ${ccb}New ${wb}'${APACH_GROUP}'${ccb} user group... "${endp}
sudo addgroup ${APACH_GROUP}
fi
if groups ${APACHE_USER} | grep "\b${A_GRP}\b" &>/dev/null ; then printf "" ; else
if [[ ${U_GRP#*:} == *"${APACH_GROUP}"* ]] ; then
printf "${ccb}↳ Already has '${gb}${DEV_USER}${ccb}' in group '${gb}${APACH_GROUP}${ccb}'..."${endp}
else sudo usermod -a -G ${APACH_GROUP} ${DEV_USER}
printf "${gb}↳ [USERMOD] ${wb}'${DEV_USER}'${ccb} added to ${wb}'${APACH_GROUP}'${ccb} user group... "${endp}
fi
if [[ ${S_GRP#*:} == *"${APACH_GROUP}"* ]] ; then
printf "${ccb}↳ Already has '${gb}${APACHE_USER}${ccb}' in group '${gb}${APACH_GROUP}${ccb}'..."${endp}
else sudo usermod -a -G ${APACH_GROUP} ${APACHE_USER}
printf "${gb}↳ [USERMOD] ${wb}'${APACHE_USER}'${ccb} added to ${wb}'${APACH_GROUP}'${ccb} user group... "${endp}
fi
fi
printf "${ccb}Setting '${gb}${APP_ABSPATH}${ccb}' ownership to '${gb}${DEV_USER}:${APACH_GROUP}${ccb}'... "${endp}
sudo chown -R ${DEV_USER}:${APACH_GROUP} "${APP_ABSPATH}"
sudo chgrp ${APACH_GROUP} "${APP_ABSPATH}"
printf "${ccb}↳ Set the group ID (setgid) to ${gb}inherit${ccb} parent directory... "${endp}
sudo find "${APP_ABSPATH}" -type d -not -path "*/.git*" -exec chmod g+s {} \;
printf "${ccb}Modifiying '${gb}${APP_ABSPATH}/${APP_CONTENT_DIR}${ccb}' directory:"${endp}
printf "${ccb}↳ Set Owner as server (${gb}${APACHE_USER}${ccb})... "${endp}
sudo chown "${APACHE_USER}" -R "${APP_ABSPATH}/${APP_CONTENT_DIR}"
printf "${ccb}↳ Set Ownership to shared group (${gb}${APACH_GROUP}${ccb})... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -exec chgrp ${APACH_GROUP} {} \;
printf "${ccb}↳ Set folders (${gb}${DIRS_APP_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type d -exec chmod ${DIRS_APP_MOD} {} \; || sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type d -exec chmod 775 {} \;
printf "${ccb}↳ Set files (${gb}${FILE_APP_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type f -exec chmod ${FILE_APP_MOD} {} \; || sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type f -exec chmod 664 {} \;
printf "${gb}SUCCESS!"${endp}
printf "${gb}Permissions have been reset to your template"${endp}
######################################################################################################################################
####################################################################################### APACHE CONFIGS
printf "${ccb}Writing Apache VirtualHost configuration files..."${endp}
sudo touch "${APACHE_VHOST_DIR}/${APP_URL_DIRSAFE}.conf"
sudo echo "${VHOST_WWW}" | sudo tee "${APACHE_VHOST_DIR}/${APP_URL_DIRSAFE}.conf" > /dev/null
sudo touch "${APACHE_VHOST_DIR}/ssl${APP_URL_DIRSAFE}.conf"
sudo echo "${VHOST_WWW_SSL}" | sudo tee "${APACHE_VHOST_DIR}/ssl${APP_URL_DIRSAFE}.conf" > /dev/null
printf "${ccb}Committing Apache log files to Client log folder..."${endp}
sudo touch "${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.error.log"
sudo touch "${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.xfer.log"
sudo touch "${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/${APP_URL_DIRSAFE}.access.log"
printf "${ccb}Setup Apache ${wb}OpenSSL${ccb} SSL key directories..."${endp}
### Create SSL Key directories if not yet already
sudo mkdir -p ${APACHE_SSLDIR}
sudo mkdir -p ${APACHE_SSLDIR}/certs
sudo mkdir -p ${APACHE_SSLDIR}/private
inform_return $?
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "${APACHE_SSLDIR}/private/${APP_URL_DIRSAFE}.key" -out "${APACHE_SSLDIR}/certs/${APP_URL_DIRSAFE}.pem" -subj "/C=AU/ST=ACT/L=Canberra/O=${APP_CLIENT}/OU=${APP_CLIENT_ALI}CyberSpace/CN=${APP_URL_FULL}/emailAddress=${APP_EMAIL}"
# SSLHonorCipherOrder On
# SSLCompression Off
printf "${ccb}Set SSL Key directories permissions..${endp}${gb}"
sudo find ${APACHE_SSLDIR} -type d -exec chmod ${SSLDIR_DIR_MOD} {} \;
sudo find ${APACHE_SSLDIR} -type f -exec chmod ${SSLDIR_FILE_MOD} {} \;
sudo chown -R root:root ${APACHE_SSLDIR}
######################################################################################################################################
####################################################################################### ETC/HOSTS FILE CONFIGS DOMAIN NAME
printf "${ccb}Writing local DNS Host management entry (${gb}/etc/hosts${ccb})..."${endp}
sudo cp /etc/hosts "/etc/hosts${datetimenow//\:\-/}.bak"
if [[ $(cat /etc/hosts | grep "127.0.0.1" ) ]] ; then sudo sed -i "s/127.0.0.1/127.0.0.1${HOSTSLINE}/g" /etc/hosts ; else sudo echo "127.0.0.1${HOSTSLINE}" >> /etc/hosts ; fi
if [[ $(cat /etc/hosts | grep "127.0.1.1" ) ]] ; then sudo sed -i "s/127.0.1.1/127.0.1.1${HOSTSLINE}/g" /etc/hosts ; else sudo echo "127.0.1.1${HOSTSLINE}" >> /etc/hosts ; fi
echo "::1${HOSTSLINE}" | sudo tee --append /etc/hosts
# sudo echo "${ETC_HOST}" | sudo tee --append /etc/hosts > /dev/null
inform_return $?
######################################################################################################################################
####################################################################################### SENDMAIL HOSTS
printf "${ccb}Adding domain to Sendmail hosts list..."${endp}
sudo echo "${APP_URL_FULL}" | sudo tee --append /etc/mail/local-host-names > /dev/null
sudo echo "${APP_URL}" | sudo tee --append /etc/mail/local-host-names > /dev/null
# sudo /etc/init.d/dns-clean restart || sudo /etc/init.d/networking force-reload
######################################################################################################################################
####################################################################################### DOWNLOAD or CLONE THE NEWEST WORDPRESS
printf "${cb}Checking version of cached download copy..."${endp}
APP_LATEST_DIR="$HOME/.cache/wordpresslatest"
WP_VERSIONFILE=$(find $(pwd) -type f -name *"version"*)
if [[ ! -d "${APP_LATEST_DIR}/wp-admin" ]] ; then mkdir -p "${APP_LATEST_DIR}" ; fi
if [[ ! $(cat ${WP_VERSIONFILE}) =~ .*?4\.9.*? ]] || [[ ! $(cat ${WP_VERSIONFILE}) =~ .*?5\.0.*? ]] ; then
echo "${gb}Success:${cb}Cached copy is latest version"${endp}
else
cd "${APP_LATEST_DIR}" && wp --path="${APP_LATEST_DIR}" core download --locale=en_AU --quiet
if [[ ! $(cat ${WP_VERSIONFILE}) =~ .*?4\.9.*? ]] || [[ ! $(cat ${WP_VERSIONFILE}) =~ .*?5\.0.*? ]] ; then
cd "${APP_LATEST_DIR}"
wget https://wordpress.org/latest.tar.gz --append-output 2>&1 /dev/null || curl -O https://wordpress.org/latest.tar.gz
mkdir -p ${APP_LATEST_DIR} && tar -zxf latest.tar.gz -C ${APP_LATEST_DIR} --strip-components 1 || \
wp --path="${APP_LATEST_DIR}" core download --locale=en_AU --quiet
touch "${APP_LATEST_DIR}/.htaccess"
# cp "${APP_LATEST_DIR}/wp-config-sample.php" "${APP_LATEST_DIR}/wp-config.php"
mkdir -p "${APP_LATEST_DIR}/wp-content/upgrade"
sudo chown -R ${APACHE_USER}:${APACH_GROUP} "${APP_LATEST_DIR}"
sudo find "${APP_LATEST_DIR}" -type d -exec chmod 755 {} \;
sudo find "${APP_LATEST_DIR}" -type f -exec chmod 644 {} \;
fi
fi
printf "${ccb}Downloading Australian Wordpress to site document root..."${endp}
cd "${APP_ABSPATH}"
wp --path="${APP_ABSPATH}" core download --locale=en_AU --quiet
if [[ ! -d "${APP_LATEST_DIR}/wp-admin" ]] ; then sudo cp -a "${APP_LATEST_DIR}" "${APP_ABSPATH}" ; fi
######################################################################################################################################
####################################################################################### WP CONFIG SETUP
printf "${ccb}Writing wp-config..."${endp}
wp --path="${APP_ABSPATH}" config create --force --dbname="${DB_NAME}" --dbuser="${DB_USER}" --dbpass="${DB_PASS}" --dbprefix="${DB_TABL_PRE}" --dbhost="${DB_HOST}" --locale="en_AU" --extra-php <<PHP #//
/**
* @see https://codex.wordpress.org/Editing_wp-config.php#External_Resources
*/
/**
* Turn on Debugging in WordPress
* @var WP_DEBUG true|false see or hide WordPress errors when in debug mode
*/
define( 'WP_DEBUG', true ); // Or false
if ( WP_DEBUG ) {
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
// Comment-out the @ini_set lines if problems with error log
@ini_set( 'log_errors', 'On' );
@ini_set( 'display_errors', 'Off' );
@ini_set( 'error_log', '${APP_CLIENT_DIR}/log/${APP_URL_FULL}/${APP_URL_DIRSAFE}.error.log' );
}
define( 'SCRIPT_DEBUG', true );
/**
* Change your site and WordPress URLs
* @var WP_HOME (string) root of your WordPress install
* @var WP_SITEURL (string) homepage url
* @var WP_CONTENT_DIR (string) make it less obvious that your site is using wordpress
* @var UPLOADS (string) as above, It will only work if located below website's Document Root folder ( ABSPATH )
*
* !!! WARNING !!!
* EXISTING SITES WITH DIFFERENT DIRECTORY STRUCTURE MAY BREAK LINKS (e.g. ${APP_CONTENT_DIR}
* There are several plugins and themes that do not follow best practices.
* They specify “wp-content” as the path and url in their code, instead of defining them dynamically.
* In such cases, the plugins and themes may not function properly.
*
* o break links to images that already attached in your posts and that are stored .
*/
define( 'WP_HOME', '${APP_PROTOCOL}${APP_URL_FULL}' );
define( 'WP_SITEURL', '${APP_PROTOCOL}${APP_URL_FULL}/' );
// define( 'WP_SITEURL', '${APP_PROTOCOL}' . \$_SERVER['HTTP_HOST'] . '/' );
// Start Potentially Breaking Changes ---->
define( 'WP_CONTENT_FOLDERNAME', '${APP_CONTENT_DIR}' );
// define( 'WP_CONTENT_DIR', ABSPATH . '${APP_CONTENT_DIR}' ) ;
define( 'WP_CONTENT_DIR', '${APP_ABSPATH}/${APP_CONTENT_DIR}' ) ;
// define( 'WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME );
define( 'WP_CONTENT_URL', '${APP_PROTOCOL}${APP_URL_FULL}/${APP_CONTENT_DIR}' );
// define( 'WP_PLUGIN_DIR', \$_SERVER['DOCUMENT_ROOT'] . '/${APP_CONTENT_DIR}/${APP_PLUGIN_DIR}' );
define( 'WP_PLUGIN_DIR', '${APP_ABSPATH}/${APP_CONTENT_DIR}/plugins' );
define( 'WP_PLUGIN_URL', '${APP_PROTOCOL}${APP_URL_FULL}/${APP_CONTENT_DIR}/${APP_PLUGIN_DIR}');
define( 'WPMU_PLUGIN_DIR', '${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_CONTENT_DIR}/${APP_MUPLUGINS_DIR}' );
define( 'WPMU_PLUGIN_URL', '${APP_PROTOCOL}${APP_URL_FULL}/${APP_CONTENT_DIR}/${APP_MUPLUGINS_DIR}' );
// @see https://wordpress.stackexchange.com/questions/47415/change-upload-directory-for-pdf-files
define( 'UPLOADS', '${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}' );
// <---- End Potentially Breaking Changes
/**
* Block external requests and list admitted hosts.
* @var AUTOMATIC_UPDATER_DISABLED (bool) Disable any auto updates firing in the background and handle these updates manually.
* @var WP_HTTP_BLOCK_EXTERNAL (bool) Prevent things from like updates, dashboard feeds, and data reporting.
* @var WP_ACCESSIBLE_HOSTS (string) Fortunately, it’s easy to whitelist (allow access) anything that is needed.
*/
define( 'AUTOMATIC_UPDATER_DISABLED', true );
// define( 'WP_HTTP_BLOCK_EXTERNAL', true );
// define( 'WP_ACCESSIBLE_HOSTS', '${APP_PROTOCOL}repo.${APP_CLIENT_ALI}' );
/**
* @var FORCE_SSL_ADMIN (bool) secure logins and the admin area so that both passwords and cookies are never sent in the clear.
* @var DISALLOW_FILE_EDIT (bool) disable the plugin or theme editor to prevent overzealous users from being able to edit sensitive files
* @var FS_METHOD (direct) you could even disable FTP access entirely, including file editing in the WordPress dashboard.
* @var FS_CHMOD_FILE (0644) allow override of default server file permissions
* @var FS_CHMOD_DIR (0775) @see ${APP_PROTOCOL}codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions
*/
define( 'FORCE_SSL_LOGIN', true );
define( 'FORCE_SSL_ADMIN', true );
// define( 'DISALLOW_FILE_EDIT', true );
define( 'FS_METHOD', 'direct' );
define( 'FS_CHMOD_FILE', 0${FILE_APP_MOD} );
define( 'FS_CHMOD_DIR', 0${DIRS_APP_MOD} );
/**
* @var DB_CHARSET|DB_COLLATE (mixed) ensure stabilised DB settings
* !!WARNING!! For 'WP_ALLOW_REPAIR' Just use WP-CLI db repair|optimize commands instead, else:
* @var WP_ALLOW_REPAIR (bool) Set to true to have WP repairs its database tables, refresh page, set back to false.
*/
// define('DB_CHARSET', 'utf8');
// define('DB_COLLATE', '');
// define('WP_ALLOW_REPAIR', false);
/**
* @var WP_CRON_LOCK_TIMEOUT int ensure a cron process cannot run more than once every (int) seconds.
* @var DISABLE_WP_CRON int Disable the WP Cron and use system cron
* @example ${APP_PROTOCOL}easyengine.io/tutorials/wordpress/wp-cron-crontab -u ${DEV_USER}/
* NEWJOB="* 18 * * * wp --path=\${APP_ABSPATH} db export --porcelain=DB-6pm.sql >/dev/null 2>&1"
* (crontab -l ; echo "\${NEWJOB}") | crontab -
*/
define( 'DISABLE_WP_CRON', true );
define( 'WP_CRON_LOCK_TIMEOUT', 60 );
/**
* @var AUTOSAVE_INTERVAL int change how often (in seconds) WordPress stores an autosave as a revision
* @var WP_POST_REVISIONS int|bool limit the number of revisions per post. ('false'=disable the post revisions)
* @var IMAGE_EDIT_OVERWRITE bool Only one set of image edits ever created; when you restore the original, edits are removed from server.
* @var EMPTY_TRASH_DAYS int When a user sends a post to trash, it is still stored on your website for next (int) days as trash
*/
define( 'AUTOSAVE_INTERVAL', 180 );
define( 'WP_POST_REVISIONS', 42 );
// define( 'IMAGE_EDIT_OVERWRITE', true );
define( 'EMPTY_TRASH_DAYS', 365 );
define( 'WPLANG', 'en_AU' );
// define( 'CUSTOM_USER_TABLE', '${DB_TABL_PRE}my_users' );
// define( 'CUSTOM_USER_META_TABLE', '${DB_TABL_PRE}my_usermeta' );
${WP_CONF_MULTI}
define( 'NOBLOGREDIRECT', '${APP_PROTOCOL}${APP_URL_FULL}' );
PHP
#// https://www.digitalocean.com/community/tutorials/how-to-set-up-a-remote-database-to-optimize-site-performance-with-mysql-on-ubuntu-16-04
sudo chmod ${CONF_MOD} ${APP_ABSPATH}/wp-config.php > /dev/null
inform_return $?
######################################################################################################################################
####################################################################################### MOVE CORE FOLDERS STRUCTURE
printf "${ccb}Moving '${gb}/wp-content${ccb}' to '${gb}/${APP_CONTENT_DIR}${ccb}'... "${endp}
sudo mv "${APP_ABSPATH}/wp-content/"* "${APP_ABSPATH}/${APP_CONTENT_DIR}"
sudo rm -rf "${APP_ABSPATH}/wp-content"
sudo mkdir -p ${APP_ABSPATH}/${APP_CONTENT_DIR}/upgrade
######################################################## KEEP PERMISSIONS|ACCESS OKAY
printf "${ccb}Setting '${gb}${APP_ABSPATH}${ccb}' ownership to '${gb}${DEV_USER}:${APACH_GROUP}${ccb}'... "${endp}
sudo chown -R ${DEV_USER}:${APACH_GROUP} "${APP_ABSPATH}"
sudo chgrp ${APACH_GROUP} "${APP_ABSPATH}"
printf "${ccb}↳ Set the group ID (setgid) to ${gb}inherit${ccb} parent directory... "${endp}
sudo find "${APP_ABSPATH}" -type d -not -path "*/.git*" -exec chmod g+s {} \;
printf "${ccb}Modifiying '${gb}${APP_ABSPATH}/${APP_CONTENT_DIR}${ccb}' directory:"${endp}
printf "${ccb}↳ Set Owner as server (${gb}${APACHE_USER}${ccb})... "${endp}
sudo chown "${APACHE_USER}" -R "${APP_ABSPATH}/${APP_CONTENT_DIR}"
printf "${ccb}↳ Set Ownership to shared group (${gb}${APACH_GROUP}${ccb})... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -exec chgrp ${APACH_GROUP} {} \;
printf "${ccb}↳ Set folders (${gb}${DIRS_APP_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type d -exec chmod ${DIRS_APP_MOD} {} \; || sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type d -exec chmod 775 {} \;
printf "${ccb}↳ Set files (${gb}${FILE_APP_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type f -exec chmod ${FILE_APP_MOD} {} \; || sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type f -exec chmod 664 {} \;
printf "${gb}Success:${wb} Permissions have been reset to template"${endp}
######################################################################################################################################
####################################################################################### INSTALLER WIZARD
printf "${ccb}Installing the configured WordPress site..."${endp}
printf "${cb}This can take a while sometimes..."${endp}
sudo chown ${DEV_USER}:${DEV_USER} -R ${APP_ABSPATH}
if [ "${IS_MULTISITE}" = "false" ] ; then wp --path="${APP_ABSPATH}" core install --url="${APP_URL_FULL}" --title="${APP_TITLE}" --admin_user="${APP_ADMIN}" --admin_password="${APP_PASSWORD}" --admin_email="${APP_EMAIL}" ; fi
if [ "${IS_MULTISITE}" = "directory" ] ; then wp --path="${APP_ABSPATH}" core multisite-install --url="${APP_URL_FULL}" --title="${APP_TITLE}" --admin_user="${APP_ADMIN}" --admin_password="${APP_PASSWORD}" --admin_email="${APP_EMAIL}" ; fi
if [ "${IS_MULTISITE}" = "domain" ] ; then wp --path="${APP_ABSPATH}" core multisite-install --url="${APP_URL_FULL}" --subdomains --title="${APP_TITLE}" --admin_user="${APP_ADMIN}" --admin_password="${APP_PASSWORD}" --admin_email="${APP_EMAIL}" ; fi
######################################################################################################################################
####################################################################################### EMPTY & FLUSH
printf "${ccb}Clean up a bit..${endp}${gb}"
wp --path="${APP_ABSPATH}" site empty --yes
wp --path="${APP_ABSPATH}" cache flush
wp --path="${APP_ABSPATH}" transient delete --all
wp --path="${APP_ABSPATH}" rewrite structure '/%postname%/' --hard
######################################################################################################################################
####################################################################################### UPDATE SITE OPTIONS
printf "${ccb}Updating site options..."${endp}
wp --path="${APP_ABSPATH}" option update disable_wp_cron 'true'
wp --path="${APP_ABSPATH}" option update blogdescription "${APP_CLIENT} ${APP_DOMAIN_CSD^^} App"
wp --path="${APP_ABSPATH}" option update upload_path "${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}"
wp --path="${APP_ABSPATH}" option update upload_url_path "${APP_URL_FULL}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}/"
wp --path="${APP_ABSPATH}" option update uploads_use_yearmonth_folders '0'
wp --path="${APP_ABSPATH}" option update blog_public '0'
wp --path="${APP_ABSPATH}" option update default_ping_status 'closed'
wp --path="${APP_ABSPATH}" option update default_comment_status 'closed'
wp --path="${APP_ABSPATH}" option update image_default_link_type 'none'
wp --path="${APP_ABSPATH}" option update permalink_structure '/%postname%/'
wp --path="${APP_ABSPATH}" option update timezone_string Australia/Sydney
######################################################################################################################################
####################################################################################### HTACCESS
printf "${ccb}Set HTACCESS rules for 'root' and 'upload' directories..."${endp}
sudo touch "${APP_ABSPATH}/.htaccess" && echo "${HTACCESS_WP}" | sudo tee "${APP_ABSPATH}/.htaccess" > /dev/null
echo "${HTACCESS_PHPINI}" | sudo tee --append "${APP_ABSPATH}/.htaccess" > /dev/null
sudo cp -a "${APACHE_PHPINI}" "${APP_ABSPATH}/php.ini"
sudo chmod ${HTAC_MOD} "${APP_ABSPATH}/.htaccess"
sudo chmod ${CONF_MOD} "${APP_ABSPATH}/php.ini"
sudo touch "${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}/.htaccess" && \
echo "${HTACCESS_UPLOADS}" | sudo tee --append "${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}/.htaccess" > /dev/null
sudo chmod ${HTAC_MOD} "${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}/.htaccess"
# sudo touch ${APP_ABSPATH}/.htaccess
# sudo echo '<files wp-config.php>
# order allow,deny
# deny from all
# </files>' | sudo cat - ${APP_ABSPATH}/.htaccess > temp && sudo mv temp ${APP_ABSPATH}/.htaccess
######################################################################################################################################
####################################################################################### QUICK UPDATE CHECK
wp --path="${APP_ABSPATH}" core update --locale=en_AU
######################################################################################################################################
####################################################################################### ENABLE APACHE MODS & CONFIGS
printf "${ccb}Enabling Server 'ssl${APP_URL_DIRSAFE}.conf'..."${endp}
sudo a2ensite -q "${APP_URL_DIRSAFE}.conf"
inform_return $?
sudo a2ensite -q "ssl${APP_URL_DIRSAFE}.conf"
inform_return $?
printf "${ccb}Enabling Server Modules..."${endp}
sudo a2enmod -q rewrite
sudo a2enmod -q ssl
printf "${ccb}Reloading Network, Server, and Database Services..."${endp}
sudo systemctl restart NetworkManager.service
sudo systemctl restart apache2.service || systemctl status apache2.service" and "journalctl -xe
sudo systemctl restart mysql.service
# sudo /etc/init.d/dns-clean restart || sudo /etc/init.d/networking force-reload
######################################################################################################################################
####################################################################################### WP PLUGINS & THEMES SETUP
wp --path="${APP_ABSPATH}" plugin uninstall akismet hello
# wp --path="${APP_ABSPATH}" plugin install user-switching allow-multiple-accounts members wps-hide-login rest-api-oauth1 bnfw --activate
# wp --path="${APP_ABSPATH}" plugin install debug-bar debug-bar-cron query-monitor wp-inspect redirection wp-crontrol rocket-lazy-load code-snippets
# # wp --path="${APP_ABSPATH}" plugin install disable-admin-notices wp-sitemap-page
# wp --path="${APP_ABSPATH}" plugin install elementor improved-save-button parent-category-toggler admin-collapse-subpages --activate
#
# # if [ ${IS_PLUGINS} = 'repo' ] || [[ "${IS_PLUGINS}" == "repo" ]] && [[ ${IS_PLUGINS} != 'false' ]] ; then
# # printf "${ccb}Plugin source: ${gb}'${APP_PLUGIN_REPO}'"${endp}
# # if [[ ! "${WP_PLUGIN_REPO}" == "${WP_PLUGIN_REPO_DEFAULT}" ]] || [ ! $WP_PLUGIN_REPO = $WP_PLUGIN_REPO_DEFAULT ] ; then
# # REPO_TO_CLEAR=$WP_PLUGIN_REPO
# # printf "${ccb}Zipping Plugins for installation... "${endp}
# # IFS=$'\n'
# # for p in $(find "${WP_PLUGIN_REPO}" -mindepth 1 -maxdepth 1 -type d ) ; do
# # zip -rq "${p%/}.zip" "$p" || sudo zip -r "${p%/}.zip" "$p"
# # wp plugin install "${p%/}.zip" --path="${APP_ABSPATH}"
# # sudo rm -f "${p%/}.zip"
# # done
# # inform_return $?
# # cd ${APP_ABSPATH}
# # fi
#
# if [ "$IS_MULTISITE" = "true' ] ; then
# wp --path="${APP_ABSPATH}" plugin install multisite-cloner multisite-post-duplicator multisite-clone-duplicator dropdown-multisite-selector multisite-toolbar-additions wp-multisite-user-sync multisite-enhancements wp-security-audit-log multisite-directory multisite-plugin-manager network-shared-media multisite-robotstxt-manager --activate
# else
# wp --path="${APP_ABSPATH}" plugin install plugin-organizer
# fi
#
# wp plugin activate --all
# wp plugin install "${APP_PLUGIN_REPO}/mainwp.zip" --path="${APP_ABSPATH}" || wp plugin install mainwp --path="${APP_ABSPATH}"
# wp plugin install "${APP_PLUGIN_REPO}/mainwp-child.zip" --path="${APP_ABSPATH}" || wp plugin install mainwp-child --path="${APP_ABSPATH}"
# wp plugin install "${APP_PLUGIN_REPO}/user-role-editor-pro.zip" --path="${APP_ABSPATH}"
#
####################################################################################### THEMES
wp --path="${APP_ABSPATH}" theme delete twentysixteen twentyfifteen
wp --path="${APP_ABSPATH}" theme install generatepress
wp --path="${APP_ABSPATH}" scaffold child-theme sample-theme --parent_theme=generatepress
# wp theme install "/home/$USER/wp/themes/themename_child.zip" --activate --path="${APP_ABSPATH}"
######################################################################################################################################
####################################################################################### CRONJOB CRONTAB
printf "${ccb}Writing Crontab..."${endp}
# wp option update disable_wp_cron 'true'
# @todo change the absolute paths to things like WP-CLI so that migration to other hosts is easier.
CTABB="
*/5 * * * * cd \"${APP_ABSPATH}\" && ${WPCLI} --path=\"${APP_ABSPATH}\"cron event run --due-now ${SHHH}
*/10 * * * * wget http://${APP_URL_FULL}/wp-cron.php ${SHHH}
* */18 * * * cd ${APP_BACKUP_DIR} && ${WPCLI} --path=\"${APP_ABSPATH}\" db export --porcelain=\"DB18hrs.sql\" ${SHHH}
* */6 * * * cd ${APP_BACKUP_DIR} && ${WPCLI} --path=\"${APP_ABSPATH}\" --quiet db export --porcelain=\"DB6hrs.sql\" ${SHHH}
* * 28 * * cd ${APP_BACKUP_DIR} && ${WPCLI} --path=\"${APP_ABSPATH}\" --quiet db export ${SHHH}
@monthly cd ${APP_BACKUP_DIR} && BAKSQL_DIR=\"${APP_BACKUP_DIR}/\$(date +\\%Y\\%m)\" ; mkdir -p \$BAKSQL_DIR ; cp ${APP_BACKUP_DIR}/*.sql \$BAKSQL_DIR || sudo cp ${APP_ABSPATH}/*.sql \$BAKSQL_DIR"
# * * * * * /path/to/command arg1 arg2
# | | | | |
# | | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
# | | | ------- Month (1 - 12)
# | | --------- Day of month (1 - 31)
# | ----------- Hour (0 - 23)
# ------------- Minute (0 - 59)
# (*) specifies all possible values for a field.
# (,) specifies a list of values, for example: “1,5,10,15,20, 25”.
# (-) specifies a range of values, for example: “5-15” days , which is equivalent to typing “5,6,7,8,9,….,13,14,15” using the comma operator.
# (/) specifies a step value, for example: “0-23/” can be used in the hours field to specify command execution every other hour.
# Steps are also permitted after an asterisk, so if you want to say every two hours, just use */2.
(crontab -l && echo "${CTABB}") | crontab -
######################################################################################################################################
####################################################################################### GITIGNORE
printf "${ccb}Setting GitIgnore rules..."${endp}
cat > .gitignore <<EOF
### WordPress
*.log
**/log
log/**
${APP_URL_DIRSAFE}.error.log
${APP_URL_DIRSAFE}.xfer.log
${APP_URL_DIRSAFE}.access.log
# ignore everything in the root except the "${APP_CONTENT_DIR}" directory.
/${APP_ABSPATH}/*
!/${APP_ABSPATH}/${APP_CONTENT_DIR}/
# ignore everything in the "${APP_CONTENT_DIR}" directory, except:
# "mu-plugins" directory
# "plugins" directory
# "themes" directory
${APP_ABSPATH}/${APP_CONTENT_DIR}/*
!${APP_ABSPATH}/${APP_CONTENT_DIR}/mu-plugins/
!${APP_ABSPATH}/${APP_CONTENT_DIR}/plugins/
!${APP_ABSPATH}/${APP_CONTENT_DIR}/themes/
!${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}/
${APP_ABSPATH}/${APP_CONTENT_DIR}/${APP_UPLOAD_DIR}/wp-migrate-db/
/.htaccess
/license.txt
/readme.html
/sitemap.xml
/sitemap.xml.gz
# ignore all files that start with ~
~*
# ignore OS generated files
ehthumbs.db
Thumbs.db
.DS_Store
# ignore Editor files
*.sublime-project
*.sublime-workspace
*.komodoproject
# ignore sass-cache
.sass-cache
# ignore log files and databases
*.log
*.sql
*.sqlite
# ignore compiled files
*.com
*.class
*.dll
*.exe
*.o
*.so
# ignore packaged files
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# ignore node/grunt and bower dependency directories
node_modules/
bower_components/
EOF
#######################################################################################################################################
### Export the configuration details
SETTINGS_CONTENT="#!/bin/bash
###############################################################
## --- ORIGINAL INSTALL CONFIGURATION ---------------------- ##
###############################################################
## Site URL
APP_DOMAIN_CSD=\"${APP_DOMAIN_CSD}\"
APP_DOMAIN_URD=\"${APP_DOMAIN_URD}\"
APP_DOMAIN_TLD=\"${APP_DOMAIN_TLD}\"
APP_URL=\"${APP_URL}\"
APP_URL_FULL=\"${APP_URL_FULL}\"
## Site Title
APP_TITLE=\"${APP_TITLE}\"
## Site Admin User
APP_ADMIN=\"${APP_ADMIN}\"
## Site Admin Pass
APP_PASSWORD=\"${APP_PASSWORD}\"
## Site Admin Email
APP_EMAIL=\"${APP_EMAIL}\"
## Client
APP_CLIENT=\"${APP_CLIENT}\"
## Installation Path
APP_ABSPATH=\"${APP_CLIENT_DIR}/${APP_URL_FULL}\"
## Site Logs
APP_LOGS=\"${APP_CLIENT_DIR}/log/${APP_URL_FULL}\"
## Error Log
APP_ERROR_LOG=\"${APP_ERROR_LOG}\"
## Access Log
APP_ACCESS_LOG=\"${APP_ACCESS_LOG}\"
## Transfer Log
APP_XFER_LOG=\"${APP_XFER_LOG}\"
## Database User
DB_USER=\"${DB_USER}\"
## Database Pass
DB_PASS=\"${DB_PASS}\"
## Database Host
DB_HOST=\"${DB_HOST}\"
## Database Name
DB_NAME=\"${DB_NAME}\"
## Database Table Prefix
DB_TABL_PRE=\"${DB_TABL_PRE}\"
## Database Backups
APP_BACKUP_DIR=\"${APP_BACKUP_DIR}\"
# AUTOMYSQLBAK_APP_SH=\"/etc/automysqlbackup/${APP_URL_FULL//$inval/}_backup_sql.sh\"
## sudo automysqlbackup ${AUTOMYSQLBAK_APP_SH}
## Setup by
DEV_USER=\"${DEV_USER}\"
## Server Group
APACH_GROUP=\"${APACH_GROUP_APP}\"
## Server User
APACHE_USER=\"${APACHE_USER}\"
## Virtual Host
APP_VHOSTS=\"/etc/apache2/sites-available/${APP_URL_DIRSAFE}.conf\"
APP_VHOSTS_SSL=\"ssl${APP_URL_DIRSAFE}.conf\"
## Directory Root
APACHE_WROOT_DIR=\"${APACHE_WROOT_DIR}\"
## Virtual Host DirRoot
APACHE_VHOST_DIR=\"${APACHE_VHOST_DIR}\"
## Apache SSL Keys Dir
APACHE_SSLDIR=\"${APACHE_SSLDIR}\"
## Directory Root
APP_ABSPATH=\"${APP_CLIENT_DIR}/${APP_URL_FULL}\"
## IP of Local Install
MY_IP_LOCAL=\"${MY_IP_LOCAL}\"
##
WILD='*'
"
INSTALLERVARSCRIPT="${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}/${datetimenow//\:\-/}.installer"
printf "${ccb}Writing the site setup details to${wb} '${INSTALLERVARSCRIPT}'${endp}${cb}"
sudo mkdir -p "${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}"
sudo touch ${APP_CLIENT_DIR}/scripts/${APP_URL_DIRSAFE}/${datetimenow//\:\-/}.installer
echo "$SETTINGS_CONTENT" | sudo tee --append "${INSTALLERVARSCRIPT}" > /dev/null
#######################################################################################################################################
### Setup Git
printf "${ccb}Initialising Git version control..${endp}${gb}"
cd ${APP_ABSPATH}
if [[ "${APP_ABSPATH}" == *"$(pwd)"* ]] ; then
# sudo mkdir -p ${APP_ABSPATH}/.git
# chown $USER.$USER -R ${APP_ABSPATH}/.git
# chown $USER.$USER -R ${APP_ABSPATH}.config
# chown $USER.$USER -R ${APP_ABSPATH}/.gitconfig
git flow init -df >/dev/null 2>&1
git rm -r --cached . >/dev/null 2>&1
git add --all && git commit -q -m "Wordpress Init & Ignore. Basic Setup" >/dev/null 2>&1
fi
inform_return $?
#######################################################################################################################################
################################################
S_GRP="$(groups ${APACHE_USER})"
U_GRP="$(groups ${DEV_USER})"
A_GRP="${S_GRP#*:}${U_GRP#*:}"
if [[ "${A_GRP}" == "${APACH_GROUP}" ]] || [[ "${A_GRP}" == *"${APACH_GROUP}"* ]] ; then
printf "${ccb}Group '${gb}${APACH_GROUP}${ccb}' already exists..."${endp}
else printf "${gb}[ADD GROUP] ${ccb}New ${wb}'${APACH_GROUP}'${ccb} user group... "${endp}
sudo addgroup ${APACH_GROUP}
fi
if groups ${APACHE_USER} | grep "\b${A_GRP}\b" &>/dev/null ; then printf "" ; else
if [[ ${U_GRP#*:} == *"${APACH_GROUP}"* ]] ; then
printf "${ccb}↳ Already has '${gb}${DEV_USER}${ccb}' in group '${gb}${APACH_GROUP}${ccb}'..."${endp}
else sudo usermod -a -G ${APACH_GROUP} ${DEV_USER}
printf "${gb}↳ [USERMOD] ${wb}'${DEV_USER}'${ccb} added to ${wb}'${APACH_GROUP}'${ccb} user group... "${endp}
fi
if [[ ${S_GRP#*:} == *"${APACH_GROUP}"* ]] ; then
printf "${ccb}↳ Already has '${gb}${APACHE_USER}${ccb}' in group '${gb}${APACH_GROUP}${ccb}'..."${endp}
else sudo usermod -a -G ${APACH_GROUP} ${APACHE_USER}
printf "${gb}↳ [USERMOD] ${wb}'${APACHE_USER}'${ccb} added to ${wb}'${APACH_GROUP}'${ccb} user group... "${endp}
fi
fi
echo ""
printf "${wb}The following processes can take a while,"${endp}
printf "${wb}please be patient and do not kill the process..."${endp}
printf "${rb}OK... ${wb}Moving to '${APP_ABSPATH}' now..."${endp}
sudo echo ""
printf "${ccb}Setting directory ownership to '${gb}${DEV_USER}:${APACH_GROUP}${ccb}'... "${endp}
sudo chown -R ${DEV_USER}:${APACH_GROUP} "${APP_ABSPATH}"
sudo chgrp ${APACH_GROUP} "${APP_ABSPATH}"
printf "${ccb}↳ Set the group ID (setgid) to ${gb}inherit${ccb} parent directory... "${endp}
sudo find "${APP_ABSPATH}" -type d -not -path "*/.git*" -exec chmod g+s {} \;
printf "${ccb}↳ Set folders (${gb}${DIRS_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}" -type d -not -path "*/.git*" -exec chmod ${DIRS_MOD} {} \; || sudo find "${APP_ABSPATH}" -type d -exec chmod 755 {} \;
printf "${ccb}↳ Set the files (${gb}${FILE_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}" -type f -not -path "*/.git*" -exec chmod ${FILE_MOD} {} \; || sudo find "${APP_ABSPATH}" -type f -exec chmod 644 {} \;
printf "${ccb}Modifiying '${gb}${APP_ABSPATH}/${APP_CONTENT_DIR}${ccb}' directory:"${endp}
printf "${ccb}↳ Set Owner as server (${gb}${APACHE_USER}${ccb})... "${endp}
sudo chown "${APACHE_USER}" -R "${APP_ABSPATH}/${APP_CONTENT_DIR}"
printf "${ccb}↳ Set Ownership to shared group (${gb}${APACH_GROUP}${ccb})... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -exec chgrp ${APACH_GROUP} {} \;
printf "${ccb}↳ Set folders (${gb}${DIRS_APP_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type d -exec chmod ${DIRS_APP_MOD} {} \; || sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type d -exec chmod 775 {} \;
printf "${ccb}↳ Set files (${gb}${FILE_APP_MOD}${ccb}) permissions... "${endp}
sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type f -exec chmod ${FILE_APP_MOD} {} \; || sudo find "${APP_ABSPATH}/${APP_CONTENT_DIR}" -type f -exec chmod 664 {} \;
printf "${ccb}↳ Set ACL rules for (${gb}${DEV_USER}${ccb}) permissions... "${endp}
sudo setfacl -R -m u:${DEV_USER}:rwx ${APP_ABSPATH}
printf "${ccb}Allowing group '${gb}${APACH_GROUP}${ccb}' to manage '${gb}wp-config.php${ccb}'..."${endp}
sudo chgrp ${APACH_GROUP} "${APP_ABSPATH}/wp-config.php"
printf "${ccb}↳ Prevent world access (${gb}${CONF_MOD}${ccb})..."${endp}
sudo chmod ${CONF_MOD} "${APP_ABSPATH}/wp-config.php" || sudo chmod 440 "${APP_ABSPATH}/wp-config.php"
printf "${ccb}Ensuring '${gb}.htaccess${ccb}' files are protected (${gb}${HTAC_MOD}${ccb})..."${endp}
sudo find "${APP_ABSPATH}" -name ".htaccess" -exec chmod ${HTAC_MOD} {} \;
printf "${gb}SUCCESS!"${endp}
printf "${gb}Permissions have been reset to your template"${endp}
printf ""${endp}
####################################################################################### RELOAD SERVICES AND GO! (OR NOT)
printf "${ccb}Reloading Network, Server, and Database Services..."${endp}
sudo /etc/init.d/networking restart
sudo service hostname restart
sudo systemctl restart NetworkManager.service || sudo service network-manager restart || sudo /etc/init.d/dnsmasq restart
sudo systemctl restart apache2.service || sudo service apache2 restart
sudo systemctl restart mysql.service || sudo service mysql restart
inform_return $?
#######################################################################################################################################
### Print success message
printf "
${gb}----------------------------------------------------------------${endp}
${gb}WordPress installation complete!${endp}
${gb}----------------------------------------------------------------${endp}
${gb}Go to: ${APP_URL_FULL}${endp}
${gb}----------------------------------------------------------------${endp}
${gb}USERNAME = ${wb}${APP_ADMIN} (${APP_EMAIL})
${gb}PASSWORD = ${wb}${APP_PASSWORD}
${gb}----------------------------------------------------------------${endp}
${gb}----------------------------------------------------------------${endp}
${gb}LOGS = ${wb}${APP_CLIENT_DIR}/log/${APP_URL_DIRSAFE}/*.log
${gb}APP FOLDER = ${wb}${APP_ABSPATH}
${gb}CLIENT DIR = ${wb}${APP_CLIENT_DIR}
${gb}----------------------------------------------------------------${endp}
${gb}INSTALL VARS = ${wb}${INSTALLERVARSCRIPT}
${gb}UNINSTALLER = ${wb}${UNINSTALLERSCRIPT}
${gb}----------------------------------------------------------------${endp}
"
########################
# printf "${wb}Launching in Web & Git browsers..."
# cd ${APP_CLIENT_DIR}/scripts/features/${APP_URL_FULL} && { sudo curl -O ${APP_PROTOCOL}raw.githubusercontent.com/hbons/git-cheat-sheet/master/preview.png ; cd -; }
# Launch site in browsers
# nohup firefox ${APP_URL} &
# nohup gitkraken -p ${APP_ABSPATH} &
# nohup subl --add --new-window ${APP_ABSPATH} &
# wp wp-sec all --lowercase --path="${APP_ABSPATH}"
echo ""
#!/bin/bash
#
## wp-prov
# This script establishes the minimum system requirements to run your app installation
# Typically, this is run on new systems with no existing software configured.
# If option is selected, it will also update pre-existing software
################################################################################################################################################
######################## INSTALL DEPENDENCIES
printf "${rb}Run Installation Environment dependency check?${endp}"
printf "${rb}Choose an Install option (e.g. ${cb}[1]${rb})${endp}"
options=("CHECK & REFRESH dependencies" "UPDATE & INSTALL dependencies" "IGNORE and run install") && PS3="[ENTER]:"
select opt in "${options[@]}" ; do
case "$REPLY" in
1|[cC]|[cC][hH]|[cC][hH][eE][cC][kK] ) DEPENDS='check' ; break;;
2|Y|y|[yY][eE][Ss] ) DEPENDS='update' ; break;;
*|3|[nN]|[nN][oO] ) DEPENDS='bail' ; break;;
esac
done
################################################################################################################################################
#### APP DEPENDENCIES
# if [[ $DEPENDS = 'bail' ]] ; then echo "" ; fi
if [[ $DEPENDS = 'check' ]] ; then
printf "${cb}Restarting core services, errors should print verbose...${endp}"
printf "${gb}hosts...${endp}"
if [[ ! -f /etc/hosts ]] || [[ ! $(cat /etc/hosts | grep "localhost") ]] ; then echo "ERROR! Hosts file not found, or missing 'localhost'" ; fi
printf "${gb}networking...${endp}"
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start
# printf "${gb}dnsmasq...${endp}"
# sudo service dnsmasq restart
# > /dev/null
# printf "${cb}" && sudo /etc/init.d/dns-clean restart || sudo /etc/init.d/networking force-reload
printf "${gb}systemd-resolved...${endp}"
sudo service systemd-resolved restart
printf "${gb}NetworkManager...${endp}"
sudo systemctl restart NetworkManager.service
# || sudoservice network-manager restart || sudo /etc/init.d/dnsmasq restart > /dev/null
printf "${gb}apache2...${endp}"
sudo systemctl restart apache2.service || sudo service apache2 restart
printf "${gb}mysql...${endp}"
sudo systemctl restart mysql.service || sudo service mysql restart
# printf "${cb}" && sudo /etc/init.d/dns-clean restart || sudo /etc/init.d/networking force-reload
printf "${gb}syslog...${endp}"
sudo service rsyslog restart
else
#######################################################################################################################################
####################################################################################### USER DEFAULTS
# DEV_USERS=$(ps aux | grep apache | awk '{print $1;}' | uniq)
APACHE_USER="www-data"
DEV_USER="$USER"
UPATH=$(echo $PATH | grep -m 1 -o "/usr[a-z/]*bin[a-z/]*" | head -n 1) || UPATH="/usr/local/bin"
APACH_GROUP_APP="${APACHE_USER}-${DEV_USER}"
APACH_GROUP=${APACH_GROUP_APP}
APP_CLIENT_DEFAULT="zzztmp" #url-safe, dir-safe
GMAIL_ID="myemail" # installer assumes '[email protected]'
DB_HOST_DEFAULT="localhost"
DB_USER_ROOT="root"
DB_PASS_ROOT="root"
#######################################################################################################################################
####################################################################################### PERMISSIONS TEMPLATE
# +------- -u: UserOwner
# |+----- -g: Group
# ||+--- -w: World
# |||
# 777
DIRS_MOD="755"
FILE_MOD="664"
CONF_MOD="640"
DIRS_APP_MOD="775"
FILE_APP_MOD="664"
HTAC_MOD="660"
#######################################################################################################################################
####################################################################################### APACHE SERVER DEFAULT
MY_IP_LOCAL="127.0.0.1"
# inet='inet' && MY_IP_LOCAL_ADD=$(ifconfig | sed -En "s/${MY_IP_LOCAL//\./\\\.}//;s/.*${inet} (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p")
APACHE_PHPINI="$(find /etc/php -type f -name "php.ini" | grep -m 1 "apache2")"
APACHE_WROOT_DIR="/var/www" # Apache web document root (e.g. xampp/htdocs)
APACHE_VHOST_PORT="80"
APACHE_VHOST_PORT_SSL="443"
APACHE_VHOST_IP_LISTEN="*"
APACHE_VHOST_DIR="/etc/apache2/sites-available" # and VirtualHosts
APACHE_SSLDIR="/etc/apache2/ssl" # /certs (pem), /private (key)
SSLDIR_DIR_MOD="700" # Recommended 700; 500 manual update required at renewal time
SSLDIR_FILE_MOD="600" # Recommended 600; 400 if you don't mind having to fiddle with them at renewal time
APACHE_PHP_CONF="$(find /etc/php -type f -name "php.ini" | grep "apache2")"
APACHE_PHP_MOD_CURRENT="$(ls -la /etc/apache2/*-enabled | awk -F"/" '{print $NF}')"
# APACHE_PHP_MOD_CURRENT=$(php --ini | grep -E "(?php/).*?") # stuck reading phpCLI!? # echo $APACHE_PHP_MOD_CURRENT
fi
#######################################################################################################################################
if [[ $DEPENDS = 'update' ]] ; then
#### List LAMP Dependencies [Ubuntu 18.04]
## KEEP THIS LIST IN ORDER OF INSTALL
dependency_list="composer
net-tools
git
git-flow
apache2
mariadb-server
mariadb-client
php7.2
phpmyadmin
wp-cli
sendmail
#php-xdebug
#dnsmasq
#automysqlbackup"
APACHE_http2mod="# HTTP/2 support is not included in Ubuntu 16.04, neither with nginx nor with Apache
# because this feature is considered as experimental by the Apache httpd upstream project,
# e.g. using the a2enmod command => ERROR: Module http2 does not exist!
Protocols h2 http/1.1
# Include module configuration:"
APACHE_DIRMOD="<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>"
declare -A DNSmSERV
DNSmSERV=(
[expand-hosts]=" \\n\#"
[log-queries]=" \\n\#"
[bind-interfaces]=" \\n\#"
[resolv-file]="=\\/etc\\/dnsmasq\\-resolv\\.conf"
[listen-address]="=${MY_IP_LOCAL/\./\\\.}"
)
APACHE_PHP_MOD="php7.2
libapache2-mod-php7.2
php7.2-common
php-pear
php7.2-dev
php7.2-mbstring
php7.2-curl
php7.2-soap
php7.2-gd
php7.2-xml
php7.2-xmlrpc
php7.2-intl
php7.2-mysql
php7.2-cli
php7.2-zip
php7.2-ldap
php7.2-imap
php7.2-fpm
php7.2-cgi
php7.2-pspell
php7.2-bz2
php7.2-calendar
php7.2-ctype
php7.2-exif
php7.2-fileinfo
php7.2-ftp
php7.2-gettext
php7.2-iconv
php7.2-json
php7.2-opcache
php7.2-pdo
php7.2-posix
php7.2-pspell
php7.2-readline
php7.2-shmop
php7.2-sockets
php7.2-sysvmsg
php7.2-sysvsem
php7.2-sysvshm
php7.2-tokenizer"
# optional after pspell in the list load order, likely all are required if using composer
# # PHP Minimums:
# sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl php7.2-ldap php7.2-gettext -y
# # For those who really need mcrypt, it is part of PECL, PHP’s extensions repository. You’re welcome to compile it on your own risk.
APACHE_ENMOD_LIST="rewrite
ssl
vhost_alias
http2
alias
authz_host
dir
headers
autoindex
negotiation
setenvif
deflate
expires
mime
"
# log_config
declare -A APACHE_PHPini
# Unnamed Road, Rendezvous Creek ACT 2620
APACHE_PHPini=([allow_url_fopen]='On'
[date.default_latitude]='-35.725808'
[date.default_longitude]='148.974161'
[date.timezone]='Australia/Sydney'
[default_socket_timeout]='360'
[display_errors]='Off'
[display_startup_errors]='Off'
[error_log]="var/log/error.log"
[error_reporting]='4339'
[expose_php]='Off'
[file_uploads]='On'
[html_errors]='Off'
[ignore_repeated_errors]='On'
[ignore_repeated_source]='Off'
[log_errors]='On'
[log_errors_max_len]='3456'
[max_execution_time]='360'
[max_input_time]='60'
[max_input_vars]='10000'
[memory_limit]='512M'
[mysqli.cache_size]='2000'
[opcache.restrict_api]="${APACHE_WROOT_DIR}"
[opcache.validate_permission]='On'
[opcache.validate_root]='On'
[pdo_mysql.cache_size]='2000'
[post_max_size]='128M'
[safe_mode]='off'
[sendmail_path]="$(which sendmail) -t -i"
[session.gc_probability]='0'
[sql.safe_mode]='Off'
[track_errors]='On'
[track_errors]='On'
[upload_max_filesize]='64MB'
)
declare -A APACHE_OPCACHE
APACHE_OPCACHE=([opcache.enable]='1'
[opcache.validate_timestamps]='1'
[opcache.revalidate_freq]='60'
[opcache.max_accelerated_files]='10000'
[opcache.memory_consumption]='64'
[opcache.interned_strings_buffer]='8'
[opcache.fast_shutdown]='1'
)
# declare -A XDEBUG_CONFIG
# @see https://github.com/martomo/SublimeTextXdebug#configuration
# @see https://xdebug.org/docs/all_settings
# XDEBUG_CONFIG=(
# [zend_extension]="$(sudo find /usr/lib/php/ -name "xdebug.so" | grep "[.\/]*xdebug" | sort -t / -k 4 -g -r | sed -n '1p')"
# [xdebug.remote_enable]="1"
# [xdebug.remote_handler]="\"dbgp\""
# [xdebug.remote_mode]="req"
# [xdebug.remote_host]="\"${MY_IP_LOCAL}\""
# [xdebug.remote_port]="9000"
# [xdebug.remote_connect_back]="1"
# [xdebug.idekey]="sublime.xdebug"
# [xdebug.max_nesting_level]="200"
# [xdebug.remote_log]="/var/log/xdebug/xdebug.log"
# )
# [xdebug.remote_host]="10.0.2.2" \ # vagrant use
# WP_CLI_LIST='ernilambar/database-command
# wp-cli/profile-command
# alleyinteractive/wp-doc-command
# binarygary/db-checkpoint
# markri/wp-sec
# wp-cli/entity-command
# config-command
# johnbillion/ext'
# https://www.linux.com/learn/how-do-painless-mysql-server-backups-automysqlbackup
# AUTOMYSQLBAK_CONF="CONFIG_mysql_dump_username='${DB_USER_ROOT}'
# CONFIG_mysql_dump_password='${DB_PASS_ROOT}'
# CONFIG_mysql_dump_host='localhost'
# CONFIG_backup_dir='/var/wwwbak/sql'
# # List of databases for Daily/Weekly Backup e.g. ( 'DB1' 'DB2' 'DB3' ... )
# # set to (), i.e. empty, if you want to backup all databases
# CONFIG_db_names=()
# # List of databases for Monthly Backups.
# # set to (), i.e. empty, if you want to backup all databases
# CONFIG_db_month_names=()
# # List of DBNAMES to EXLUCDE if DBNAMES is empty, i.e. ().
# #CONFIG_db_exclude=('information_schema' 'test_db' 'demo_db' )
# # Which day do you want monthly backups? (01 to 31)
# CONFIG_do_monthly=\"01\"
# # Which day do you want weekly backups? (1 to 7 where 1 is Monday)
# CONFIG_do_weekly=\"5\"
# # Set rotation of daily backups. VALUE*24hours
# # If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.
# CONFIG_rotation_daily=6
# # Set rotation for weekly backups. VALUE*24hours
# CONFIG_rotation_weekly=35
# # Set rotation for monthly backups. VALUE*24hours
# CONFIG_rotation_monthly=150
# CONFIG_mysql_dump_port=3306
# CONFIG_mysql_dump_use_separate_dirs='yes'
# CONFIG_mysql_dump_compression='gzip'"
# Project Settings in Sublime Text
# PYTH_PATH=$(which python)
# SUBLIME_PROJECT_FILE="{
# \"folders\":
# [
# {
# \"follow_symlinks\": true,
# \"path\": \"${APP_PATH}\"
# },
# }
# ],
# \"settings\": {
# \"xdebug\": {
# \"path_mapping\": {
# \"${APP_PATH//\/var\/www\/*\//}\": \"${APP_PATH}\"
# }
# \"url\": \"https://${APP_URL_FULL}/\",
# \"super_globals\": true,
# \"close_on_stop\": true,
# \"pretty_output\": true,
# \"ide_key\": sublime.xdebug,
# \"python_path\": ${PYTH_PATH}
# }
# }
# }
# "
################################################################################################################################################
######################## INSTALL DEPENDENCIES
printf "${ccb}Refreshing software version listings...${endp}"
printf "${ccb}"
while IFS= read -r listpackage ; do
case $listpackage in
# make sure the 'dependency_list' is in the order of install
# 'case' DOES NOT care about chronology of cases
#
*#* ) echo "[OMITTED] $listpackage, commented-out" ;;
composer )
sudo apt update
sudo apt install curl php-cli php-mbstring git unzip
mkdir -p "$HOME/.composer"
cd "$HOME/.composer"
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar "$HOME/.composer/composer"
sudo sed -i 's,PATH=,PATH=$HOME/.composer,g' ~/.zshrc
sudo sed -i 's,PATH=,PATH=$HOME/.composer,g' ~/.bashrc
touch "$HOME/.composer/composer.json"
cat > "$HOME/.composer/composer.json" << EOF
{
"config": {
"sort-packages": true,
"platform": {
"php": "7.2"
}
},
"require": {
"php": ">=7.2",
"aaemnnosttv/wp-cli-dotenv-command": "^2.0",
"guzzlehttp/guzzle": "^6.3",
"guzzlehttp/promises": "^1.3",
"inpsyde/wonolog": "^1.0",
"jaywood/jw-shortcode-scraper": "^1.0",
"markri/wp-sec": "^0.0.3",
"mhcg/monolog-wp-cli": "^1.0",
"mollie/polyfill-libsodium": "^1.1",
"php-console/php-console": "^3.1",
"roots/bedrock": ">=1.9.0",
"simpro/restclient-php": "^1.0",
"soberwp/intervention": "^1.2",
"soberwp/models": "^1.1",
"typisttech/image-optimize-command": "^0.3.0",
"wp-cli/cache-command": "*",
"wp-cli/config-command": "^2.0",
"wp-cli/core-command": "^2.0",
"wp-cli/cron-command": "^2.0",
"wp-cli/db-command": "^2.0",
"wp-cli/entity-command": "^2.0",
"wp-cli/eval-command": "^2.0",
"wp-cli/extension-command": "^2.0",
"wp-cli/find-command": "^0.2.1",
"wp-cli/media-command": "^2.0",
"wp-cli/package-command": "^2.0",
"wp-cli/profile-command": "^0.3.0",
"wp-cli/rewrite-command": "^2.0",
"wp-cli/role-command": "^2.0",
"wp-cli/scaffold-command": "^2.0",
"wp-cli/search-replace-command": "*",
"wp-cli/shell-command": "*",
"wp-cli/super-admin-command": "*",
"wp-cli/wp-cli": "^2.0",
"wpmetabox/meta-box": "^4.15"
},
"prefer-stable": true,
"require-dev": {
"squizlabs/php_codesniffer": "*",
"object-calisthenics/phpcs-calisthenics-rules": "*",
"phpcompatibility/php-compatibility": "*",
"wp-coding-standards/wpcs": "*",
"psy/psysh": "~0.6",
"phpcompatibility/phpcompatibility-wp": "*",
"roave/security-advisories": "dev-master"
}
}
EOF
composer self-update || sudo composer self-update
composer global update || sudo composer global update
;;
apache|apache2 )
if [ $(which apache2) ] || [[ $(dpkg -s --dry-run "$listpackage" ) == *"installed"* ]] ; then
printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
else # echo "apt $listpackage"
sudo apt install $listpackage -y
fi
if [[ "$(cat /etc/apache2/apache2.conf)" == *"Protocols h2 http\/1\.1"* ]] ; then
printf "${ccb}[INSTALL]${wb} 'http2mod.conf' snippet instead of direct 'apache2.conf'${endp}"
sudo sed -i "s,^.*Protocols h2 http.*$,\# Protocols h2 http\/1\.1," /etc/apache2/apache2.conf
fi
if [ ! -f /etc/apache2/conf-available/http2mod.conf ] || [[ $(grep "Protocol" /etc/apache2/conf-available/http2mod.conf) == *"#"* ]] ; then
printf "${ccb}[INSTALL]${wb} Generating and enabling 'http2mod.conf'...${endp}"
sudo touch /etc/apache2/conf-available/http2mod.conf
# sudo sed -i "s,^[# \*\/]*Protocols.*$,Protocols h2 http\/1\.1,g" /etc/apache2/conf-available/http2mod.conf > /dev/null || \
sudo echo "Protocols h2 http/1.1" | sudo tee /etc/apache2/conf-available/http2mod.conf > /dev/null
sudo a2enconf http2mod
# sudo service apache2 restart || sudo systemctl restart apache2.service
fi
if [ ! -f /etc/apache2/conf-available/servername.conf ]; then
printf "${ccb}[INSTALL]${wb} Generating and enabling 'servername.conf'...${endp}"
sudo touch /etc/apache2/conf-available/servername.conf
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf > /dev/null
sudo a2enconf servername
# sudo service apache2 restart || sudo systemctl restart apache2.service
fi
# if [ ! -f /etc/apache2/mods-enabled/dir.conf ]; then
printf "${ccb}[INSTALL]${wb} Generating and enabling 'dir.conf'...${endp}"
sudo touch /etc/apache2/mods-enabled/dir.conf
echo "${APACHE_DIRMOD}" | sudo tee /etc/apache2/mods-enabled/dir.conf > /dev/null
# fi
sudo cp "${APACHE_PHP_CONF}" "${APACHE_PHP_CONF}_${datetimenow//\:\-/}.bak"
for option in "${!APACHE_OPCACHE[@]}" ; do
sudo sed -i "s,[; ]*${i} = .*$,${option} = '${APACHE_OPCACHE[$option]}'," ${APACHE_PHP_CONF} || \
sudo sed -i "s,[; ]*${i}[ \s]*=.*$,${option} = '${APACHE_OPCACHE[$option]}'," ${APACHE_PHP_CONF}
done
while read -r apachemod ; do
if [[ $(apache2ctl -t -D DUMP_INCLUDES) == *"enabled/${apachemod}"* ]] ; then
printf "${gb}[SUCCESS]${wb} Apache ${apachemod} already configured${endp}"
else
printf "${gb}[INSTALL]${wb} Enabling '${apachemod}'...${endp}"
sudo a2enmod ${apachemod}
fi
done <<< "$APACHE_ENMOD_LIST"
sudo service apache2 restart
;;
sendmail )
if [ $(which sendmail) ] || [[ $(dpkg -s --dry-run "$listpackage" ) == *"installed"* ]] ; then
printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
else # echo "apt $listpackage"
sudo apt install sendmail -y
ETC_HOST_SENDMAIL="127.0.0.1 localhost localhost.localdomain"
sudo echo "${NL}${ETC_HOST_SENDMAIL}" | sudo tee --append /etc/hosts > /dev/null
echo "include(\`/etc/mail/tls/starttls.m4')dnl" | sudo tee --append /etc/mail/sendmail.mc > /dev/null
yes 'y' | sudo sendmailconfig
fi
sudo sed -i 's/localhost.localdomain/ /g' /etc/hosts > /dev/null
sudo sed -i 's/localhost/ /g' /etc/hosts > /dev/null
sudo sed -i 's/127.0.0.1/127.0.0.1 localhost localhost.localdomain/g' /etc/hosts > /dev/null
;;
# dnsmasq )
# if [ $(which $listpackage) ] || [[ $(dpkg -s --dry-run $listpackage) == *"installed"* ]] ; then
# printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
# else
# # sudo apt install dnsmasq
# # sudo apt-get install network-manager network-manager-gnome
# # sudo systemctl unmask dnsmasq > /dev/null
# # sudo systemctl enable dnsmasq > /dev/null
# # sudo service dnsmasq restart > /dev/null
# # sudo service systemd-resolved restart > /dev/null
# # sudo service network-manager restart > /dev/null
# fi
# printf "${gb}[UPDATER]${wb} Checking DNSmasq configs...${endp}"
# if [ ! -f /etc/dnsmasq.conf ] ; then
# sudo touch /etc/dnsmasq.conf ; else sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf_${datetimenow//\:\-/}.bak
# fi && sleep 0.15
# for idns in "${!DNSmSERV[@]}"; do
# if [[ "${DNSmSERV[${idns}]}" == *"#"* ]] ; then
# sudo sed -ir "0,/^[# ]*${idns}$/s//${idns}/" /etc/dnsmasq.conf
# sudo sed -ir "0,/^[# ]*${idns}/s//${idns}\n#${idns}/" /etc/dnsmasq.conf
# else
# sudo sed -ir "0,/^[# ]*${idns}${DNSmSERV[${idns}]}$/s//${idns}${DNSmSERV[${idns}]}/" /etc/dnsmasq.conf
# sudo sed -ir "0,/^[#]*${idns}${DNSmSERV[${idns}]}$/s//${idns}${DNSmSERV[${idns}]}/" /etc/dnsmasq.conf
# sudo sed -ir "0,/^[# ]*${idns}/s//${idns}${DNSmSERV[${idns}]}\n#${idns}/" /etc/dnsmasq.conf
# fi
# sudo awk '!NF || !seen[$0]++' /etc/dnsmasq.conf > ${APACHE_WROOT_DIR}/dnsmasq.tmp && sudo mv -f ${APACHE_WROOT_DIR}/dnsmasq.tmp /etc/dnsmasq.conf
# done
# if [ ! -f /etc/NetworkManager/NetworkManager.conf ] ; then
# sudo touch /etc/NetworkManager/NetworkManager.conf ; else sudo cp /etc/NetworkManager/NetworkManager.conf /etc/NetworkManager/NetworkManager.conf_${datetimenow//\:\-/}.bak
# fi && sudo sed -i 's/[# ]*dns=dnsmasq/dns=dnsmasq/g' /etc/NetworkManager/NetworkManager.conf > /dev/null || \
# echo "dns=dnsmasq" | sudo tee --append /etc/NetworkManager/NetworkManager.conf > /dev/null
# # We require that DNS queries be resolved first with dnsmasq, only checking external servers if dnsmasq cannot resolve the query.
# # dhcpcd, unfortunately, tends to overwrite '/etc/resolv.conf' by default
# # if [ ! -f /etc/resolv.conf ] ; then sudo touch /etc/resolv.conf ; else sudo cp /etc/resolv.conf /etc/resolv.conf_${datetimenow//\:\-/}.bak ; fi
# # sudo sed -i "s/nameserver.*$/nameserver ${MY_IP_LOCAL}/g" /etc/resolv.conf || echo "nameserver ${MY_IP_LOCAL}" | sudo tee /etc/resolv.conf > /dev/null
# # if [ ! -f /etc/dhcp/dhclient.conf ] ; then sudo touch /etc/dhcp/dhclient.conf ; else sudo cp /etc/dhcp/dhclient.conf /etc/dhcp/dhclient.conf_${datetimenow//\:\-/}.bak ; fi
# # sudo sed -i "s/.*prepend domain-name-servers.*$/prepend domain-name-servers ${MY_IP_LOCAL}/g" /etc/dhcp/dhclient.conf|| echo "prepend domain-name-servers ${MY_IP_LOCAL}" | sudo tee /etc/dhcp/dhclient.conf > /dev/null
# if [ ! -f /etc/dnsmasq-resolv.conf ] ; then
# sudo touch /etc/dnsmasq-resolv.conf ; else sudo cp /etc/dnsmasq-resolv.conf /etc/dnsmasq-resolv.conf_${datetimenow//\:\-/}.bak
# fi && sudo sed -i "s/.*nameserver.*$/nameserver ${MY_IP_LOCAL}/g" /etc/dnsmasq-resolv.conf > /dev/null || \
# sudo sed -i "1 i\nameserver ${MY_IP_LOCAL}" /etc/dnsmasq-resolv.conf > /dev/null || \
# echo "nameserver ${MY_IP_LOCAL}" | sudo tee --append /etc/dnsmasq-resolv.conf > /dev/null
# if [[ $(sudo netstat -nap | grep "${MY_IP_LOCAL}:53") == *"dnsmasq"* ]] ; then
# # # This will switch off binding to port 53.
# # # The 'bind-interfaces' config should do fine, but if you have DNSmasq properly setup then this should still work too...
# # sudo sed -ir "s/[ #]*DNSStubListener\=yes.*$/DNSStubListener\=no/g" /etc/systemd/resolved.conff || \
# # sudo sed -i "s/.*DNSStubListener.*$/DNSStubListener\=no/g" /etc/systemd/resolved.conff || \
# # echo "DNSStubListener=no" | sudo tee /etc/systemd/resolved.conf > /dev/null
# printf "${rb}"
# # sudo systemctl unmask dnsmasq > /dev/null
# # sudo systemctl enable dnsmasq > /dev/null
# # sudo service dnsmasq restart > /dev/null
# else
# dnsmasq -r /etc/dnsmasq-resolv.conf > /dev/null
# fi
# # For further, @see https://www.linux.com/learn/intro-to-linux/2018/2/dns-and-dhcp-dnsmasq
# printf "${cb}"
# # dnsmasq -r /etc/dnsmasq-resolv.conf > /dev/null
# sudo service systemd-resolved restart > /dev/null
# sudo service network-manager restart > /dev/null
# ;;
php5*|php7* )
if [ $(which $listpackage) ] || [[ $(dpkg -s --dry-run $listpackage) == *"installed"* ]] ; then
printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
else # echo "apt $listpackage"
software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudo apt update > /dev/null 2>&1
fi
while read phpmodule ; do
if [[ "$(dpkg --get-selections | grep "php")" == *"$phpmodule"* ]] || [[ $(php -m) =~ .*?${phpmodule#"php7.2-"}.*? ]] ; then
printf "${gb}[SUCCESS]${wb} '${phpmodule}' already installed${endp}"
else
printf "${ccb}[INSTALL]${wb} '${phpmodule}' install required...${endp}"
apt install ${phpmodule} -y || sudo apt install ${phpmodule} -y
fi
done <<< "$APACHE_PHP_MOD"
sudo cp "${APACHE_PHP_CONF}" "${APACHE_PHP_CONF}_${datetimenow//\:\-/}.bak"
for i in "${!APACHE_PHPini[@]}" ; do
sudo sed -i "s,[; ]*${i} = .*$,${i} = '${APACHE_PHPini[$i]}'," ${APACHE_PHP_CONF} || \
sudo sed -i "s,[; ]*${i}[ \s]*=.*$,${i} = '${APACHE_PHPini[$i]}'," ${APACHE_PHP_CONF}
done
printf "${cb}" && sudo service apache2 restart > /dev/null
;;
# xdebug-php )
# if [[ $(dpkg -s --dry-run "$listpackage") == *"installed"* ]] ; then
# printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
# else
# sudo apt-get install php-xdebug
# # git clone https://github.com/martomo/SublimeTextXdebug.git "Xdebug Client"
# fi
# APACHE_USER="www-data"
# if [ ! -d /var/log/xdebug ] ; then
# sudo mkdir /var/log/xdebug && sudo chown ${APACHE_USER}:${APACHE_USER} /var/log/xdebug ; fi
# for xi in "${!XDEBUG_CONFIG[@]}" ; do
# sudo sed -i "s,[; ]*${xi}[ =]*.*$,${xi} = ${XDEBUG_CONFIG[$xi]},g" ${APACHE_PHP_CONF} || \
# sudo sed -i "s,[; ]*${xi}.*$,${xi} = ${XDEBUG_CONFIG[$xi]},g" ${APACHE_PHP_CONF}
# done
# printf "${cb}" && sudo service apache2 restart > /dev/null
# ;;
mariadb*|*sql* )
if [ $(which mysql) ] || [[ $(dpkg -s --dry-run $listpackage) == *"installed"* ]] ; then
printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
SECURE_MYSQL="set timeout 10
spawn mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"${DB_PASS_ROOT}\r\"
expect \"Change the root password?\"
send \"n\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof"
else
# sudo apt-get install mariadb-server mariadb-client
echo "apt $listpackage"
sudo apt install expect -y
sudo apt install mysql-server -y
echo "$(expect -c ${SECURE_MYSQL})"
fi
# /etc/mysql/my.cnf
# max_allowed_packet=64M
# wait_timeout = 100
printf "${cb}" && sudo systemctl restart mysql.service > /dev/null
;;
phpmyadmin )
if [ $(which $listpackage) ] || [[ $(dpkg -s --dry-run $listpackage) == *"installed"* ]] ; then
printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
else # echo "apt $listpackage"
# @see https://askubuntu.com/questions/168191/where-is-my-phpmyadmin-installation
sudo apt install debconf-set-selections -y
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/app-password-confirm password $DB_PASS_ROOT" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $DB_PASS_ROOT" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/app-pass password $DB_PASS_ROOT" | debconf-set-selections
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections
# Web server to configure automatically: <-- Select the option: apache2
# Configure database for phpmyadmin with dbconfig-common? <-- Yes
# MySQL application password for phpmyadmin: <-- Press enter, apt will create a random password automatically.
sudo apt install phpmyadmin -y
sudo ln -s /usr/share/phpmyadmin ${APACHE_WROOT_DIR}/html/
sudo systemctl restart mysql.service
printf "${cb}" && sudo service apache2 restart > /dev/null
fi
;;
# automysqlbackup )
# 15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data '+%m-%d-%Y'`.sql.gz
# # # https://github.com/sunfjun/Scripts/blob/master/automysqlbackup.sh.2.5
# # if which automysqlbackup ; then
# # sudo cp /var/wwwbak/sql/automysqlbackup.conf /var/wwwbak/sql/automysqlbackup.conf.${datetimenow//\:\-/}.bak
# # else
# # sudo apt install $listpackage -y > /dev/null 2>&1
# # fi
# # sudo mkdir -p /var/wwwbak/sql
# # if sudo find /etc/automysqlbackup -name automysqlbackup.conf ; then printf "" ; else
# # sudo touch /etc/automysqlbackup/automysqlbackup.conf
# # sudo echo "${AUTOMYSQLBAK_CONF}" | sudo tee --append /etc/automysqlbackup/automysqlbackup.conf > /dev/null
# # ls -lR $(which automysqlbackup) | grep ^l
# # ln -s $(which automysqlbackup) /etc/cron.daily/ || sudo ln -s /usr/sbin/automysqlbackup /etc/cron.daily/ || echo "[!] Failed to add AutoMySQLBackup Cron"
# # fi
# # sudo automysqlbackup
# ;;
wp-cli|wp\s*|wp-* )
if [ ! $(which wp) ] ; then composer global require wp-cli/wp-cli ; fi
if [[ $(which wp) =~ .*?composer.*? ]] ; then
while read -r wpclipack ; do
if [ $(composer global show) =~ .*?${wpclipack}.*? ] || [ $(composer show) =~ .*?${wpclipack}.*? ] ; then
printf "${gb}[SUCCESS]${wb} '${wpclipack}' already installed${endp}"
composer global update
else
printf "${ccb}[INSTALL]${wb} '${wpclipack}' install required...${endp}"
composer global require $wpclipack
fi
done <<< "${WP_CLI_LIST}"
else
printf "${rb}[INSTALLER]${wb} WP-CLI was not installed via composer, so please manually update${endp} ${WP_CLI_LIST} ${endp}"
fi
;;
* )
if [ $(which $listpackage) ] || [[ $(dpkg -s $listpackage) == *"installed"* ]] ; then
printf "${gb}[SUCCESS]${wb} $listpackage already installed${endp}"
else # echo "apt $listpackage"
sudo apt install $listpackage -y
fi
;;
esac
done <<< "$dependency_list"
# sudo setfacl -R -m g:${APACH_GROUP}:rwx ${APACHE_WROOT_DIR} || sudo setfacl -R -m g:www-data:rwx ${APACHE_WROOT_DIR}
# sudo ufw default deny incoming
# sudo ufw default deny outgoing
# sudo ufw allow from 127.0.0.1
# sudo ufw allow ssh || sudo ufw allow 22/tcp
# sudo ufw allow http || sudo ufw allow 80
# sudo ufw allow https || sudo ufw allow 443
# sudo ufw allow 25 #mail SMTP
# # sudo ufw reset
sudo apt-get clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment