Collection of useful scripts for Tine 2.0

On this page I'd like to collect my bash scripts for Linux to administer Tine 2.0 installations.It will grow over the time whenever I'll find the time to put one of my helper scripts online.

Update Script

The following script assumes that your config file is located at /etc/tine20/config.inc.php, which will be put into place by a symbolic link. You have to configure the variables at the beginning, especially the location of your installation and the storage directory for old installations. And you have to tell the script the URL of your installation (to retrieve the current version).

The TRIGGER is a file which tells the webserver to show a site "maintenance work in progress". Additionally you need to specify which user and group the files need to have (USERGROUP) - separated by a dot. If you don't use SELINUX you have to delete the line beginning with chcon. Finally you have to setup mysqldump by a a mysql config file and specify the database to backup. If you don't use a standard php you have to midify this variable, too.

Short usage

Make the script executable by issuing chmod +x /usr/sbin/update-tine20. Then run the script, it asks you for the name of the backup-files (default is preset as current version) while the database dump is named by date/time (useful if you install one version more than once). Secondly it asks for the version to download (as default the latest official version is set). After it downloads the version and makes a database dump, the script will show you the size of the sql-dump (gzip) - after a while you have a pretty good feeling of how big a successful dump is. Until that stage everything is still untouched. If you press CTRL+C you may cancel other wise press enter which will update your version.

/usr/sbin/update-tine20

#!/bin/bash

TINE_DIR=/var/www/tine20
BACKUP_DIR=/root/tine-installationen
TINE_URL="https://tine20.mailserver2010.de/"

TRIGGER=/var/www/html/tine20-maintenance.trigger
USERGROUP=www.apache
SELINUX="unconfined_u:object_r:httpd_sys_content_t:s0"

DUMP_CNF="--defaults-file=/etc/tine20/my.cnf"
DUMP_DB=tine20
PHP=`which php`

# RESTORE BACKUP:
# zcat tine20-backup.sql.gz | tail -n +25 | mysql -u tine20 -p -Dtine20 --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;"

if [ ! -d "$BACKUP_DIR" ]; then
 echo "Folder for Installation Backups not found. "
 exit
fi

cd "$BACKUP_DIR"

OLDVERSION=$( curl -s "$TINE_URL" | grep X-Tine20-Version | cut -d '"' -f 4 )
read -p "Backup title [$OLDVERSION]: " OLD; echo
if [ "$OLD" == "" ]; then OLD=$OLDVERSION; fi

UPDATE_VERSION=$( curl -s "https://versioncheck.tine20.net/versionCheck/versionCheck.php" | cut -d ',' -f 2 | cut -d '"' -f 4 )
read -p "Tine 2.0 Version (for downloading) [$UPDATE_VERSION]: " VER; echo
if [ "$VER" == "" ]; then VER=$UPDATE_VERSION; fi

touch $TRIGGER

# remove lock and exit
function clean_up {
 rm -f $TRIGGER
 exit
}

if [ ! -f "tine20-allinone_$VER.tar.bz2" ]; then
 wget "http://packages.tine20.org/source/$VER/tine20-allinone_$VER.tar.bz2"
 if [ "$?" -ne "0" ]; then
  echo "ERROR: Download failed."
  clean_up
 fi
fi

echo "Backup Database ..."

BACKUP_FILE=tine20-`date +"%Y-%m-%dT%H%M%S"`.sql.gz

mysqldump $DUMP_CNF --hex-blob --complete-insert --routines --databases\
 --lock-tables --disable-keys --add-locks $DUMP_DB | gzip > $BACKUP_FILE

ls -lh $BACKUP_FILE

read -p "=== UPDATE TINE 2.0 NOW === Press Ctrl+C to abort! === Pess Enter to continue. ===" YESNO; echo

mkdir $OLD
mv $TINE_DIR/* $OLD/

tar -xf $BACKUP_DIR/tine20-allinone_$VER.tar.bz2 -C $TINE_DIR/
rm -f $TINE_DIR/config.inc.php.dist
#cp -a $OLD/config.inc.php $TINE_DIR/
ln -s /etc/tine20/config.inc.php $TINE_DIR/config.inc.php

chown $USERGROUP -R $TINE_DIR/*
chcon $SELINUX -R $TINE_DIR/*

#
# Update DB
#

cd $TINE_DIR/
$PHP setup.php --update

####
clean_up