#!/bin/sh
# $Id$
# vim:set ts=2 sw=2 et:

# arg 1:  the new package version
pre_install() {
 /bin/true
}

# arg 1:  the new package version
post_install() {
  ln -s /opt/sonar/bin/sonar.sh /etc/rc.d/sonar

  echo ">>> Creating user and group and setting permissions..."
  getent group sonar > /dev/null || usr/sbin/groupadd sonar
  getent passwd sonar > /dev/null || usr/sbin/useradd -c \
        'Sonar Code Quality metric system' -g sonar -d '/opt/sonar' \
        --system -s /bin/bash sonar &> /dev/null

  cd opt/sonar

  chown -R sonar:sonar * 
  chown -R root:sonar /var/log/sonar
  chmod -R 775 /var/log/sonar

  chown -R sonar:sonar /var/run/sonar

  ln -s /etc/sonar conf

  cat << EOF
>>>
>>> This package is part of the ArchLinux Development Stack, vist
>>> http://openpario.mime.oregonstate.edu:3000/projects/archdevstack for
>>> more information.
>>>
>>> Sonar can now be started via /opt/sonar/bin/sonar.sh or via
>>> /etc/rc.d/sonar. 
>>> 
>>> Sonar will run by default using the Derby embedded database, to change this
>>> to another database (e.g. MySql), please edit the 
>>> /opt/sonar/conf/sonar.properties accordingly.
>>>  
>>> Sonar is running by default on port 9000 and is bound to all interfaces,
>>> you can change this in the file /etc/sonar/sonar.properties. 
>>>
>>> For additional information please visit http://sonar.codehaus.org
>>> 
>>> If you are upgrading from an earlier version, please read http://sonar.codehaus.org/
>>> and browse to http://localhost:9000/setup.
EOF
}

# arg 1:  the new package version
# arg 2:  the old package version
pre_upgrade() {
 /bin/true
}

# arg 1:  the new package version
# arg 2:  the old package version
post_upgrade() {
  /bin/true
}

# arg 1:  the old package version
pre_remove() {
 /bin/true
}

# arg 1:  the old package version
post_remove() {
  getent passwd sonar > /dev/null && usr/sbin/userdel sonar &>/dev/null
  getent group sonar > /dev/null && usr/sbin/groupdel sonar &>/dev/null  

	if [ -x /var/run/sonar ] ; then
	    rm -r /var/run/sonar
	fi  
}

