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.
73 lines
1.9 KiB
73 lines
1.9 KiB
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
exec 3>&1 # make stdout available as fd 3 for the result
|
|
exec 1>&2 # redirect all output to stderr for logging
|
|
|
|
echo "BUILD_ID: $BUILD_ID"
|
|
echo "BUILD_NAME: $BUILD_NAME"
|
|
echo "BUILD_JOB_NAME: $BUILD_JOB_NAME"
|
|
echo "BUILD_PIPELINE_NAME: $BUILD_PIPELINE_NAME"
|
|
|
|
source $(dirname $0)/common.sh
|
|
|
|
source=$1
|
|
|
|
if [ -z "$source" ]; then
|
|
echo "usage: $0 <path/to/source>"
|
|
exit 1
|
|
fi
|
|
|
|
# for jq
|
|
PATH=/usr/local/bin:$PATH
|
|
|
|
payload=$(mktemp $TMPDIR/rclone-resource-request.XXXXXX)
|
|
cat > $payload <&0
|
|
|
|
# TODO: Remove Me - DEBUGGING
|
|
echo "Payload:"
|
|
cat $payload
|
|
|
|
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"
|
|
|
|
if [ -z "$rclone_source_directory" ]; then
|
|
echo "invalid source directory (missing source)"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$rclone_destination" ]; 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
|
|
|
|
rclone_source="local:${source}/${rclone_source_directory}"
|
|
rclone_target="${rclone_destination}/${rclone_destination_subdir}"
|
|
|
|
echo "Source: ${rclone_source}"
|
|
echo "Target: ${rclone_target}"
|
|
|
|
sha256=$((find ${source}/${rclone_source_directory} -type f -exec sha256sum {} \;) | cut -d ' ' -f1)
|
|
|
|
rclone copy "${rclone_source}" "${rclone_target}" --config /opt/rclone/config/.rclone.conf
|
|
|
|
jq -n "{
|
|
version: {
|
|
digest: $((echo -n "sha256:"; echo "$sha256") | jq -R .)
|
|
}
|
|
}" >&3
|