saturnin-push 2.0KB

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