Skip to content

Instantly share code, notes, and snippets.

@christianhanvey
Last active November 1, 2017 16:40
Show Gist options
  • Save christianhanvey/5592012 to your computer and use it in GitHub Desktop.
Save christianhanvey/5592012 to your computer and use it in GitHub Desktop.

Revisions

  1. christianhanvey revised this gist Jun 11, 2013. 1 changed file with 73 additions and 25 deletions.
    98 changes: 73 additions & 25 deletions modx-upgrade.sh
    Original file line number Diff line number Diff line change
    @@ -3,33 +3,58 @@
    # modx-upgrade.sh
    # ---------------
    # A shell script to help automate the upgrade of a MODX Revolution installation
    # This script is for traditional installations only - not advanced
    #
    # 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
    # 1. Update the config section with your own site specific details
    # 2. Upload this file to your server, preferably outside of web root
    # 3. give this file execute permissions, and run from the command line
    # 4. run /setup from your browser to finish upgrade
    # 5. there is no step 5!
    # 6. no step 6 either, huh?
    #
    # 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
    # - finally, we swap old for new
    # - also make a date-stamped archive of the old site, including a database backup
    #
    # REMEMBER: always verify your backups
    # don't leave checking they actually work until the point where you need to use them
    # that is the worst time to find out your backups don't work
    # a backup works if you can fully restore your site from it


    # --------------
    # config section
    # --------------

    # set absolute path to MODX
    # MUST SET:
    #
    # absolute path to MODX
    PATH_TO_MODX='/absolute/path/to/modx'
    #
    # db config
    DB_NAME='your_db_name'
    DB_USER='your_db_user'
    DB_PASS='your_db_pass'
    DB_HOST='your_db_host'


    # OPTIONALLY SET:
    #
    # writable folder permissions
    WRITE_DIR_MODE=0755
    #
    # writable file permissions
    WRITE_FILE_MODE=0644
    #
    # 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)

    @@ -38,15 +63,23 @@ 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

    # define some colours
    red='\e[0;31m'
    green='\e[0;32m'
    litegreen='\e[1;32m'
    purple='\e[0;35m'
    NC='\e[0m' # No Color

    echo ''
    echo -e "${green}MODX Upgrade script${NC}"
    echo -e "${litegreen}* * * * * * * * * * ${NC}"
    echo ''
    echo -e "${green}[INFO]${NC} Preparing to upgrade MODX installation at: $PATH_TO_MODX "
    echo ''

    # lets go
    cd $PATH_TO_MODX
    # get the name of directory where the install is
    @@ -56,21 +89,29 @@ cd ..
    # remove any old upgrade folders
    rm -rf _$MODX_DIR_NAME

    echo -e "${green}[INFO]${NC} Copying directory ${MODX_DIR_NAME} to _${MODX_DIR_NAME}"
    echo ''

    # copy current site to temporary duplicate directory
    cp -R $MODX_DIR_NAME _$MODX_DIR_NAME
    cp -Rp $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
    if [ -d setup ]
    then
    mv setup _setup
    fi
    cd ..

    # grab the latest and greatest
    #mkdir $MODX_DL
    rm -rf $MODX_DL
    mkdir $MODX_DL
    cd $MODX_DL
    #wget -O latest.zip http://modx.com/download/latest
    wget -O latest.zip http://modx.com/download/latest
    unzip -q latest.zip
    rm latest.zip
    cd ..
    @@ -86,16 +127,19 @@ mv index.php ../../_$MODX_DIR_NAME

    # copy components over
    cd ../../_$MODX_DIR_NAME
    cp -Rf _core/components core
    cp -Rfp _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/
    cp -Rfp _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
    # make sure permissions of required folders are correct
    chmod $WRITE_DIR_MODE core/cache core/export core/components core/packages assets assets/components
    chmod $WRITE_FILE_MODE core/config/config.inc.php

    # backup setup to make it easy to re-run
    rm -rf setup.tar
    @@ -104,7 +148,8 @@ tar -czf setup.tar.gz setup

    # swap old site with new site
    echo ''
    echo "Preparing to hot-swap to upgraded version..."
    echo -e "${green}[INFO]${NC} Ok, let's hot-swap to upgraded version..."
    echo -e ''

    cd $PATH_TO_MODX
    cd ..
    @@ -118,15 +163,18 @@ rm -rf $MODX_DIR_NAME/_core && rm -rf $MODX_DIR_NAME/_connectors && rm -rf $MODX
    # remove download folder
    rm -rf $MODX_DL

    # backup the database
    mysqldump -u $DB_USER -p$DB_PASS -h $DB_HOST $DB_NAME | gzip -9 > $MODX_DIR_NAME"-backup/"$DB_NAME"-"$D".sql.gz"

    # create archive of old version
    tar -czf "$MODX_DIR_NAME--$D.tar.gz" $MODX_DIR_NAME-backup
    tar -czf $MODX_DIR_NAME"_"$D".tar.gz" $MODX_DIR_NAME-backup
    rm -rf $MODX_DIR_NAME-backup

    echo -e "${green}[INFO]${NC} All done${NC}"
    echo ''
    echo "All done. Now go and run setup in your browser to finish the upgrade"
    echo "Have a nice day! :)"
    echo -e "${red}[WARNING]${NC} You must now finish the upgrade by running /setup from your browser"
    echo ''
    echo -e "Have a nice day! ${green}:)${NC}"
    echo ''




  2. christianhanvey revised this gist May 16, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions modx-upgrade.sh
    Original file line number Diff line number Diff line change
    @@ -24,8 +24,7 @@
    # --------------

    # set absolute path to MODX
    #PATH_TO_MODX='/absolute/path/to/modx'
    PATH_TO_MODX='/Users/christianhanvey/Sites/modx/modx-2.2.6-dev'
    PATH_TO_MODX='/absolute/path/to/modx'

    # name of temporary folder for modx download
    # will be created alongside modx directory (should not already exist)
  3. christianhanvey created this gist May 16, 2013.
    133 changes: 133 additions & 0 deletions modx-upgrade.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,133 @@
    #!/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 ''