hets_script revision 6eb335aba416a77cb49ecd390fa3fee7aed55e2e
a9de0a2f34860a24f457c777e740b7e87e6e3827Christian Maeder#!/bin/sh -e
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian Maeder#
306763c67bb99228487345b32ab8c5c6cd41f23cChristian Maeder# this script is part of Hets
3a6c7a7ff823616f56cd3d205fc44664a683effdChristian Maeder# - Heterogenous Tool Set -
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian Maeder#
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian Maeder#
306763c67bb99228487345b32ab8c5c6cd41f23cChristian Maeder# Handling switches
306763c67bb99228487345b32ab8c5c6cd41f23cChristian Maeder# -update
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder# -revert
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maeder#
44fb55f639914f4f531641f32dd4904f15c510a4Till Mossakowskiif [ "$#" = "1" ]; then
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski case "$1" in
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski
af0cbe339851fc558d2b18cde3666981325e667cTill Mossakowski -update)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski if [ "`id -u`" = "0" ]; then
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski apt-get install hets-core
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder export HETS_DAILY_VERSION=`date +%Y%m%d`
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maederpython << __END__
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederimport fcntl, os, sys, subprocess;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedersubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedersubprocess.STDOUT=sys.stdout
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedersubprocess.STDERR=sys.stderr
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maederclass UpdateFailure(Exception):
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder def __init__(self, msg):
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder self.value = msg
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder def __str__(self):
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder return repr(self.msg)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedertry:
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder f = open("/var/lib/dpkg/lock", 'w')
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder fcntl.lockf(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder print "Retrieving latest Hets library...",
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder sys.stdout.flush()
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder subprocess.call("rm -r -f /tmp/hets*",shell=True,stderr=subprocess.DEVNULL)
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder try:
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder subprocess.check_call(["svn","export", "--force", "-q",
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder "https://svn-agbkb.informatik.uni-bremen.de/Hets-lib/trunk","/tmp/hets-lib"],
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder stdout=subprocess.STDOUT,stderr=subprocess.STDERR)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski except subprocess.CalledProcessError:
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski raise UpdateFailure("Failed to retrieve latest Hets library!")
922819b1c2d383a0fa5d70e1c4aa76667e2f1ca3Christian Maeder print "Done"
63324a97283728a30932828a612c7b0b0f687624Christian Maeder print "Retrieving latest Hets binary...",
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian Maeder sys.stdout.flush()
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder subprocess.call(["rm", "-f", "/tmp/hets-$HETS_DAILY_VERSION*"],stderr=subprocess.DEVNULL)
53310804002cd9e3c9c5844db3b984abcf001788Christian Maeder try:
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder if os.uname()[4] == "x86_64":
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maeder subprocess.check_call("curl -sG http://www.informatik.uni-bremen.de/agbkb/forschung/formal_methods/CoFI/hets/linux64/daily/hets.bz2 \
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maeder > /tmp/hets-$HETS_DAILY_VERSION.bz2",shell=True,stdout=sys.stdout,stderr=sys.stderr)
63324a97283728a30932828a612c7b0b0f687624Christian Maeder else:
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder subprocess.check_call("curl -sG http://www.informatik.uni-bremen.de/agbkb/forschung/formal_methods/CoFI/hets/linux/daily/hets.bz2 \
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski > /tmp/hets-$HETS_DAILY_VERSION.bz2",shell=True,stdout=sys.stdout,stderr=sys.stderr)
59fa9b1349ae1e001d996da732c4ac805c2938e2Christian Maeder except subprocess.CalledProcessError:
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski raise UpdateFailure("Failed to retrieve latest Hets binary...")
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski try:
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski subprocess.check_call(["bunzip2", "/tmp/hets-$HETS_DAILY_VERSION.bz2"],
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski stdout=subprocess.STDOUT,stderr=subprocess.STDERR)
53310804002cd9e3c9c5844db3b984abcf001788Christian Maeder subprocess.call(["chmod","+x","/tmp/hets-$HETS_DAILY_VERSION"])
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski subprocess.check_call(["/tmp/hets-$HETS_DAILY_VERSION","-V"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski except subprocess.CalledProcessError:
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski raise UpdateFailure("Retrieved Hets binary seems broken. Please try again later!")
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski print "Done"
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski print "Creating Backups ...",
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski sys.stdout.flush()
3a87487c048b275c56e502c4a933273788e8d0bbChristian Maeder try:
2b565fe5cfb9f99857fd25b52304758d8544e266Mihai Codescu subprocess.check_call(["mv", "/usr/lib/hets/hets",
2b565fe5cfb9f99857fd25b52304758d8544e266Mihai Codescu "/usr/lib/hets/hets.bak"],stderr=subprocess.DEVNULL)
2b565fe5cfb9f99857fd25b52304758d8544e266Mihai Codescu subprocess.check_call(["mv","/usr/lib/hets/hets-lib",
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski "/usr/lib/hets/hets-lib.bak"],stderr=subprocess.DEVNULL)
2ecf6cfb90e84d40f224cda5d92c191182c976d2Till Mossakowski except subprocess.CalledProcessError:
2ecf6cfb90e84d40f224cda5d92c191182c976d2Till Mossakowski raise UpdateFailure("Couldn't create backups. Please make sure the package hets-core is properly installed!")
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski print "Done"
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski print "Installing new files ...",
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski sys.stdout.flush()
2ecf6cfb90e84d40f224cda5d92c191182c976d2Till Mossakowski try:
bba825b39570777866d560bfde3807731131097eKlaus Luettich subprocess.check_call(["install", "-m", "755", "/tmp/hets-$HETS_DAILY_VERSION",
bba825b39570777866d560bfde3807731131097eKlaus Luettich "/usr/lib/hets/hets"],stderr=subprocess.DEVNULL)
53310804002cd9e3c9c5844db3b984abcf001788Christian Maeder subprocess.check_call(["cp", "-r", "/tmp/hets-lib", "/usr/lib/hets/hets-lib"])
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski except subprocess.CalledProcessError:
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder subprocess.call(["rm", "-r", "-f", "/usr/lib/hets/hets",
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski "/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
5d6e7ea3bd14fc987436cff0f542393ea9ba34bbTill Mossakowski print "Done"
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maederexcept IOError:
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder print "Could not acquire lock \"/var/lib/dpkg/lock\""
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder sys.exit(0)
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiexcept UpdateFailure as e:
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski print "Experienced update failure: ", e.value
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski subprocess.call(["mv", "/usr/lib/hets/hets.bak",
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maeder "/usr/lib/hets/hets"],stderr=subprocess.DEVNULL)
0647a6c86b231e391826c7715338ba29cb4934c0Christian Maeder subprocess.call(["mv","/usr/lib/hets/hets-lib.bak",
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maeder "/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
a975722baf6fee1ca3e67df170c732c4abd0a945Christian Maederfinally:
a975722baf6fee1ca3e67df170c732c4abd0a945Christian Maeder if not os.path.exists("/usr/lib/hets/hets-lib"):
a975722baf6fee1ca3e67df170c732c4abd0a945Christian Maeder subprocess.call(["mv","/usr/lib/hets/hets-lib.bak","/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
a975722baf6fee1ca3e67df170c732c4abd0a945Christian Maeder if not os.path.exists("/usr/lib/hets/hets"):
63324a97283728a30932828a612c7b0b0f687624Christian Maeder subprocess.call(["mv","/usr/lib/hets/hets.bak","/usr/lib/hets/hets"],stderr=subprocess.DEVNULL)
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu subprocess.call("rm -r -f /tmp/hets*",shell=True,stderr=subprocess.DEVNULL)
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu sys.exit(0)
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu__END__
b4e202184f6977662c439c82866fe93f06cebe41Christian Maeder echo "Updated to `hets -V`."
830e14495f9cac8e154dd4813dae010166f33d09Mihai Codescu exit 0
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu else
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescu echo "Root access required for \"hets -update\""
f2c050360525df494e6115073b0edc4c443a847cMihai Codescu exit 0
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maeder fi
f2c050360525df494e6115073b0edc4c443a847cMihai Codescu ;;
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maeder
f2c050360525df494e6115073b0edc4c443a847cMihai Codescu -revert)
0e51a998b1b213654c7a9eca451562041971f100Till Mossakowski if [ "`id -u`" = "0" ]; then
0e51a998b1b213654c7a9eca451562041971f100Till Mossakowski if [ -f /usr/lib/hets/hets.bak ]; then
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maederpython << __END__
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maederimport fcntl, os, sys, subprocess;
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maedersubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR)
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maedersubprocess.STDOUT=sys.stdout
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maedersubprocess.STDERR=sys.stderr
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederclass UpdateFailure(Exception):
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder def __init__(self, msg):
da955132262baab309a50fdffe228c9efe68251dCui Jian self.value = msg
da955132262baab309a50fdffe228c9efe68251dCui Jian def __str__(self):
bba825b39570777866d560bfde3807731131097eKlaus Luettich return repr(self.msg)
da955132262baab309a50fdffe228c9efe68251dCui Jian
bba825b39570777866d560bfde3807731131097eKlaus Luettichtry:
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder f = open("/var/lib/dpkg/lock", 'w')
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maeder fcntl.lockf(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder print "Reverting to previous Hets binary... ",
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder try:
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder subprocess.check_call(["mv", "/usr/lib/hets/hets.bak",
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder "/usr/lib/hets/hets"],stderr=subprocess.DEVNULL);
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder if os.path.exists("/usr/lib/hets/hets-lib.bak"):
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder subprocess.check_call(["rm", "-r", "-f", "/usr/lib/hets/hets-lib"],
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maeder stderr=subprocess.DEVNULL)
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder subprocess.check_call(["mv", "/usr/lib/hets/hets-lib.bak",
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder "/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder except subprocess.CalledProcessError:
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder raise UpdateFailure("Couldn't restore backup!")
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder print "Done"
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederexcept IOError:
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder print "Could not acquire lock \"/var/lib/dpkg/lock\""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder sys.exit(0)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederexcept UpdateFailure as e:
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder print "Experienced revert failure: ", e.value
64e1905404e5135e98a26d2ab4150b6764956576Christian Maedersys.exit(0)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder__END__
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder echo "Reverted to `hets -V`."
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder exit 0
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder else
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder echo "No hets.bak found to revert."
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder exit 0
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder fi
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder else
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder echo "Root access required for \"hets -revert\""
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder exit 0
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder fi
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder esac
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederfi
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder#
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder# Setting environment variables
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder# and starting Hets
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder#
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_LIB=/usr/lib/hets/hets-lib
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_OWL_TOOLS=/usr/lib/hets/hets-owl-tools
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_ISABELLE_LIB=/usr/lib/hets/hets-lib/Isabelle
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_APROVE=$HETS_OWL_TOOLS/AProVE.jar
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_ONTODMU=$HETS_OWL_TOOLS/OntoDMU.jar
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_MAUDE_LIB=/usr/lib/hets/hets-maude-lib
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_HOLLIGHT_TOOLS=/usr/lib/hets/hets-hollight-tools
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_HOL_DIR=/usr/share/hol-light
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport HETS_OCAML_LIB_DIR=/usr/lib/ocaml/compiler-libs
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maederexport PELLET_PATH=/usr/share/pellet
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maederexport TWELF_LIB=/usr/share/twelf/bin
b1f59a4ea7c96f4c03a4d7cfcb9c5e66871cfbbbChristian Maederexport MAUDE_LIB=/usr/share/maude
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian Maeder
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian Maeder/usr/lib/hets/hets $@
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian Maeder