hets_script revision 56f92cc69648f26085eff586c8cb960d846a4d62
0N/A#!/bin/sh -e
1879N/A#
0N/A# this script is part of Hets
0N/A# - Heterogenous Tool Set -
0N/A#
0N/A
0N/A#
0N/A# Handling switches
0N/A# -update
0N/A# -revert
0N/A#
0N/Aif [ "$#" = "1" ]; then
0N/A case "$1" in
0N/A
0N/A -update)
0N/A if [ "`id -u`" = "0" ]; then
0N/A apt-get install hets-core
0N/A export HETS_DAILY_VERSION=`date +%Y%m%d`
1472N/Apython << __END__
1472N/Aimport fcntl, os, sys, subprocess;
1472N/A
0N/Asubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR)
0N/Asubprocess.STDOUT=sys.stdout
0N/Asubprocess.STDERR=sys.stderr
1879N/A
1879N/Aclass UpdateFailure(Exception):
1879N/A def __init__(self, msg):
1879N/A self.value = msg
1879N/A def __str__(self):
1879N/A return repr(self.msg)
1879N/A
0N/Atry:
0N/A f = open("/var/lib/dpkg/lock", 'w')
0N/A fcntl.lockf(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
0N/A print "Retrieving latest Hets library...",
0N/A sys.stdout.flush()
0N/A subprocess.call("rm -r -f /tmp/hets*",shell=True,stderr=subprocess.DEVNULL)
0N/A try:
0N/A subprocess.check_call(["svn","export", "--force", "-q",
0N/A "https://svn-agbkb.informatik.uni-bremen.de/Hets-lib/trunk","/tmp/hets-lib"],
0N/A stdout=subprocess.STDOUT,stderr=subprocess.STDERR)
0N/A except subprocess.CalledProcessError:
0N/A raise UpdateFailure("Failed to retrieve latest Hets library!")
0N/A print "Done"
0N/A print "Retrieving latest Hets binary...",
0N/A sys.stdout.flush()
0N/A subprocess.call(["rm", "-f", "/tmp/hets-$HETS_DAILY_VERSION*"],stderr=subprocess.DEVNULL)
0N/A try:
0N/A if os.uname()[4] == "x86_64":
0N/A subprocess.check_call("curl -sG http://www.informatik.uni-bremen.de/agbkb/forschung/formal_methods/CoFI/hets/linux64/daily/hets.bz2 \
0N/A > /tmp/hets-$HETS_DAILY_VERSION.bz2",shell=True,stdout=sys.stdout,stderr=sys.stderr)
0N/A else:
0N/A subprocess.check_call("curl -sG http://www.informatik.uni-bremen.de/agbkb/forschung/formal_methods/CoFI/hets/linux/daily/hets.bz2 \
0N/A > /tmp/hets-$HETS_DAILY_VERSION.bz2",shell=True,stdout=sys.stdout,stderr=sys.stderr)
0N/A except subprocess.CalledProcessError:
0N/A raise UpdateFailure("Failed to retrieve latest Hets binary...")
0N/A try:
0N/A subprocess.check_call(["bunzip2", "/tmp/hets-$HETS_DAILY_VERSION.bz2"],
0N/A stdout=subprocess.STDOUT,stderr=subprocess.STDERR)
0N/A subprocess.call(["chmod","+x","/tmp/hets-$HETS_DAILY_VERSION"])
0N/A subprocess.check_call(["/tmp/hets-$HETS_DAILY_VERSION","-V"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
0N/A except subprocess.CalledProcessError:
0N/A raise UpdateFailure("Retrieved Hets binary seems broken. Please try again later!")
0N/A print "Done"
0N/A print "Creating Backups ...",
0N/A sys.stdout.flush()
0N/A try:
0N/A subprocess.check_call(["mv", "/usr/lib/hets/hets",
0N/A "/usr/lib/hets/hets.bak"],stderr=subprocess.DEVNULL)
0N/A subprocess.check_call(["mv","/usr/lib/hets/hets-lib",
0N/A "/usr/lib/hets/hets-lib.bak"],stderr=subprocess.DEVNULL)
0N/A except subprocess.CalledProcessError:
0N/A raise UpdateFailure("Couldn't create backups. Please make sure the package hets-core is properly installed!")
0N/A print "Done"
0N/A print "Installing new files ...",
0N/A sys.stdout.flush()
0N/A try:
0N/A subprocess.check_call(["install", "-m", "755", "/tmp/hets-$HETS_DAILY_VERSION",
0N/A "/usr/lib/hets/hets"],stderr=subprocess.DEVNULL)
0N/A subprocess.check_call(["cp", "-r", "/tmp/hets-lib", "/usr/lib/hets/hets-lib"])
0N/A except subprocess.CalledProcessError:
0N/A subprocess.call(["rm", "-r", "-f", "/usr/lib/hets/hets",
0N/A "/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
0N/A print "Done"
0N/Aexcept IOError:
0N/A print "Could not acquire lock \"/var/lib/dpkg/lock\""
0N/A sys.exit(0)
0N/Aexcept UpdateFailure as e:
0N/A print "Experienced update failure: ", e.value
0N/A subprocess.call(["mv", "/usr/lib/hets/hets.bak",
0N/A "/usr/lib/hets/hets"],stderr=subprocess.DEVNULL)
0N/A subprocess.call(["mv","/usr/lib/hets/hets-lib.bak",
0N/A "/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
0N/Afinally:
0N/A if not os.path.exists("/usr/lib/hets/hets-lib"):
0N/A subprocess.call(["mv","/usr/lib/hets/hets-lib.bak","/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
0N/A if not os.path.exists("/usr/lib/hets/hets"):
0N/A subprocess.call(["mv","/usr/lib/hets/hets.bak","/usr/lib/hets/hets"],stderr=subprocess.DEVNULL)
0N/A subprocess.call("rm -r -f /tmp/hets*",shell=True,stderr=subprocess.DEVNULL)
0N/A sys.exit(0)
0N/A__END__
0N/A echo "Updated to `hets -V`."
0N/A exit 0
0N/A else
0N/A echo "Root access required for \"hets -update\""
0N/A exit 0
0N/A fi
0N/A ;;
0N/A
0N/A -revert)
0N/A if [ "`id -u`" = "0" ]; then
0N/A if [ -f /usr/lib/hets/hets.bak ]; then
0N/Apython << __END__
0N/Aimport fcntl, os, sys, subprocess;
0N/A
0N/Asubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR)
0N/Asubprocess.STDOUT=sys.stdout
0N/Asubprocess.STDERR=sys.stderr
0N/A
0N/Aclass UpdateFailure(Exception):
0N/A def __init__(self, msg):
0N/A self.value = msg
0N/A def __str__(self):
0N/A return repr(self.msg)
0N/A
0N/Atry:
0N/A f = open("/var/lib/dpkg/lock", 'w')
0N/A fcntl.lockf(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
0N/A print "Reverting to previous Hets binary... ",
0N/A try:
0N/A subprocess.check_call(["mv", "/usr/lib/hets/hets.bak",
0N/A "/usr/lib/hets/hets"],stderr=subprocess.DEVNULL);
0N/A if os.path.exists("/usr/lib/hets/hets-lib.bak"):
0N/A subprocess.check_call(["rm", "-r", "-f", "/usr/lib/hets/hets-lib"],
0N/A stderr=subprocess.DEVNULL)
0N/A subprocess.check_call(["mv", "/usr/lib/hets/hets-lib.bak",
0N/A "/usr/lib/hets/hets-lib"],stderr=subprocess.DEVNULL)
0N/A except subprocess.CalledProcessError:
0N/A raise UpdateFailure("Couldn't restore backup!")
0N/A print "Done"
0N/Aexcept IOError:
0N/A print "Could not acquire lock \"/var/lib/dpkg/lock\""
0N/A sys.exit(0)
0N/Aexcept UpdateFailure as e:
0N/A print "Experienced revert failure: ", e.value
0N/Asys.exit(0)
0N/A__END__
0N/A echo "Reverted to `hets -V`."
0N/A exit 0
0N/A else
0N/A echo "No hets.bak found to revert."
0N/A exit 0
0N/A fi
0N/A else
0N/A echo "Root access required for \"hets -revert\""
0N/A exit 0
0N/A fi
0N/A esac
0N/Afi
0N/A
0N/A#
0N/A# Setting environment variables
0N/A# and starting Hets
0N/A#
0N/A
0N/Aexport HETS_LIB=/usr/lib/hets/hets-lib
0N/Aexport HETS_OWL_TOOLS=/usr/lib/hets/hets-owl-tools
0N/Aexport HETS_ISABELLE_LIB=/usr/lib/hets/hets-lib/Isabelle
0N/Aexport HETS_ISA_TOOLS=/usr/lib/hets/hets-isa-tools/
0N/Aexport HETS_APROVE=$HETS_OWL_TOOLS/AProVE.jar
0N/Aexport HETS_ONTODMU=$HETS_OWL_TOOLS/OntoDMU.jar
0N/Aexport HETS_MAUDE_LIB=/usr/lib/hets/hets-maude-lib
0N/Aexport HETS_HOLLIGHT_TOOLS=/usr/lib/hets/hets-hollight-tools
0N/Aexport HETS_HOL_DIR=/usr/share/hol-light
0N/Aexport HETS_OCAML_LIB_DIR=/usr/lib/ocaml/compiler-libs
0N/Aexport PELLET_PATH=/usr/share/pellet
0N/Aexport TWELF_LIB=/usr/share/twelf/bin
0N/Aexport MAUDE_LIB=/usr/share/maude
0N/A
0N/A/usr/lib/hets/hets $@
0N/A