FIx configuration, TTY setting, etc
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Jun 2018 20:54:03 +0000 (16:54 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Jun 2018 20:54:03 +0000 (16:54 -0400)
libremanage

index 8d63eedbd777325665e6ac0b1bc72cda9a856146..283d57506f9390026efa87701cd86bf7ec35bdeb 100755 (executable)
@@ -35,16 +35,23 @@ Valid commands are as follows:
     - shutdown, reboot, poweron: Power management
     - tty: Open TTY in GNU Screen
     - sanity, sanity-sh: SSH sanity tests, ignore
+
+Define a configuration file in ~/.libremanage.json. See the included
+config.json for an example. Servers correspond to managed servers; managers
+correspond to single-board computers connecting the servers. libremanage SSHs
+into the manager to access the server through the side-channel.
 """
 
 import sys
 import json
 import functools
 import subprocess
+import os.path
 
 def open_ssh(server, command, force_tty=False):
     config = server["ssh"]
-    subprocess.run(["ssh", "-t" if force_tty else "", config["username"] + "@" + config["host"], "-p", str(config["port"]), command])
+    args = ["ssh"] + (["-t"] if force_tty else []) + [config["username"] + "@" + config["host"], "-p", str(config["port"]), command]
+    subprocess.run(args)
 
 def die_with_usage(message):
     print(message)
@@ -104,8 +111,11 @@ def issue_command(server_name, command):
 
 # Load configuration, get command, and go!
 
-with open("config.json") as f:
-    CONFIG = json.load(f)
+try:
+    with open(os.path.expanduser("~/.libremanage.json")) as f:
+        CONFIG = json.load(f)
+except FileNotFoundError:
+    die_with_usage("Configuration file missing in ~/.libremanage.json")
 
 if len(sys.argv) != 3:
     die_with_usage("Incorrect number of arguments")