Skip to content

Instantly share code, notes, and snippets.

@craigrodway
Last active April 20, 2022 11:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save craigrodway/66c9633ae5d865a9b090 to your computer and use it in GitHub Desktop.
Save craigrodway/66c9633ae5d865a9b090 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# ProcessWire upgrade script
#
# Upgrades ProcessWire ./wire directory.
# Use either master of dev branch.
#
#
# Usage:
#
# chmod +x ./wire-upgrade.sh
# ./wire-upgrade.sh dev|master
#
#
# Variables
#
TIME=`date +%Y-%m-%d` # date Y-m-d
WIRE_TMP="wire.tmp"
WIRE_CURRENT="wire"
WIRE_BACKUP="wire.backup.$TIME"
WIRE_NEW="wire.new"
PW_REPO_URL="git://github.com/ryancramerdesign/ProcessWire.git"
#
# Functions
#
#
# Visual output
#
out ()
{
echo "["`date +"%Y-%m-%d %T"`"] $1"
}
#
# Git checkout
#
checkout ()
{
echo ""
out "Retrieving repository..."
git clone -b $1 $2 $3
out "Done!"
echo ""
}
#
# Cleanup
#
cleanup ()
{
echo ""
out "Cleaning up temporary directory..."
rm -rf $WIRE_TMP
out "Done!"
echo ""
}
args=("$@")
BRANCH=${args[0]}
echo ""
out "ProcessWire upgrade script."
echo ""
if [ ! -d $WIRE_CURRENT ]; then
out "ProcessWire '$WIRE_CURRENT' directory not found. Cannot continue."
exit 0
fi
if [ -d $WIRE_TMP ]; then
out "Temporary directory '$WIRE_TMP' already exists."
out "Please delete before continuing."
exit 0
fi
if [ -d "$WIRE_BACKUP" ]; then
out "Backup directory '$WIRE_BACKUP' already exists."
out "Please delete before continuing."
exit 0
fi
if [ -z $BRANCH ]; then
out "No branch specified. Please run with either 'master' or 'dev' parameter."
out "E.g. './wire-upgrade.sh master'"
exit 0
fi
echo ""
out "Upgrading ProcessWire in '$WIRE_CURRENT' to the current '$BRANCH' branch..."
echo ""
# Checkout from Git repo
checkout $BRANCH $PW_REPO_URL $WIRE_TMP
# Move the wire dir out of the downloaded repository
if [ ! -d "$WIRE_TMP/wire" ]; then
out "New 'wire' directory '$WIRE_TMP/wire' does not exist. Cannot continue."
exit 0
fi
mv -v $WIRE_TMP/wire "./$WIRE_NEW"
echo ""
out "Backing up current ProcessWire '$WIRE_CURRENT' to '$WIRE_BACKUP' ..."
echo ""
# Rename current wire to a .backup; and then move new version to 'wire' (making it the new version)
mv -v $WIRE_CURRENT $WIRE_BACKUP && mv -v $WIRE_NEW $WIRE_CURRENT
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment