2006-04-26 12:28:53 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
|
|
|
# this script will look for upgrade scripts in
|
|
|
|
# /usr/share/alternc/install/upgrades and execute them based on the
|
|
|
|
# extension
|
|
|
|
#
|
|
|
|
# usage:
|
|
|
|
# $0 oldvers, where oldvers is the version of the package previously
|
|
|
|
# installed
|
|
|
|
#
|
|
|
|
# an upgrade file is considered only if its basename is a version
|
|
|
|
# number greater than the $oldvers argument
|
|
|
|
|
|
|
|
# remove version from filename by stripping the extension
|
|
|
|
strip_ext() {
|
2012-11-09 13:43:34 +00:00
|
|
|
echo $1 | sed -e 's/\.[^.]*$//' -e 's/[a-z_]*$//'
|
2006-04-26 12:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# find the version from a filename by stripping everything but the extension
|
|
|
|
get_ext() {
|
|
|
|
echo $1 | sed 's/^.*\.\([^.]*\)$/\1/'
|
|
|
|
}
|
|
|
|
|
|
|
|
oldvers=$1
|
|
|
|
|
|
|
|
if [ -z "$oldvers" -o "$oldvers" = '<unknown>' ]; then
|
|
|
|
# this is not an upgrade
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-03-06 09:23:09 +00:00
|
|
|
#Checking the form of the version variable. it should be x.x.x with x as a digit.
|
|
|
|
#If it is not we correct it.
|
|
|
|
if echo $oldvers | grep -qi '[0-9]\.[0-9]\.[0-9].*' ; then
|
|
|
|
echo upgrading from : $oldvers
|
|
|
|
else
|
|
|
|
old_ifs="$IFS"
|
|
|
|
IFS='~'
|
|
|
|
read PART1 PART2 <<EOF
|
|
|
|
$oldvers
|
|
|
|
EOF
|
|
|
|
IFS="$old_ifs"
|
|
|
|
oldvers=$PART1".0"
|
|
|
|
echo upgrading from : $oldvers
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2006-04-26 12:28:53 +00:00
|
|
|
. /etc/alternc/local.sh
|
|
|
|
|
|
|
|
# the upgrade script we are considering
|
|
|
|
extensions="*.sql *.sh *.php"
|
|
|
|
cd /usr/share/alternc/install/upgrades
|
2013-02-18 11:45:17 +00:00
|
|
|
for file in $( ls $extensions | sort -n ) ; do
|
2006-04-26 12:28:53 +00:00
|
|
|
if [ -r $file ]; then
|
|
|
|
# the version in the filename
|
|
|
|
upvers=`strip_ext $file`
|
|
|
|
# the extension
|
|
|
|
ext=`get_ext $file`
|
|
|
|
if dpkg --compare-versions $upvers gt $oldvers; then
|
|
|
|
echo running upgrade script $file
|
|
|
|
# run the proper program to interpret the upgrade script
|
|
|
|
case "$ext" in
|
|
|
|
sql)
|
2008-10-07 16:49:05 +00:00
|
|
|
mysql --defaults-file=/etc/alternc/my.cnf -f \
|
2006-04-26 12:28:53 +00:00
|
|
|
< $file || true
|
|
|
|
;;
|
|
|
|
php)
|
2007-04-18 16:55:34 +00:00
|
|
|
php -q $file || true
|
2006-04-26 12:28:53 +00:00
|
|
|
;;
|
|
|
|
sh)
|
|
|
|
sh $file || true
|
|
|
|
;;
|
2013-02-08 11:20:04 +00:00
|
|
|
*)
|
2013-09-25 09:50:53 +00:00
|
|
|
# Do nothing
|
2013-02-08 11:20:04 +00:00
|
|
|
;;
|
2006-04-26 12:28:53 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|