2014-07-04 14:04:17 +00:00
#!/bin/bash
2006-04-26 12:28:53 +00:00
# this script will look for upgrade scripts in
# /usr/share/alternc/install/upgrades and execute them based on the
# extension
#
# 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/'
}
2014-03-27 15:43:36 +00:00
# Reading the current version in the DB.
# If the DB exist but the alternc_status table doesn't, we will initialize it below
# In that case we search where we upgrade from in /var/lib/alternc/backups/lastversion from debian.postinstall script
2014-03-28 13:56:49 +00:00
oldvers = "`mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -e " SELECT value FROM alternc_status WHERE name = 'alternc_version' " 2>/dev/null||true`"
2014-03-27 15:43:36 +00:00
if [ -z " $oldvers " ]
then
# no version number, we check from /var/lib/alternc
if [ -f "/var/lib/alternc/backups/lastversion" ]
then
oldvers = "`cat /var/lib/alternc/backups/lastversion`"
2014-03-28 14:06:59 +00:00
# this is a *version number*, not a *last upgrade script* we have this *border case*
if [ " $oldvers " = "3.1" ]
then
2014-07-04 14:04:17 +00:00
oldvers = "3.1.0~c.sh"
2014-03-28 14:06:59 +00:00
fi
2014-03-27 15:43:36 +00:00
else
echo "##############################################"
echo "# NO VERSION FOUND TO UPGRADE FROM, ABORTING #"
echo "##############################################"
exit 1
fi
2006-04-26 12:28:53 +00:00
fi
2014-03-27 15:43:36 +00:00
if [ " $oldvers " = '<unknown>' ]
then
# this is not an upgrade
exit 0
2013-03-06 09:23:09 +00:00
fi
2014-03-27 15:43:36 +00:00
# Thanks to that, we handle alternc older than 3.1.0~b.php
mysql --defaults-file= /etc/alternc/my.cnf -e "CREATE TABLE IF NOT EXISTS alternc_status (name VARCHAR(48) NOT NULL DEFAULT '',value LONGTEXT NOT NULL,PRIMARY KEY (name),KEY name (name) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;"
mysql --defaults-file= /etc/alternc/my.cnf -e " INSERT IGNORE INTO alternc_status SET name='alternc_version',value=' $oldvers '; "
2013-03-06 09:23:09 +00:00
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 `
2017-10-08 11:43:57 +00:00
if dpkg --compare-versions " $upvers " gt " $oldvers " ; then
2014-03-27 15:43:36 +00:00
echo " Running upgrade script $file "
2006-04-26 12:28:53 +00:00
# run the proper program to interpret the upgrade script
case " $ext " in
2014-03-27 15:43:36 +00:00
sql)
2014-03-27 16:08:20 +00:00
( echo "BEGIN;"
2014-03-27 15:43:36 +00:00
cat $file
2014-03-27 16:08:20 +00:00
echo " UPDATE alternc_status SET value=' $file ' WHERE name='alternc_version'; "
echo "COMMIT;"
2014-07-04 14:17:07 +00:00
) | mysql --defaults-file= /etc/alternc/my.cnf -f
2014-03-27 15:43:36 +00:00
; ;
php)
php -q $file
2015-04-29 08:45:40 +00:00
echo " UPDATE alternc_status SET value=' $file ' WHERE name='alternc_version'; " |
mysql --defaults-file= /etc/alternc/my.cnf -f
2014-03-27 15:43:36 +00:00
; ;
sh)
2014-03-27 17:39:28 +00:00
bash $file
2015-04-29 08:45:40 +00:00
echo " UPDATE alternc_status SET value=' $file ' WHERE name='alternc_version'; " |
mysql --defaults-file= /etc/alternc/my.cnf -f
2014-03-27 15:43:36 +00:00
; ;
*)
echo " skipping $file , not recognized ! "
; ;
2006-04-26 12:28:53 +00:00
esac
fi
fi
done
2014-03-27 15:43:36 +00:00