eepush.in 2.2KB

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