1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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