TYPO free

home

fighting for TYPO free code

TYPO3 mass upgrade script

21 Jan 2009

Yesterday some updates came out for TYPO3. These updates fixed certain issues and we needed to update all of our excellent shared hosting environments.

We already have a script (which is more elaborate now) that checks all our TYPO3 installations and sends the sysadmins a nice report about its findings. We use part of that report (list of paths to Document Roots) to feed the updater script.

The TYPO3 update requires you to do the followi

  • update encryption key
  • clear configuration cache
  • clear page cache

We do not want to go into 200+ TYPO3 backends and do those tasks manually. We are lazy and we will write a script to automagically do the boring tasks for us.

This script is not perfect but it works well on Debian systems. You can modify it to fit your needs. It was just a quick hack to ease the upgrade pain. Take care to switch the symlink part for upgrade runs of different versions of TYPO3.

I am not responsible for any damage to your system that may occur to misuse of this script. Make sure you understand it before you run it. Run it with a single URI before attempting a whole ist of URI's.

  1. #!/bin/sh
  2. binDir=/usr/bin/
  3. sleep=2
  4.  
  5. pageCacheTables=(
  6. cache_pages
  7. cache_pagesection
  8. )
  9.  
  10. sites=(
  11. /var/www/sites/live/www.somedomain.tld
  12. /var/www/sites/live/www.someotherdomain.tld
  13. /var/www/sites/live/www.yetsomeotherdomain.tld
  14. )
  15.  
  16. len=${#sites[*]}
  17. pageCacheTablesLength=${#pageCacheTables[*]}
  18. i=0
  19. while [ $i -lt $len ]; do
  20. echo updating: ${sites[$i]}
  21. cd ${sites[$i]}
  22. rm typo3_src
  23. ln -s ../../sources/typo3_src-4.2.5 typo3_src
  24.  
  25. echo generating new key
  26. k=0
  27. key=''
  28. while [ $k -lt 96 ]; do
  29. key=$key$(head -100 /dev/urandom | md5sum | cut -c1)
  30. let k++
  31. done
  32. echo key: $key
  33. sed -i "s/\(\$TYPO3_CONF_VARS\['SYS']\['encryptionKey'] = \).*/\1'$key';/g" typo3conf/localconf.php
  34.  
  35. echo removing configuration cache
  36. rm -f typo3conf/temp_CACHED*
  37.  
  38. echo clearing page cache
  39. # For some insane reason some values are enclosed in double qotes
  40. database=$(grep "typo_db " typo3conf/localconf.php | tail -1 | sed "s/^[^']*'\([^']*\)'.*/\1/" | grep '$typo_db =')
  41. if [ -z "$database" ] ; then
  42. database=$(grep "typo_db " typo3conf/localconf.php | tail -1 | sed "s/^[^']*'\([^']*\)'.*/\1/")
  43. else
  44. database=$(grep "typo_db " typo3conf/localconf.php | tail -1 | sed "s/^[^\"]*\"\([^\"]*\)\".*/\1/")
  45. fi
  46. username=$(grep "typo_db_username " typo3conf/localconf.php | tail -1 | sed "s/^[^']*'\([^']*\)'.*/\1/" | grep '$typo_db_username =')
  47. if [ -z "$username" ] ; then
  48. username=$(grep "typo_db_username " typo3conf/localconf.php | tail -1 | sed "s/^[^']*'\([^']*\)'.*/\1/")
  49. else
  50. username=$(grep "typo_db_username " typo3conf/localconf.php | tail -1 | sed "s/^[^\"]*\"\([^\"]*\)\".*/\1/")
  51. fi
  52. password=$(grep "typo_db_password " typo3conf/localconf.php | tail -1 | sed "s/^[^']*'\([^']*\)'.*/\1/" | grep '$typo_db_password =')
  53. if [ -z "$password" ] ; then
  54. password=$(grep "typo_db_password " typo3conf/localconf.php | tail -1 | sed "s/^[^']*'\([^']*\)'.*/\1/")
  55. else
  56. password=$(grep "typo_db_password " typo3conf/localconf.php | tail -1 | sed "s/^[^\"]*\"\([^\"]*\)\".*/\1/")
  57. fi
  58. j=0
  59. while [ $j -lt $pageCacheTablesLength ];
  60. do
  61. nice -n 19 ${binDir}mysql --batch -u$username -p"$password" -D$database -e "TRUNCATE ${pageCacheTables[$j]}"
  62. nice -n 19 ${binDir}mysql --batch -u$username -p"$password" -D$database -e "ALTER TABLE ${pageCacheTables[$j]} auto_increment=1"
  63. let j++
  64. done
  65.  
  66. echo "done! Sleeping $sleep seconds . . ."
  67. sleep $sleep
  68.  
  69. echo
  70. let i++
  71. done

The highlighting script is not perfect yet when pasting in the RTE, please find a cut and paste version in the scripts section.

Happy upgrading!

Tobias 26 Jan 2009, 10:13
Thanks for sharing this script!
alex 27 Feb 2009, 10:19
hey, thx for the script.. - ;)
maholtz 4 Mar 2009, 13:02
great, thanks a lot
Christoph 8 Nov 2009, 09:32
Hi! I just got a link to your update script. Some time ago I also build a update script which fetches the source from a central rep and does some backup of the site. My script is designed to upgrade a single installation. Perhaps it's useful for somebody out there. You can find the script here:
https://www.abaton.at/support/typo3/typo3-update-script/
Script is called: get_typo3_update.sh

br, Christoph
Commenting is closed for this item