hets_script revision 56f92cc69648f26085eff586c8cb960d846a4d62
0N/A# this script is part of Hets 0N/A# - Heterogenous Tool Set - 0N/Aif [
"$#" =
"1" ];
then 0N/A if [
"`id -u`" =
"0" ];
then 1472N/Aimport fcntl, os, sys, subprocess; 0N/Asubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR) 0N/Asubprocess.STDOUT=sys.stdout 0N/Asubprocess.STDERR=sys.stderr 1879N/Aclass UpdateFailure(Exception): 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 subprocess.call("rm -r -f /tmp/hets*",shell=True,stderr=subprocess.DEVNULL) 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 "Retrieving latest Hets binary...", 0N/A subprocess.call(["rm", "-f", "/tmp/hets-$HETS_DAILY_VERSION*"],stderr=subprocess.DEVNULL) 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 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 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 "Creating Backups ...", 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 "Installing new files ...", 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 "Could not acquire lock \"/var/lib/dpkg/lock\"" 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/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 echo "Root access required for \"hets -update\"" 0N/A if [
"`id -u`" =
"0" ];
then 0N/Aimport fcntl, os, sys, subprocess; 0N/Asubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR) 0N/Asubprocess.STDOUT=sys.stdout 0N/Asubprocess.STDERR=sys.stderr 0N/Aclass UpdateFailure(Exception): 0N/A def __init__(self, msg): 0N/A return repr(self.msg) 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 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 "Could not acquire lock \"/var/lib/dpkg/lock\"" 0N/Aexcept UpdateFailure as e: 0N/A print "Experienced revert failure: ", e.value 0N/A echo "Root access required for \"hets -revert\"" 0N/A# Setting environment variables