Запуск сценария удара после гнома-демона брелока для ключей, но перед гномом-encfs?

Я должен смонтироваться sshfs после gnome-keyring-daemon становится доступным (т.е. не в моем .profile и по-видимому после /etc/xdg/autostart/gnome-keyring-ssh.desktop завершился (однако, у меня есть сомнение на этом, поскольку его полномочия являются-rw-r - r-)), но прежде gnome-encfs автоматические запуски (~/.config/autostart/gnome-encfs.desktop) как мой encfs исходные папки sshfs монтируется.

Так интересно, какой сценарий записать, где и как управлять зависимостями - т.е. готовность брелока для ключей deamon перед монтированием sshfs, затем смонтируйтесь завершенный перед запуском encfs.

Любой и вся справка, ценившая как мой поиск, были бесплодны до сих пор.

Я нахожусь на Ubuntu 10.04.

0
задан 12 November 2016 в 20:51

1 ответ

Не найдя лучшего решения, я решил изменить гнома-encfs для добавления опции перед командой:

--- original gnome-encfs
+++ modified gnome-encfs
@@ -48,6 +48,7 @@
     econfig = None
     mpoint = None
     amount = None
+    precmd = None
# =============================================================================
# constants
@@ -125,6 +126,8 @@
                   help="Input for mount point edit")
     og.add_option("", "--amount", default=None,
                   help="Input for auto mount question")
+    og.add_option("", "--precmd", default=None,
+                  help="Input for pre-command question")
     og.add_option("", "--econfig", default=None,
                   help="Input for encfs config file question")
@@ -150,12 +153,12 @@
     opts.p2 = args and args.pop(0) or None

     if opts.add and not (opts.p1 and opts.p2):
-        op.error("add needs an EncFS path and a moint point")
+        op.error("add needs an EncFS path and a mount point")
         op.print_help()
         op.exit(1)

     if opts.remove and not opts.p1:
-        op.error("remove needs a moint point")
+        op.error("remove needs a mount point")
         op.print_help()
         op.exit(1)
@@ -164,6 +167,7 @@
     preset.epath = opts.epath
     preset.mpoint = opts.mpoint
     preset.amount = opts.amount
+    preset.precmd = opts.precmd
     preset.econfig = opts.econfig

     return opts
@@ -220,7 +224,7 @@    _items_cached = None  
-def _get_items(mpoint=None, epath=None, anypath=None, amount=None):
+def _get_items(mpoint=None, epath=None, anypath=None, amount=None, precmd=None):
     """Get all EncFS items or those matching given attributes."""

     global _items_cached
@@ -243,6 +247,8 @@
             continue
         if amount and item.attributes["auto-mount"] != amount:
             continue
+        if precmd and item.attributes["pre-command"] != precmd:
+            continue
         match.append(item)

     return match
@@ -292,10 +298,12 @@
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
         amount = item.attributes["auto-mount"]
+        precmd = item.attributes["pre-command"]
         econfig = item.attributes.get("encfs-config", "-")
         print("* encfs path     : %s" % epath)
         print("  mount point    : %s" % mpoint)
         print("  mount at login : %s" % (amount == "y" and "yes" or "no"))
+        print("  pre command    : %s" % precmd)
         print("  encfs config   : %s" % econfig)

     return RC_OK
@@ -316,8 +324,9 @@
     secret = preset.password or getpass.getpass("EncFS password: ")
     amount = preset.amount or raw_input("Mount at login [Y/n]: ") or "y"
     amount = amount.strip()[0].lower() == "y" and "y" or "n"
+    precmd = preset.precmd or raw_input("Pre command: ") or None
     attr = {"encfs-path": epath, "mount-point": mpoint, "auto-mount": amount,
-        "encfs-config": econfig}
+        "pre-command": precmd, "encfs-config": econfig}
     attr.update(GENCFS_ATTR)
     name = "EncFS mount at %s" % mpoint
     gk.item_create_sync(KEYRING, ITYPE, name, attr, secret, False)
@@ -343,6 +352,7 @@
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
         amount = item.attributes["auto-mount"]
+        precmd = item.attributes["pre-command"]
         econfig = item.attributes.get("encfs-config", "-")
         epath = preset.epath or raw_input("EncFS path [%s]: " % epath) or epath
         econfig = preset.econfig or raw_input("EncFS config file [%s] (`-`: default): " % econfig) or econfig
@@ -351,6 +361,7 @@
         hint = amount == "y" and "Y/n" or "y/N"
         amount = preset.amount or raw_input("Mount at login [%s]: " % hint) or amount
         amount = amount.strip()[0].lower() == "y" and "y" or "n"
+        precmd = preset.precmd or raw_input("Pre command: ") or None
         mpoint = _pathify(mpoint)
         epath = _pathify(epath)
@@ -368,6 +379,7 @@
         attributes["encfs-path"] = epath
         attributes["mount-point"] = mpoint
         attributes["auto-mount"] = amount
+        attributes["pre-command"] = precmd
         attributes["encfs-config"] = econfig
         gk.item_set_attributes_sync(KEYRING, item.item_id, attributes)
         info = gk.item_get_info_sync(KEYRING, item.item_id)
@@ -427,6 +440,18 @@
             msg += "mount point does not exist or is not a directory"
             rc |= RC_INVALID_PATH
         else:
+            if precmd != None:
+                # fire command and forget (do all the error handling in
+                # pre-command - no tie in here if it fails)
+                # My use case: mount sshfs before encfs, if the sshfs
+                # mount fails, then encfs will start on an empty
+                # directory.
+                cmd = precmd.split()
+       #print("pre command    : %s" % precmd)
+       #print("pre command    : %s" % cmd)
+                p = subprocess.Popen(cmd)
+                p.wait()
+                print("Pre command return code: %s" % p.returncode)
             cmd = ["encfs", "-o", "nonempty", "-S", epath, mpoint]
             p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                 env=_encfs_env(econfig))
0
ответ дан 28 September 2019 в 05:01

Другие вопросы по тегам:

Похожие вопросы: