eepush 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. . <(ffoom init)
  3. ffoo import core
  4. ffoo import recon
  5. ORDER="$(eeini -p push.options.order)"
  6. while true; do case $1 in
  7. -d|--debug) FFOO_DEBUG=true; shift; ;;
  8. -v|--verbose) FFOO_VERBOSE=true; shift; ;;
  9. -q|--quiet) FFOO_VERBOSE=false; shift; ;;
  10. -o|--order) ORDER=$2; shift 2; ;;
  11. -h|--help) usage; ;;
  12. "") break ;;
  13. *) hosts="$1"; shift; ;;
  14. esac done
  15. test -n "$hosts" || hosts=$(eeini -s push.hosts | debug_pipe ini_hosts)
  16. debug -v hosts
  17. test -n "$hosts" || die "no valid hosts to begin with"
  18. paths=$(eeini -s push.paths)
  19. test -n "$paths" || die "no valid paths to begin with"
  20. think "Probing & sorting paths"
  21. paths=$(echo "$paths" \
  22. | expand_tilde \
  23. | filter test -e \
  24. | sort_paths_by_age \
  25. | debug_pipe ok_paths
  26. )
  27. test -n "$paths" || die "no valid paths"
  28. think "Probing hosts"
  29. hosts=$(echo "$hosts" | filter_hosts -s | debug_pipe ok_hosts )
  30. test -n "$hosts" || die "no valid hosts"
  31. test "$(wc -l <<<"$paths")" == 1 && ORDER="path:host"
  32. test "$(wc -l <<<"$hosts")" == 1 && ORDER="host:path"
  33. think "Pushing (${ORDER/:/, then })..."
  34. debug -v "paths:hosts"
  35. case "$ORDER" in
  36. "path:host")
  37. for path in $paths;
  38. do
  39. for host in $hosts;
  40. do
  41. if rsync -L -r --delete $path $host:
  42. then
  43. think $(collapse_tilde <<<"$path") sent to $host
  44. fi
  45. done
  46. done
  47. ;;
  48. "host:path")
  49. for host in $hosts;
  50. do
  51. for path in $paths;
  52. do
  53. if rsync -L -r --delete $path $host:
  54. then
  55. think $host got $path
  56. fi
  57. done
  58. done
  59. ;;
  60. *)
  61. die "unknown push order: '$ORDER'"
  62. ;;
  63. esac
  64. for host in $hosts;
  65. do
  66. eeini -s push.commands \
  67. | grep . \
  68. | while read cmd;
  69. do
  70. think "ssh $host -- $cmd"
  71. ssh -n $host -- "$cmd" > /dev/null
  72. done
  73. done