You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/bin/bash
  2. set -e
  3. exec 3>&1 # make stdout available as fd 3 for the result
  4. exec 1>&2 # redirect all output to stderr for logging
  5. echo "BUILD_ID: $BUILD_ID"
  6. echo "BUILD_NAME: $BUILD_NAME"
  7. echo "BUILD_JOB_NAME: $BUILD_JOB_NAME"
  8. echo "BUILD_PIPELINE_NAME: $BUILD_PIPELINE_NAME"
  9. source $(dirname $0)/common.sh
  10. source=$1
  11. if [ -z "$source" ]; then
  12. echo "usage: $0 <path/to/source>"
  13. exit 1
  14. fi
  15. # for jq
  16. PATH=/usr/local/bin:$PATH
  17. payload=$(mktemp $TMPDIR/rclone-resource-request.XXXXXX)
  18. cat > $payload <&0
  19. # TODO: Remove Me - DEBUGGING
  20. echo "Payload:"
  21. cat $payload
  22. load_config $payload
  23. load_files $payload
  24. rclone_source_directory=$(jq -r '.params.source // ""' < $payload)
  25. rclone_destinations=$(jq -r '.params.destination[]? | .dir // ""' < $payload)
  26. if [ -z "$rclone_source_directory" ]; then
  27. echo "invalid source directory (missing source)"
  28. exit 1
  29. fi
  30. if [ -z "$rclone_destinations" ]; then
  31. echo "invalid destination (missing destination)"
  32. exit 1
  33. fi
  34. echo "Source directory: $rclone_source_directory"
  35. echo "Destinations:"
  36. jq -c '.params.destination[] | .dir' < $payload
  37. local_source_dir="${source}/${rclone_source_directory}"
  38. ls -alh ${local_source_dir}
  39. sha256=$((find ${local_source_dir} -type f -exec sha256sum {} \;) | cut -d ' ' -f1)
  40. echo "sha256:${sha256}"
  41. # Source is always the same for each destination
  42. rclone_source="local:${local_source_dir}"
  43. echo "Source: ${rclone_source}"
  44. for destination in $(jq -r '.params.destination[] | @base64'); do
  45. _jq() {
  46. echo ${destination} | base64 --decode | jq -r ${1}
  47. }
  48. rclone_destination=$(_jq '.dir')
  49. echo "Destination: $rclone_destination"
  50. rclone_destination_subdir_file=$(_jq '.subdir // ""')
  51. echo "Destination subdir file: ${rclone_destination_subdir_file}"
  52. rclone_destination_subdir=""
  53. if [ ! -z "$rclone_destination_subdir_file" ]; then
  54. echo "Looking in ${source}/${rclone_destination_subdir_file} for subdir to use"
  55. rclone_destination_subdir=$(cat "${source}/${rclone_destination_subdir_file}" | head -n 1)
  56. fi
  57. rclone_target="${rclone_destination}/${rclone_destination_subdir}"
  58. echo "Target: ${rclone_target}"
  59. rclone copy "${rclone_source}" "${rclone_target}" --config /opt/rclone/config/.rclone.conf --progress
  60. done
  61. jq -n "{
  62. version: {
  63. digest: $((echo -n "sha256:"; echo "$sha256") | jq -R .)
  64. }
  65. }" >&3