File tine20-admin.sh of Package tine20

#!/bin/sh
#
# Manage tine20 installations
#
# (c) Johannes Weberhofer, Weberhofer GmbH 2011, 2015
#
# This script is licensed under the AGPL
#

BASEURL='https://packages.tine20.org/source'
TINE20SOURCE='/usr/share/tine20'
INSTALLATIONS='/etc/tine20-installations'
MAININST='/var/lib/tine20'
APACHEUSER='wwwrun'
TINE20_DIRS='webroot session tmp log files'

#
# check input parameters
#
ERR=0
HELP=0
TARGETDIR=''
BUILD=0
PREFIX=''
COMMAND='install'
SCRIPTDIR=`dirname $0`

while [ $# -ge 1 ] ; do
	case "$1" in
	--help)
		HELP=1
		;;
	help)
	        HELP=1
	        ;;
	install)
		shift
		COMMAND='install'
		if [ -d `dirname "$1"` ] ; then
			TARGETDIR=`readlink -f "$1"`
		else
			echo "Invalid directory $1" 1>&2
			ERR=2
		fi
		;;
	addremove)
		shift
                COMMAND='addremove'
                ;;
	update)
		shift
		COMMAND='update'
		;;
	--prefix)
		shift
		if [ -d "$1" ] ; then
			PREFIX=`readlink -f "$1"`"/"
			BUILD=1
		else
			echo "Invalid prefix $1" 1>&2
			ERR=3
		fi
		;;
	*)
	        echo "unknown option: $1" 1>&2
	        ERR=1
	        ;;
	esac
	shift
done

if [ ! -d $PREFIX$TINE20SOURCE ] ; then
	echo "Tine20 source directory does not exist: $TINE20SOURCE" 1>&2
	ERR=4
fi

if [ "$COMMAND" == "install" ] ; then
	if ( [ -z "$TARGETDIR" ] || [ ! -d `dirname "$TARGETDIR"` ] ) ; then
		echo "Target-directory has not been set correctly!" 1>&2
		echo ""
		ERR=6
	fi
fi

#
# usage section
#
if ( [ $HELP -eq 1 ] || [ $ERR -ne 0 ] ) ; then
	echo \
"usage: "`basename $0`" [install DIR [--prefix DIR] |update|help]

Create or update a Tine20-installation based on an Apache/Alias configuration

help             display this text

install           Install into installation directory
 DIR              The installation's root directory; the structure will be
		  placed into this directory
 --prefix DIR     For packaging-purposes this directory will be prefixed.
		  This feature should not be used in production systems.

addremove         correct added and removed modules.

update            Update all current installations.
"
	exit $ERR
fi

TARGETDIR=`echo "$TARGETDIR" | sed -e 's/\/\//\//g ; s/\/$//'`

function doInstall() {
	#create hosting-relevant directories
	for DIR in $TINE20_DIRS ; do
		mkdir -p "$PREFIX$TARGETDIR/$DIR"
		if [ $BUILD -eq 0 ] ; then
			chown $APACHEUSER. "$PREFIX$TARGETDIR/$DIR"
		fi
	done

	# Create tine20 symlinks
	for CFILE in `ls $PREFIX$TINE20SOURCE/` ; do
		ln -s "$TINE20SOURCE/$CFILE" "$PREFIX$TARGETDIR/webroot/"
	done

	if [ $BUILD -eq 0 ] ; then
		echo $TARGETDIR/webroot >> "$INSTALLATIONS"
	fi
	# Prepeare the configuration file
	echo "<?php
return array (
  'database' =>
  array (
    'host' => 'ENTER DATABASE HOSTNAME',
    'dbname' => 'ENTER DATABASE NAME',
    'username' => 'ENTER DATABASE USERNAME',
    'password' => 'ENTER DATABASE PASSWORD',
    'adapter' => 'pdo_mysql',
    'tableprefix' => 'tine20_',
    'port' => '',
  ),
  'setupuser' =>
  array (
    'username' => 'SETUP USERNAME',
    'password' => 'SETUP PASSWORD',
  ),
  'logger' =>
  array (
    'active' => false,
    'filename' => '$TARGETDIR/log/tine20.log',
    'priority' => 6,
  ),
  'caching' =>
  array (
    'active' => true,
    'path' => '$TARGETDIR/tmp',
    'lifetime' => 120,
  ),
  'session' =>
  array (
    'path' => '$TARGETDIR/session',
    'lifetime' => 86400,
    'backend' => 'File',
    'host' => 'localhost',
    'port' => 6379,
  ),
  'tmpdir' => '$TARGETDIR/tmp',
  'filesdir' => '$TARGETDIR/files',
  'mapPanel' => 1,
);" > "$PREFIX$TARGETDIR/webroot/config.inc.php"

	echo "### Suggested Alias-based tine20-configuration
	### Have a look to the documentation in:
	### /usr/share/doc/packages/tine20/README.DISTRIBUTION
	#Alias   /tine20           \"$TARGETDIR/webroot\"

	### The rewrite-engine is needed for ActiveSync or DAV services
	#RewriteEngine on
	#RewriteBase /
	#
	### ActiveSync configuration
	#RewriteRule ^Microsoft-Server-ActiveSync /tine20/index.php?frontend=activesync [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
	#
	### OpenID
	#RewriteRule ^users/(.*)   /tine20/index.php?frontend=openid&username=$1 [L,QSA]
	#
	### WebDAV / CalDAV / CardDAV configuration
	#RewriteCond %{REQUEST_METHOD} !^(GET|POST)$
	#RewriteRule ^$            /tine20/index.php?frontend=webdav [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
	#RewriteRule ^addressbooks /tine20/index.php?frontend=webdav [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
	#RewriteRule ^calendars    /tine20/index.php?frontend=webdav [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
	#RewriteRule ^principals   /tine20/index.php?frontend=webdav [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
	#RewriteRule ^webdav       /tine20/index.php?frontend=webdav [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]

	<Directory $TARGETDIR>
		Allow From All
		Options +FollowSymLinks
		php_admin_value session.gc_maxlifetime 86400
		php_admin_value memory_limit 128M
		php_admin_value upload_max_filesize 20M
		php_admin_value post_max_size 20M
		php_admin_flag display_errors off
		php_admin_flag log_errors on
		php_admin_value session.save_path "$TARGETDIR/session"
		php_admin_value upload_tmp_dir "$TARGETDIR/tmp"
		php_admin_value open_basedir "$TARGETDIR:/usr/share/tine20:/usr/share/php7/PEAR"
		php_admin_value max_execution_time 120
		php_admin_value max_input_time 120
	</Directory>
"
}

