3 # this script will look for upgrade scripts in
4 # /usr/share/alternc/install/upgrades and execute them based on the
7 # an upgrade file is considered only if its basename is a version
8 # number greater than the $oldvers argument
10 # remove version from filename by stripping the extension
12 echo $1 | sed -e 's/\.[^.]*$//' -e 's/[a-z_]*$//'
15 # find the version from a filename by stripping everything but the extension
17 echo $1 | sed 's/^.*\.\([^.]*\)$/\1/'
21 # Reading the current version in the DB.
22 # If the DB exist but the alternc_status table doesn't, we will initialize it below
23 # In that case we search where we upgrade from in /var/lib/alternc/backups/lastversion from debian.postinstall script
24 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`"
27 # no version number, we check from /var/lib/alternc
28 if [ -f "/var/lib/alternc/backups/lastversion" ]
30 oldvers="`cat /var/lib/alternc/backups/lastversion`"
31 # this is a *version number*, not a *last upgrade script* we have this *border case*
32 if [ "$oldvers" = "3.1" ]
37 echo "##############################################"
38 echo "# NO VERSION FOUND TO UPGRADE FROM, ABORTING #"
39 echo "##############################################"
44 if [ "$oldvers" = '<unknown>' ]
46 # this is not an upgrade
50 # Thanks to that, we handle alternc older than 3.1.0~b.php
51 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;"
52 mysql --defaults-file=/etc/alternc/my.cnf -e "INSERT IGNORE INTO alternc_status SET name='alternc_version',value='$oldvers';"
54 . /etc/alternc/local.sh
56 # the upgrade script we are considering
57 extensions="*.sql *.sh *.php"
58 cd /usr/share/alternc/install/upgrades
59 for file in $( ls $extensions | sort -n ) ; do
61 # the version in the filename
62 upvers=`strip_ext $file`
65 if dpkg --compare-versions "$upvers" gt "$oldvers"; then
66 echo "Running upgrade script $file"
67 # run the proper program to interpret the upgrade script
72 echo "UPDATE alternc_status SET value='$file' WHERE name='alternc_version';"
74 ) | mysql --defaults-file=/etc/alternc/my.cnf -f
78 echo "UPDATE alternc_status SET value='$file' WHERE name='alternc_version';" |
79 mysql --defaults-file=/etc/alternc/my.cnf -f
83 echo "UPDATE alternc_status SET value='$file' WHERE name='alternc_version';" |
84 mysql --defaults-file=/etc/alternc/my.cnf -f
87 echo "skipping $file, not recognized !"