#!/bin/sh -e
# preinst script for perforce-swarm
#
# see: dh_installdeb(1)
# 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
ME="${0##*/}"
#echo "###########################"
#echo "[$ME] [$*]"
THISPKG="helix-swarm"
PERFORCE_ROOT="/opt/perforce"
PERFORCE_CFGDIR="$PERFORCE_ROOT/etc"
SWARM_ROOT="$PERFORCE_ROOT/swarm"
SWARM_DATADIR="$SWARM_ROOT/data"
SWARM_SBINDIR="$SWARM_ROOT/sbin"
SWARM_CONFIG="$SWARM_DATADIR/config.php"
APACHE_SITESDIR="/etc/apache2/sites-available"
SWARM_VHOST="$APACHE_SITESDIR/perforce-swarm-site.conf"
APACHE_USER="www-data"
APACHE_GROUP="$APACHE_USER"
CRON_DIR="/etc/cron.d"
CRON_SCRIPT="$CRON_DIR/helix-swarm"
CRON_SCRIPT_OLD="$CRON_DIR/perforce-swarm"
CRON_CONFIG="$PERFORCE_CFGDIR/swarm-cron-hosts.conf"
PHPINI_DIR="/etc/php5/conf.d"
P4PHP_INI="${PHPINI_DIR}/perforce.ini"
check_old_cron()
{
if [ -r $CRON_SCRIPT_OLD ]; then
echo "$THISPKG: Removing obsoleted cronfile..."
rm $CRON_SCRIPT_OLD
fi
return 0
}
upgrade_20142()
{
echo "$THISPKG: Handling upgrade exceptions for Swarm 2014.2..."
upgrade_good=0
while true; do
# HACK: Recreate the cron job in its original 2014.2 form so it can be upgraded without user input
cat << __CRON_SCRIPT__ > "$CRON_SCRIPT"
#
# Regular cron job for the perforce-swarm-rXX.Y package
#
* * * * * nobody [ -x /usr/bin/wget ] && /usr/bin/wget -qO /dev/null -T5 http://localhost/queue/worker
__CRON_SCRIPT__
if [ ! -r "$SWARM_CONFIG" ]; then
error_msg="Could not find Swarm config file [$SWARM_CONFIG]"
break
fi
# Obtain the Swarm hostname to create Swarm cron job
swarm_hostname="$(\
egrep -v "^\s*(#|//).*" "$SWARM_CONFIG" |
tr -d '\n' |
sed -rne "s#.*['\"]environment['\"]\s*=>\s*array\s*\(\s*['\"]hostname['\"]\s*=>\s*['\"]([^'\"]*)['\"].*#\1#p" \
)"
if [ -z "$swarm_hostname" ]; then
error_msg="Could not obtain Swarm hostname from Swarm config file [$SWARM_CONFIG]"
break
fi
echo "$THISPKG: -obtained Swarm hostname from Swarm config file: [$swarm_hostname]"
mkdir -p "$(dirname "$CRON_CONFIG")"
cat << __CRON_CONFIG__ > "$CRON_CONFIG"
# Perforce Swarm cron configuration
#
# Format (one per line):
# [http[s]://]<swarm-host>[:<port>]
#
$swarm_hostname
__CRON_CONFIG__
echo "$THISPKG: -wrote Swarm cron config [$CRON_CONFIG]"
upgrade_good=1
break
done
if [ $upgrade_good -ne 1 ]; then
cat << __UPGRADE_WARNING__
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! $THISPKG: WARNING: Unable to automatically upgrade from $from_version_major
!! Problem:
!! $error_msg
!!
!! This means you will need to reconfigure Swarm after the upgrade of
!! the package completes.
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
__UPGRADE_WARNING__
fi
return 0
}
case "$1" in
install)
check_old_cron
;;
upgrade)
from_version="$2"
from_version_major="${from_version%%-*}"
echo "$THISPKG: Upgrading from $from_version"
check_old_cron
[ "$from_version_major" = "2014.2" ] && upgrade_20142
;;
abort-upgrade)
;;
*)
echo "$ME 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
# |
Change |
User |
Description |
Committed |
|
#1
|
18730 |
Liz Lam |
clean up code and move things around |
|
|