We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28173
    • 409 Posts
    Hi,

    I'm an addict MODX user since... since... 2006/2007
    Now, I have about 70 websites made with Evolution and Revolution

    When a new security fix is out, with a new MODX version, I "have to" upgrade each of my websites one by one.
    Hopefully, the upgrade process by web interface is ALWAYS working like a charm : only one fail theses 7 last years.

    Now, I'm become older and lazy.
    So I want to make (or find) a script which doing this (at least for Revo) :

    1. I'm going on the root directory of one of my Revolution website
    2. I'm running the wonderfull script
    3. the script check if in /tmp, there is the lastest modx-revo package. If yes, unpack it. If not, download it and extract it
    4. copy the content of /tmp/modx-2.3.1-pl where I am (on my website directory)
    5. change the correct owner recursively to restore the good rights
    6. run in command line the upgrade process by recovering the database name, username/passwd for the database, admin username/password (in fact, the same as going to the setup directory and following the 5 steps, just by clicking "next")
    7. delete /setup directory
    And after, manually, I just have to check on my browser if everything is well.
    And now I'll be ready to upgrade another Revolution website smiley


    I have found several scripts which can help for the install or upgrade process, but nothing to make with less efforts as described before.


    Thank you for your help smiley

    This question has been answered by gissirob. See the first response.

    [ed. note: Spheerys last edited this post 12 years, 2 months ago.]
    • discuss.answer
      • 44580
      • 189 Posts
      Before you get to step 4 your should:
      - backup (tar) the existing installation to /tmp
      - export the database schema to /tmp
      - cop config.inc.php to /tmp

      Christian's script seems to do most of what you want - you just need to generate the xml configuration file and run the cli upgrade at the end. You could also create your own config file for each installation that your upgrade script could read to get all the parameters you would otherwise have to edit the script for each time.
        • 28173
        • 409 Posts
        Thanks gissirob for your answer smiley

        I always have backup before, of course wink

        I have found this command line : php ./index.php --installmode=upgrade
        The good point is all settings are recovered from the /core/config/config.inc.php, so I don't have to enter them manually, neither use a xml config file

        I only have one problem now : the language !
        I've always wondered why the classical web updater interface didn't recovered the language of the actual revolution (and before evolution) instance : each time, non-english users have to select the correct language.
        In CLI, the selection is simply ignored, but maybe there is a option to pass to the command line ?

        Alternatively, where is set the language of the MODX revolution instance ?
        I could change it afterward in my script....
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It's a System Setting - manager_language, I believe.

          Of course, this can also be set in context settings, group settings (as of 2.3) and even user settings.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 28173
            • 409 Posts
            I have found the key it on the setting interface but when I'm changing "en" to "fr", nothing append (even after clean the cache).
              • 28173
              • 409 Posts
              OK I fix my problem : I can only set the language on the config.xml file.
              Making upgrade on CLI width this config.xml file set everything fine.

              Thanks for you help smiley
                • 28173
                • 409 Posts
                I wrote this script quickly today :
                #!/bin/bash
                
                # MODX Update Script
                # -------------------
                # This shell script automate the upgrade of a MODX Revolution installation
                # on command line (CLI) on a webserver.
                # Is not bullet proof and has to be understood and adapted to each user.
                # I wrote it because upgrading 60 Revolution website is long and boring.
                # With it, you can update a Revolution Website in 8 seconds without mouse
                #
                # BE SURE TO HAVE FONCTIONNAL BACKUP BEFORE USING THIS SCRIPT (database dump AND files)
                #
                # Thanks to Christian Hanvey for the inspiration https://gist.github.com/christianhanvey/5592012
                
                
                
                # --------------
                # Config section
                # --------------
                SOURCE_DIR="/root/utils"
                MODX_PACKAGE_MAX_AGE=86400
                MODX_PACKAGE_LAST_FILENAME="modx-lastest.zip"
                MODX_LAST_DIR="modx-lastest"
                
                
                # ---------------
                # Start of script
                # ---------------
                # Set to exit on error
                set -e
                # Define some colours
                red='\e[0;31m'
                green='\e[0;32m'
                yellow='\e[1;33m'
                litegreen='\e[1;32m'
                purple='\e[0;35m'
                NC='\e[0m' # No Color
                
                
                # -------------------
                # FUNCTION : Cleaning
                # -------------------
                # 1/ Remove all packages, sources directory and symlink of MODX in the $SOURCE_DIR
                function clean_modx {
                  echo -e "${litegreen}-------------------- ${NC}"
                  echo -e "${litegreen}Cleaning old package ${NC}"
                  echo -e "${litegreen}-------------------- ${NC}"
                  # Delete old package, directories and symlink
                  rm -fr $SOURCE_DIR/{modx-2*,$MODX_LAST_DIR}
                  rm -f $SOURCE_DIR/$MODX_PACKAGE_LAST_FILENAME
                  echo -e "-> old MODX packages and directories removed from $SOURCE_DIR/ ${green}[OK]${NC}"
                  echo ""
                }
                
                
                # -------------------
                # FUNCTION : Get MODX
                # -------------------
                # 1/ Check if package is older than a day before downloading it again
                # 2/ Remove older source package and directories
                # 3/ Download last MODX version and extract it to $SOURCE_DIR
                # 4/ Make a symlink from $SOURCE_DIR/modx-2.3.1-pl to $SOURCE_DIR/modx-lastest
                function get_modx {
                  echo -e "${litegreen}------------${NC}"
                  echo -e "${litegreen}Getting MODX${NC}"
                  echo -e "${litegreen}------------${NC}"
                
                  # Downloading only if not exist or it's to older
                  if [ -f $SOURCE_DIR/$MODX_PACKAGE_LAST_FILENAME ]
                    then
                      MODX_PACKAGE_LAST_DOWNLOADED_DATE=`stat -c %X $SOURCE_DIR/$MODX_PACKAGE_LAST_FILENAME`
                      CURRENT_DATE=`date +%s`
                      MODX_PACKAGE_CURRENT_AGE=$(( ($CURRENT_DATE - $MODX_PACKAGE_LAST_DOWNLOADED_DATE) ))
                    else
                      MODX_PACKAGE_CURRENT_AGE=86400000
                  fi
                  if [ $MODX_PACKAGE_CURRENT_AGE -gt $MODX_PACKAGE_MAX_AGE ]
                    then
                      # Function call to cleaning old package
                      clean_modx
                
                      # Getting last MODX package
                      wget -O $SOURCE_DIR/$MODX_PACKAGE_LAST_FILENAME http://modx.com/download/latest
                      echo -e "-> download MODX package ${green}[OK]${NC}"
                
                      # Unzip the package on the Source Directory
                      unzip -o -q $SOURCE_DIR/$MODX_PACKAGE_LAST_FILENAME -d $SOURCE_DIR
                      echo -e "-> extract MODX package inside $SOURCE_DIR/ ${green}[OK]${NC}"
                
                      # Finding the name of the lastest created directory during the extraction
                      LAST_CREATED_DIR=$(find $SOURCE_DIR/modx-2* -type d -prune -exec ls -d {} \; |tail -1)
                
                      # Symbolic link is created to set an unvariable path to the last version of MODX
                      ln -s $LAST_CREATED_DIR $SOURCE_DIR/$MODX_LAST_DIR
                      echo -e "-> symbolic link to $SOURCE_DIR/$MODX_LAST_DIR ${green}[OK]${NC}"
                      echo ""
                    else
                      echo -e "${green}[INFO]${NC} The MODX package is very fresh (less than 24h). Not necessary to download it again."
                      echo ""
                  fi
                }
                
                
                # -------------------
                # FUNCTION : Put MODX
                # -------------------
                # 1/ Check if we are in the right place (the root of one Revo Website). The test is made for my server
                # 2/ If yes, copy new MODX files to the current directory (the project which has to be upgraded)
                # 3/ Setting correct owner to the files inside the directory project to upgrade
                function put_modx {
                  echo -e "${litegreen}----------------------------------${NC}"
                  echo -e "${litegreen}Copy new MODX files on the project${NC}"
                  echo -e "${litegreen}----------------------------------${NC}"
                
                  # Directory verification : we're checking the owner of the directory where we are
                  # It's specidic to my server... so adapt to yours
                  # If we are not on a correct directory project, we stop
                  PROJECT_DIR_OWNER=$(ls -ld .|awk '{ print $3 }')
                
                  if [ "$(echo $PROJECT_DIR_OWNER | grep -E "vu([0-9]{4})")" ]
                  then
                    echo ""
                    echo "Copying the last files of MODX in ${PWD}"
                    cp -Rf /root/utils/modx-lastest/* ./
                    echo -e " -> done ${green}[OK]${NC}"
                
                    echo ""
                    echo "Setting correct owner to the files inside ${PWD}"
                    chown -R $PROJECT_DIR_OWNER.www-data ./
                    echo -e " -> done ${green}[OK]${NC}"
                    echo ""
                
                  else
                          echo "CANCELATION : you are not in a correct project directory !!"
                          exit
                  fi
                }
                
                
                # -----------------------
                # FUNCTION : Upgrade MODX
                # -----------------------
                # 1/ The fabulous CLI to upgrade in 7 seconds. I'm using an optionnal config-modx.xml file just to set the language
                function up_modx {
                  echo -e "${litegreen}------------------------ ${NC}"
                  echo -e "${litegreen}Running the MODX upgrade ${NC}"
                  echo -e "${litegreen}------------------------ ${NC}"
                  echo "Upgrading in progress..."
                
                  /usr/bin/php ./setup/index.php --installmode=upgrade --config=/root/bin/config-modx.xml
                }
                
                
                
                # ============
                # Introduction
                # ============
                echo ''
                echo -e "${litegreen}* * * * * * * * * * ${NC}"
                echo -e "${litegreen}MODX UPGRADE SCRIPT ${NC}"
                echo -e "${litegreen}* * * * * * * * * * ${NC}"
                echo ''
                echo -e "What do you want to do ?"
                echo -e "------------------------"
                echo -e "- get    : getting the last MODX Revolution package and unpack it on $SOURCE_DIR/$MODX_LAST_DIR"
                echo -e "- put    : copy $SOURCE_DIR/$MODX_LAST_DIR to ${yellow}${PWD}${NC}"
                echo -e "- up     : run upgrade command in ${yellow}${PWD}${NC}"
                echo -e "- put-up : copy AND run upgrade command in ${yellow}${PWD}${NC}"
                echo -e "- clean  : remove every MODX sources in $SOURCE_DIR/"
                echo ''
                
                
                # ===========
                # The choices
                # ===========
                echo -e "You are in ${PWD}"
                PS3='Please enter your choice  : '
                options=("get" "put" "up" "put-up" "clean" "Quit")
                select opt in "${options[@]}"
                do
                  case $opt in
                    "get")
                      get_modx;;
                    "put")
                      put_modx;;
                    "up")
                      up_modx
                      exit
                    ;;
                    "put-up")
                      put_modx
                      up_modx
                      exit
                    ;;
                    "clean")
                      clean_modx
                      exit
                    ;;
                    "Quit")
                        break
                        ;;
                    *) echo -e "${red}[ERROR]${NC} Invalid option";;
                  esac
                done
                
                
                


                More recent version here : https://github.com/Spheerys/Scripts/blob/master/MODXUpgradeScript
                With it, you can update a Revolution Website in 8 seconds without mouse ^^
                You can eventually take 5 more seconds to check the front-end page, just in case smiley

                It's not universal : is just working (very) well on my servers.
                But some parts could be useful to someone... [ed. note: Spheerys last edited this post 12 years, 2 months ago.]
                  • 44580
                  • 189 Posts
                  That looks really good Spheerys. Could you possibly post your config.xml file as well?

                  You could extend this further if you wanted to:
                  - automatically back up the filesystem and the database before you start
                  - backing up config.inc.php
                  - removing the setup directory once you've finished
                  - making config.inc.php writable during the upgrade and then read-only again after
                  - capturing all output (including errors) to a log in case something goes wrong.

                    • 28173
                    • 409 Posts
                    Here is my config-modx.xml file :
                    <modx>
                        <!-- Set this to 1 if you are using MODX from Git or extracted it from the full MODX package to the server prior 
                             to installation. -->
                        <inplace>0</inplace>
                    
                        <!-- Set this to 1 if you have manually extracted the core package from the file core/packages/core.transport.zip. 
                             This will reduce the time it takes for the installation process on systems that do not allow the PHP time_limit 
                             and Apache script execution time settings to be altered. -->
                        <unpacked>0</unpacked>
                    
                        <!-- The language to upgrade MODX for. This will set the default manager language to this. Use IANA codes. -->
                        <language>fr</language>
                    
                        <!-- Paths for your MODX core directory -->
                        <!--<core_path>/www/modx/core/</core_path> -->
                    
                        <!-- Whether or not to remove the setup/ directory after installation. -->
                        <remove_setup_directory>1</remove_setup_directory>
                    </modx>
                    


                    About your suggestions :
                    - automatically back up the filesystem and the database before you start
                    In my case, I don't really need to include the backup automation in this script because I have another system on my server (automysqlbackup and rsnapshot)
                    If I have a problem, I can restore old version easily (but not automaticaly, you're right... I'll think about it wink )

                    - backing up config.inc.php
                    In my experience, I never had to do this.
                    The reason is in the original modx package, the directory /core/config is empty.
                    So your config.inc.php won't be overwrite

                    - removing the setup directory once you've finished
                    It's already active in my script, with using the idoine config.xml option

                    - making config.inc.php writable during the upgrade and then read-only again after
                    As said before, I don't touch to the original config.inc.php during the upgrade.
                    So I don't need to change rights on it smiley

                    - capturing all output (including errors) to a log in case something goes wrong.
                    Yes, you're right, I will put it on my todo-list smiley
                    It's my first "big" script, and I'm learning step by step the bash language.

                    In the future, I will go further in the automation :
                    - add a backup/restore function, in case something massively going wrong ^^
                    - find a way to detect the version of Revo on a tree with a lots of projects
                    - upgrade in one step all Revo version in this tree

                      • 44580
                      • 189 Posts
                      Thanks for the xml file.

                      On my server (ubuntu 12.04) the setup directory is not removed by an interactive upgrade. Maybe it will be if automated and using that config.xml setting. I'll have to try it.

                      Backups are all about timing. Best time is just before the upgrade with no-one on the site. smiley

                      And my bad. I was confusing config.inc.php (which does need to be writable during the upgrade but read-only afterwards) with index.php at the root of the site. Making a backup of this is recommended but I guess if you are backing up the whole site you don't need to do that specially.

                      Again, good work!