在 gnome-keyring-daemon 之后但在 gnome-encfs 之前启动 bash 脚本?

在 gnome-keyring-daemon 之后但在 gnome-encfs 之前启动 bash 脚本?

我需要在可用sshfs之后挂载一个(即不在我的 .profile 中并且大概在完成后(但是我对此有疑问,因为它的权限是 -rw-r--r--)),但在自动启动之前()因为我的源文件夹是挂载的。gnome-keyring-daemon/etc/xdg/autostart/gnome-keyring-ssh.desktopgnome-encfs~/.config/autostart/gnome-encfs.desktopencfssshfs

所以我想知道要编写哪个脚本,在哪里以及如何管理依赖项 - 例如,在安装之前密钥环守护进程的准备就绪sshfs,然后在启动之前安装完成encfs

由于我的搜索迄今为止没有结果,因此非常感谢您的帮助。

我在使用 Ubuntu 10.04。

答案1

由于没有找到更好的解决方案,我决定修改 gnome-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))

相关内容