diff --git a/README.md b/README.md index 3b5a200..dbc65e0 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,9 @@ It's highly recommended to use secrets mangement to avoid storing sensitive cred #### Parameters * `source`: Required. The path to the source files. -* `destination`: Required. The rclone destination for the files. ex. `remote:some/location` -* `subdir`: Optional. A file that includes additional path information to be appended to the end of destination. +* `destination`: Required. A list of destinations to copy files to. + * `dir`: Required. A rclone destination for the files. ex. `remote:some/location` + * `subdir`: Optional. A file that includes additional path information to be appended to the end of destination. #### Example @@ -73,8 +74,9 @@ jobs: - put: rclone params: source: code - destination: "remote:backup" - subdir: code/target + destination: + - dir: "remote:backup" + subdir: code/target ``` ## License diff --git a/assets/out b/assets/out index c03fcd2..8922cf2 100644 --- a/assets/out +++ b/assets/out @@ -33,38 +33,53 @@ load_config $payload load_files $payload rclone_source_directory=$(jq -r '.params.source // ""' < $payload) -rclone_destination=$(jq -r '.params.destination // ""' < $payload) -rclone_destination_subdir_file=$(jq -r '.params.subdir // ""' < $payload) - -echo "Source directory: $rclone_source_directory" -echo "Destination: $rclone_destination" -echo "Destination subdir file: $rclone_destination_subdir_file" +rclone_destinations=$(jq -r '.params.destination[]? | .dir // ""' < $payload) if [ -z "$rclone_source_directory" ]; then echo "invalid source directory (missing source)" exit 1 fi -if [ -z "$rclone_destination" ]; then +if [ -z "$rclone_destinations" ]; then echo "invalid destination (missing destination)" exit 1 fi -rclone_destination_subdir="" -if [ ! -z "$rclone_destination_subdir_file" ]; then - echo "Looking in ${source}/${rclone_destination_subdir_file} for subdir to use" - rclone_destination_subdir=$(cat "${source}/${rclone_destination_subdir_file}" | head -n 1) -fi +echo "Source directory: $rclone_source_directory" +echo "Destinations:" +jq -c '.params.destination[] | .dir' < $payload + +local_source_dir="${source}/${rclone_source_directory}" +ls -alh ${local_source_dir} -rclone_source="local:${source}/${rclone_source_directory}" -rclone_target="${rclone_destination}/${rclone_destination_subdir}" +sha256=$((find ${local_source_dir} -type f -exec sha256sum {} \;) | cut -d ' ' -f1) +echo "sha256:${sha256}" + +# Source is always the same for each destination +rclone_source="local:${local_source_dir}" echo "Source: ${rclone_source}" -echo "Target: ${rclone_target}" -sha256=$((find ${source}/${rclone_source_directory} -type f -exec sha256sum {} \;) | cut -d ' ' -f1) +for destination in $(jq -r '.params.destination[] | @base64'); do + _jq() { + echo ${destination} | base64 --decode | jq -r ${1} + } + + rclone_destination=$(_jq '.dir') + echo "Destination: $rclone_destination" + + rclone_destination_subdir_file=$(_jq '.subdir // ""') + echo "Destination subdir file: ${rclone_destination_subdir_file}" + rclone_destination_subdir="" + if [ ! -z "$rclone_destination_subdir_file" ]; then + echo "Looking in ${source}/${rclone_destination_subdir_file} for subdir to use" + rclone_destination_subdir=$(cat "${source}/${rclone_destination_subdir_file}" | head -n 1) + fi -rclone copy "${rclone_source}" "${rclone_target}" --config /opt/rclone/config/.rclone.conf + rclone_target="${rclone_destination}/${rclone_destination_subdir}" + echo "Target: ${rclone_target}" + rclone copy "${rclone_source}" "${rclone_target}" --config /opt/rclone/config/.rclone.conf --progress +done jq -n "{ version: {