hets_script revision 6eb335aba416a77cb49ecd390fa3fee7aed55e2e
306763c67bb99228487345b32ab8c5c6cd41f23cChristian Maeder# this script is part of Hets
3a6c7a7ff823616f56cd3d205fc44664a683effdChristian Maeder# - Heterogenous Tool Set -
306763c67bb99228487345b32ab8c5c6cd41f23cChristian Maeder# Handling switches
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederimport fcntl, os, sys, subprocess;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedersubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedersubprocess.STDOUT=sys.stdout
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maedersubprocess.STDERR=sys.stderr
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 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 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!")
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)
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)
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 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 "Creating Backups ...",
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski sys.stdout.flush()
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!")
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill Mossakowski print "Installing new files ...",
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski sys.stdout.flush()
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)
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maederexcept IOError:
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder print "Could not acquire lock \"/var/lib/dpkg/lock\""
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 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 echo "Root access required for \"hets -update\""
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maederimport fcntl, os, sys, subprocess;
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maedersubprocess.DEVNULL=os.open(os.devnull, os.O_RDWR)
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maedersubprocess.STDOUT=sys.stdout
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maedersubprocess.STDERR=sys.stderr
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)
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 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 Maederexcept IOError:
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder print "Could not acquire lock \"/var/lib/dpkg/lock\""
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederexcept UpdateFailure as e:
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder print "Experienced revert failure: ", e.value
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder echo "No hets.bak found to revert."
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder echo "Root access required for \"hets -revert\""
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder# Setting environment variables
5c358300e78157f4bfaf5415c70e1096a9205b61Christian Maeder# and starting Hets
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