Skip to content

Instantly share code, notes, and snippets.

@jamesbishopca
Last active November 17, 2020 17:47
Show Gist options
  • Save jamesbishopca/b7f748daddbc73a8f422c469ad8dacac to your computer and use it in GitHub Desktop.
Save jamesbishopca/b7f748daddbc73a8f422c469ad8dacac to your computer and use it in GitHub Desktop.
WordPress Bash Script
#!/bin/bash
NAME="new_wordpress"
WD=`pwd`
PLUGINS='w3-total-cache wordfence wordpress-seo wp-smushit updraftplus'
while getopts "n:d:u:ph:" options; do
case "${options}" in
n)
NAME=${OPTARG}
;;
d)
WPDB="s/database_name_here/${OPTARG}/g"
;;
u)
WPUSER="s/username_here/${OPTARG}/g"
;;
p)
echo -n "enter password: "
read -s pass
pass=$(printf '%q' "$pass")
WPPASS="s/password_here/$pass/g"
;;
h)
WPHOST="s/localhost/${OPTARG}/g"
;;
esac
done
echo "making directory $NAME"
mkdir $NAME
if [ $? -ne 0 ]; then
echo "couldn't create directory"
exit 1
fi
echo "entering directory $NAME"
cd $NAME
echo "downloading wordpress"
curl https://wordpress.org/latest.tar.gz | tar -xz
if [[ -n $WPDB ]] && [[ -n $WPUSER ]] && [[ -n $WPPASS ]]; then
echo "setting up wp-config"
cp ./wordpress/wp-config-sample.php ./wordpress/wp-config.php
for value in $WPDB $WPUSER $WPPASS; do
sed -i $value ./wordpress/wp-config.php
done
if [[ -n $WPHOST ]]; then
sed -i $WPHOST ./wordpress/wp-config.php
fi
PREFIX=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 8 | head -n 1)
sed -i "s/'wp_';/'${PREFIX}_';/g" ./wordpress/wp-config.php
fi
echo "removing readme.html"
rm ./wordpress/readme.html
echo "who uses hello dolly?"
rm ./wordpress/wp-content/plugins/hello.php
echo "removing unneeded themes"
find ./wordpress/wp-content/themes/ -maxdepth 1 -type d -not \( -name "twentytwenty" -o -name "themes" \) -exec rm -rf {} +
echo "downloading plugins"
for plugin in $PLUGINS; do
TEMP=`mktemp`
echo "downloading $plugin to $TEMP"
curl "https://downloads.wordpress.org/plugin/${plugin}.latest-stable.zip" -o $TEMP
echo "extracting $plugin"
unzip -q $TEMP -d ./wordpress/wp-content/plugins
echo "removing $TEMP"
rm $TEMP
done
echo "returning to original directory"
cd $WD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment