plinkfs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. # Wrapper around the FUSE 'sshfs' client, which arranges to use Plink
  3. # as the SSH transport subcommand.
  4. #
  5. # This is not totally trivial because sshfs assumes slightly more of
  6. # OpenSSH's command-line syntax than Plink supports. So we actually
  7. # give sshfs a subcommand which is this script itself, re-invoked with
  8. # the --helper option.
  9. import sys
  10. import os
  11. import shlex
  12. if sys.argv[1:2] == ["--helper"]:
  13. # Helper mode. Strip OpenSSH-specific '-o' options from the
  14. # command line, and invoke Plink.
  15. plink_command = ["plink"]
  16. it = iter(sys.argv)
  17. next(it) # discard command name
  18. next(it) # discard --helper
  19. for arg in it:
  20. if arg == "-o":
  21. next(it) # discard -o option
  22. elif arg.startswith("-o"):
  23. pass
  24. else:
  25. plink_command.append(arg)
  26. os.execvp(plink_command[0], plink_command)
  27. else:
  28. # Normal mode, invoked by the user.
  29. sshfs_command = [
  30. "sshfs", "-o", "ssh_command={} --helper".format(
  31. os.path.realpath(__file__))
  32. ] + sys.argv[1:]
  33. os.execvp(sshfs_command[0], sshfs_command)