concourse-ssh-resource/out

48 lines
1,017 B
Text
Raw Normal View History

2022-05-05 23:23:10 +02:00
#!/usr/bin/env sh
2022-05-06 03:10:47 +02:00
set -e
set -o pipefail
2022-05-06 03:44:58 +02:00
[ -e /opt/resource/common ] && cd /opt/resource/
2022-05-06 03:10:47 +02:00
. ./common
cd "$1"
2022-05-06 03:44:58 +02:00
if [ -n "$(get_directory)" ]; then
files="$(find . | sed -e '/^\.$/d' -e 's|^./||')"
tarfile="$(mktemp -tp /tmp)"
remote_tarfile="$(mktemp -u)"
tar -cf "$tarfile" ./*
scp -F "$CONFIG_PATH" "$tarfile" "$HOSTNAME:$remote_tarfile"
fi
2022-05-06 03:10:47 +02:00
ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF
set -e
2022-05-06 03:44:58 +02:00
if [ -n "$(get_directory)" ]; then
cd "$(get_directory)"
tar xf "$remote_tarfile"
rm "$remote_tarfile"
fi
2022-05-06 03:10:47 +02:00
if [ "$(get_command)" = "null" ]; then
exit 0
fi
cd "$(get_workdir)"
$(get_command | jq .[] | tr '\n"' " '") >&2
# echo "\$command_log" >&2
EOF
get_files_for_new_version() {
echo "$files" | xargs printf "$(get_directory)/%s\n"
}
version="$(compute_version "$(fetch_file_infos get_files_for_new_version)")"
jq -r tostring << EOF
{
2022-05-06 03:44:58 +02:00
"version": {
"files": $version,
2022-05-06 11:33:04 +02:00
"time": $(date +%s)
2022-05-06 03:44:58 +02:00
}
2022-05-06 03:10:47 +02:00
}
EOF
2022-05-06 03:44:58 +02:00
cleanup