undo previous commit and redo it properly via a patch file instead of
[invirt/packages/invirt-vnc-client.git] / debian / invirt-update-vnc-cert
index 27997c0..177c39a 100755 (executable)
@@ -1,30 +1,41 @@
 #!/usr/bin/python
 
 from invirt.config import structs as config
 #!/usr/bin/python
 
 from invirt.config import structs as config
-from subprocess import Popen, call, PIPE
+from subprocess import Popen, check_call, PIPE, CalledProcessError
 import tempfile
 import os
 import sys
 import shutil
 
 import tempfile
 import os
 import sys
 import shutil
 
+def check_wait(popen):
+    retcode = popen.wait()
+    if retcode != 0:
+        raise CalledProcessError(retcode, popen.pid)
+    return retcode
+
 def main():
 def main():
-    call(['kinit', '-k', 'daemon/%s' % config.web.hostname])
+    check_call(['kinit', '-k', 'daemon/%s' % config.web.hostname])
     
     
+    temp_dir = tempfile.mkdtemp()
+
+    jarfile = os.path.join(temp_dir, 'VncViewer.jar')
+
     shutil.copy('/usr/share/invirt-vnc-client/VncViewer.src.jar',
     shutil.copy('/usr/share/invirt-vnc-client/VncViewer.src.jar',
-                '/usr/share/invirt-vnc-client/VncViewer.jar')
+                jarfile)
     
     
-    temp_dir = tempfile.mkdtemp()
     keystore = os.path.join(temp_dir, 'trust.store')
     for host in config.hosts:
         cert = Popen(['remctl', config.remote.hostname, 'web', 'vnccert', host.hostname],
                      stdout=PIPE)
     keystore = os.path.join(temp_dir, 'trust.store')
     for host in config.hosts:
         cert = Popen(['remctl', config.remote.hostname, 'web', 'vnccert', host.hostname],
                      stdout=PIPE)
-        cert.wait()
-        call(['keytool', '-import', '-noprompt', '-alias', host.hostname,
-              '-keystore', keystore, '-storepass', 'foobar'],
-             stdin=cert.stdout)
+        check_wait(cert)
+        check_call(['keytool', '-import', '-noprompt', '-alias', host.hostname,
+                    '-keystore', keystore, '-storepass', 'foobar'],
+                   stdin=cert.stdout)
     
     
-    call(['jar', 'uf', '/usr/share/invirt-vnc-client/VncViewer.jar',
-          '-C', temp_dir, 'trust.store'])
+    check_call(['jar', 'uf', jarfile,
+                '-C', temp_dir, 'trust.store'])
+
+    shutil.move(jarfile, '/usr/share/invirt-vnc-client/VncViewer.jar')
     
     shutil.rmtree(temp_dir)
 
     
     shutil.rmtree(temp_dir)