SHARE
TWEET

Untitled

jcomeau_ictx Jul 27th, 2013 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # rdiff: remote diff, copyleft 2013 under GPL jc.unternet.net
  3. # for bug reports replace first dot with @
  4. set +H  # prevent history expansion
  5. sshfs_mount() {
  6.  remote="$1"  # rather, purported remote; we shall find out
  7.  if [ ! -e "$remote" -a "${remote%%:*}" != "$remote" ]; then
  8.   old_remote="$remote"
  9.   remote=$(mktemp -d)
  10.   if ! sshfs "$old_remote" "$remote"; then
  11.    if ! sshfs "${old_remote%[:/]*}" "$remote"; then
  12.     rmdir $remote
  13.     remote="$old_remote"
  14.    else
  15.     remote="$remote/${old_remote##*[:/]}"
  16.    fi
  17.   fi
  18.  fi
  19.  echo "$remote"
  20. }
  21. sshfs_umount() {
  22.  tempdir="$1"
  23.  while [ ${#tempdir} -gt 1 -a ! -d "$tempdir" ]; do
  24.   if [ "$tempdir" = "${tempdir%/*}" ]; then
  25.    break
  26.   else
  27.    tempdir="${tempdir%/*}"
  28.   fi
  29.  done
  30.  while [ ${#tempdir} -gt 1 -a -d "$tempdir" ]; do
  31.   if fusermount -u "$tempdir"; then
  32.    rmdir "$tempdir"
  33.    break
  34.   elif [ "$tempdir" = "${tempdir%/*}" ]; then
  35.    break
  36.   else
  37.    tempdir=${tempdir%/*}
  38.   fi
  39.  done
  40. }
  41. diff_source="$(sshfs_mount "${@:$#-1:1}")"
  42. diff_target="$(sshfs_mount "${@:$#:1}")"
  43. diff "${@:1:$#-2}" "$diff_source" "$diff_target"
  44. exstat=$?
  45. sshfs_umount "$diff_source"
  46. sshfs_umount "$diff_target"
  47. exit $exstat
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top