function doAddRemove() {
	WEBROOT="$1"
	if [ -d "$WEBROOT" ] ; then
		# remove invalid symlinks
		pushd "$WEBROOT" > /dev/null
		for CFILE in `ls` ; do
			if [ -L "$CFILE" ] ; then
				if [ ! -d "$CFILE" ] ; then
					rm "$CFILE"
				fi
			fi
		done
		popd > /dev/null
		# create missing symlinks
		pushd "$TINE20SOURCE" > /dev/null
		for CFILE in `ls` ; do
			if [ "$CFILE" != "admintools" ] ; then
				if [ ! -L "$WEBROOT/$CFILE" ] ; then
					rm -rf "$WEBROOT/$CFILE"
				fi
				if [ ! -e "$WEBROOT/$CFILE" ] ; then
					ln -s "$TINE20SOURCE/$CFILE" "$WEBROOT/"
				fi
			fi
		done
		popd > /dev/null
	fi
}

function doUpdate() {
	WEBROOT="$1"
	if [ -d "$WEBROOT" ] ; then
		echo "Updating tine20 installation in $WEBROOT: "
		# remove old caches
		if [ -d "$WEBROOT/../tmp" ] ; then
			rm -rf "$WEBROOT/../tmp/*"
		fi
		# update installation
		if [ -x "/usr/bin/php" ] ; then
			PHP="/usr/bin/php"
		else 
			if [ -x "/usr/bin/php5" ] ; then
				PHP="/usr/bin/php5"
			fi
		fi
		if [ -x "$PHP" ] ; then
			pushd "$WEBROOT" > /dev/null
			# update only when config.inc.php exists and 
			# update only, when 'ENTER DATABASE HOSTNAME' is no longer present
			if [ -e config.inc.php ] ; then
				grep -q 'ENTER DATABASE HOSTNAME' config.inc.php
				if [ "$?" -ne 0 ] ; then
					"$PHP" setup.php --update
				fi
			else
				echo "No configuration file exists in $WEBROOT" 1>&2
			fi
			popd > /dev/null
		fi
	else
		echo "Invilid tine20 location: $WEBROOT" 1>&2
	fi
}

if [ "$COMMAND" == "install" ] ; then
	if [ -d "$PREFIX$TARGETDIR" ] ; then
		echo "Installation exists in $PREFIX$TARGETDIR" 1>&2
		ERR=2
	else
		doInstall
	fi
fi

if [ "$COMMAND" == "addremove" ] ; then
	doAddRemove "$MAININST/webroot"
	if [ -e "$INSTALLATIONS" ] ; then
		while read INST ; do
			if [ "$INST" != "$MAININST" ] ; then
				doAddRemove "$INST"
			fi
		done < "$INSTALLATIONS"
	fi
fi

if [ "$COMMAND" == "update" ] ; then
	doAddRemove "$MAININST/webroot"
	doUpdate "$MAININST/webroot"
	if [ -e "$INSTALLATIONS" ] ; then
		while read INST ; do
			if [ "$INST" != "$MAININST" ] ; then
				doAddRemove "$INST"
				doUpdate "$INST"
			fi
		done < "$INSTALLATIONS"
	fi
fi
openSUSE Build Service is sponsored by