Last active
August 2, 2025 04:07
-
-
Save christianhanvey/5592012 to your computer and use it in GitHub Desktop.
A shell script to help automate the upgrade of a MODX Revolution installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # modx-upgrade.sh | |
| # --------------- | |
| # A shell script to help automate the upgrade of a MODX Revolution installation | |
| # | |
| # Instructions: | |
| # 1. Upload this file to your server, preferably outside of web root | |
| # 2. give this file execute permissions, and run from the command line | |
| # 3. re-run setup from your browser to finish upgrade | |
| # | |
| # If you want to know what is happening: | |
| # - a copy of the site files is made | |
| # - the new modx is downloaded and then moved into this folder after | |
| # preserving components, packages and configs from your existing install | |
| # - those components, packages, and configs are then synced from the old site | |
| # - finally, we swap old for new, and also make an date stamped archive of the old site | |
| # NOTE: this script does not back-up your database | |
| # -------------- | |
| # config section | |
| # -------------- | |
| # set absolute path to MODX | |
| #PATH_TO_MODX='/absolute/path/to/modx' | |
| PATH_TO_MODX='/Users/christianhanvey/Sites/modx/modx-2.2.6-dev' | |
| # name of temporary folder for modx download | |
| # will be created alongside modx directory (should not already exist) | |
| MODX_DL='modx_download' | |
| # date format - used in back-up archive filename | |
| D=$(date +%Y-%m-%d) | |
| # --------------- | |
| # start of script | |
| # --------------- | |
| echo '' | |
| echo 'MODX Upgrade script' | |
| echo '-------------------' | |
| echo "Preparing to upgrade MODX installation at: $PATH_TO_MODX" | |
| echo '' | |
| # set to exit on error | |
| set -e | |
| # lets go | |
| cd $PATH_TO_MODX | |
| # get the name of directory where the install is | |
| MODX_DIR_NAME=${PWD##*/} | |
| cd .. | |
| # remove any old upgrade folders | |
| rm -rf _$MODX_DIR_NAME | |
| # copy current site to temporary duplicate directory | |
| cp -R $MODX_DIR_NAME _$MODX_DIR_NAME | |
| # prepare new directory - make it easier to merge new modx | |
| cd _$MODX_DIR_NAME | |
| mv connectors _connectors | |
| mv core _core | |
| mv manager _manager | |
| mv index.php _index.php | |
| cd .. | |
| # grab the latest and greatest | |
| #mkdir $MODX_DL | |
| cd $MODX_DL | |
| #wget -O latest.zip http://modx.com/download/latest | |
| unzip -q latest.zip | |
| rm latest.zip | |
| cd .. | |
| # we don't know the name of the containing directory we just unzipped | |
| # but we know its the only item in our temporary download folder | |
| cd $MODX_DL/* | |
| mv connectors ../../_$MODX_DIR_NAME/ | |
| mv core ../../_$MODX_DIR_NAME/ | |
| mv manager ../../_$MODX_DIR_NAME/ | |
| mv setup ../../_$MODX_DIR_NAME/ | |
| mv index.php ../../_$MODX_DIR_NAME | |
| # copy components over | |
| cd ../../_$MODX_DIR_NAME | |
| cp -Rf _core/components core | |
| # move packages over make sure not to bring old core files | |
| rm -rf _core/packages/core | |
| rm -rf _core/packages/core.transport.zip | |
| cp -Rf _core/packages/* core/packages/ | |
| # bring our config files over | |
| cp -f $PATH_TO_MODX/config.core.php . | |
| cp -f $PATH_TO_MODX/connectors/config.core.php connectors | |
| cp -f $PATH_TO_MODX/manager/config.core.php manager | |
| cp -f $PATH_TO_MODX/core/config/config.inc.php core/config | |
| # backup setup to make it easy to re-run | |
| rm -rf setup.tar | |
| tar -czf setup.tar.gz setup | |
| # swap old site with new site | |
| echo '' | |
| echo "Preparing to hot-swap to upgraded version..." | |
| cd $PATH_TO_MODX | |
| cd .. | |
| #remove any existing backup folder first | |
| rm -rf $MODX_DIR_NAME-backup | |
| mv $MODX_DIR_NAME $MODX_DIR_NAME-backup && mv _$MODX_DIR_NAME $MODX_DIR_NAME | |
| # clean up | |
| rm -rf $MODX_DIR_NAME/_core && rm -rf $MODX_DIR_NAME/_connectors && rm -rf $MODX_DIR_NAME/_manager && rm -f _index.php | |
| # remove download folder | |
| rm -rf $MODX_DL | |
| # create archive of old version | |
| tar -czf "$MODX_DIR_NAME--$D.tar.gz" $MODX_DIR_NAME-backup | |
| rm -rf $MODX_DIR_NAME-backup | |
| echo '' | |
| echo "All done. Now go and run setup in your browser to finish the upgrade" | |
| echo "Have a nice day! :)" | |
| echo '' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment