concourse-ssh-resource/out
2022-05-06 03:44:58 +02:00

47 lines
1,013 B
Bash
Executable file

#!/usr/bin/env sh
set -e
set -o pipefail
[ -e /opt/resource/common ] && cd /opt/resource/
. ./common
cd "$1"
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
ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF
set -e
if [ -n "$(get_directory)" ]; then
cd "$(get_directory)"
tar xf "$remote_tarfile"
rm "$remote_tarfile"
fi
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
{
"version": {
"files": $version,
"command": true
}
}
EOF
cleanup