sintonia/campcaster/etc/debian/campcaster-station.preinst

117 lines
3.2 KiB
Bash

#! /bin/sh
# preinst script for livesupport
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
# * <new-preinst> `upgrade' <old-version>
# * <old-preinst> `abort-upgrade' <new-version>
#
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#-------------------------------------------------------------------------------
# Function to check for a group to be available, and the ability
# to set files to belong into that group
#
# @param $1 the group to check
# @return 0 if the groups id OK, non-0 otherwise
#-------------------------------------------------------------------------------
check_group_permission() {
group_tmp_file=/tmp/ls_group_check.$$
touch $group_tmp_file
test_result=`chgrp $1 $group_tmp_file 2> /dev/null`
if [ $? != 0 ]; then
rm -f $group_tmp_file;
echo "Unable to use apache deamon group $1.";
echo "Please check if $1 is a correct user group.";
return 1;
fi
rm -f $group_tmp_file;
echo "Apache daemon group $1 OK.";
return 0;
}
#-------------------------------------------------------------------------------
# Function to check for the existence of an executable on the PATH
#
# @param $1 the name of the exectuable
# @return 0 if the executable exists on the PATH, non-0 otherwise
#-------------------------------------------------------------------------------
check_exe() {
if [ -x "`which $1 2> /dev/null`" ]; then
echo "Exectuable $1 found...";
return 0;
else
echo "Exectuable $1 not found...";
return 1;
fi
}
#-------------------------------------------------------------------------------
# Function to check for a PEAR module
#
# @param $1 the name of the PEAR module
# @return 0 if the module is available, non-0 otherwise
#-------------------------------------------------------------------------------
check_pear_module() {
test_result=`pear info $1`
if [ $? = 0 ]; then
echo "PEAR module $1 found...";
return 0;
else
echo "PEAR module $1 not found...";
return 1;
fi
}
#-------------------------------------------------------------------------------
# Variables
#-------------------------------------------------------------------------------
apache_group=www-data
case "$1" in
install|upgrade)
echo "Checking for required tools..."
check_exe "sed" || exit 1;
check_exe "psql" || exit 1;
check_exe "php" || exit 1;
check_exe "pear" || exit 1;
check_exe "odbcinst" || exit 1;
echo "Checking for validity of apache daemon group $apache_group...";
check_group_permission $apache_group || exit 1;
if [ "$1" = "upgrade" ]; then
/etc/init.d/campcaster-scheduler stop || true
/etc/init.d/campcaster-scheduler kill || true
fi
;;
abort-upgrade)
;;
*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0