eepush.in 2.2KB

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