TYPO free

home

fighting for TYPO free code

TYPO3 mass upgrade

TYPO3 mass update script

  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