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