From 13b1d7f0b10ceb7334516953270d741ba46a4055 Mon Sep 17 00:00:00 2001 From: redxef Date: Fri, 6 May 2022 03:10:47 +0200 Subject: [PATCH] Implement out. --- check | 48 +----------------------------------------------- common | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ out | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 47 deletions(-) diff --git a/check b/check index 6369a3e..3a5f1e1 100755 --- a/check +++ b/check @@ -4,50 +4,4 @@ set -e . ./common -fetch_file_infos() { - files_file="$(mktemp -tp /tmp)" -ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF > "$files_file" - files="$(get_files)" - echo "\$files" | while read -r file; do - echo "\$file" - [ -e "\$file" ] && echo true || echo false - [ -e "\$file" ] && echo "\$(stat --format=%Y "\$file")" || echo - done -EOF - echo "$files_file" - return 0 -} - -_compute_version() { - echo "[" - last_line= - line_file= - line_exists= - line_modify= - while read -r line; do - if [ -z "$line_file" ]; then - line_file="$line" - elif [ -z "$line_exists" ]; then - line_exists="$line" - elif [ -z "$line_modify" ]; then - line_modify="$line" - else - if "$line_exists"; then - echo '{"path":' "\"$line_file\"," '"modify":' "$line_modify" '}', - fi - line_file="$line" - line_exists= - line_modify= - fi - done < "$1" - if [ -n "$line_file" ] && [ -n "$line_exists" ] && [ -n "$line_modify" ] && "$line_exists"; then - echo '{"path":' "\"$line_file\"," '"modify":' "$line_modify" '}' - fi - echo "]" -} - -compute_version() { - _compute_version "$@" | jq -r tostring -} - -compute_version "$(fetch_file_infos)" +compute_version "$(fetch_file_infos get_files)" diff --git a/common b/common index 0894a77..b42b81a 100755 --- a/common +++ b/common @@ -59,3 +59,61 @@ get_version() { get_files() { jq -r '.source.files?[]' < "$INPUT_PATH" } + +get_command() { + jq -r '.params.command?' < "$INPUT_PATH" +} + +get_directory() { + jq -r '.params.directory // "/"' < "$INPUT_PATH" +} + +get_workdir() { + jq -r '.params.workdir // "$HOME"' < "$INPUT_PATH" +} + +fetch_file_infos() { + files_file="$(mktemp -tp /tmp)" +ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF > "$files_file" + files="$("$1")" + echo "\$files" | while read -r file; do + echo "\$file" + [ -e "\$file" ] && echo true || echo false + [ -e "\$file" ] && echo "\$(stat --format=%Y "\$file")" || echo + done +EOF + echo "$files_file" + return 0 +} + +_compute_version() { + echo "[" + last_line= + line_file= + line_exists= + line_modify= + while read -r line; do + if [ -z "$line_file" ]; then + line_file="$line" + elif [ -z "$line_exists" ]; then + line_exists="$line" + elif [ -z "$line_modify" ]; then + line_modify="$line" + else + if "$line_exists"; then + echo '{"path":' "\"$line_file\"," '"modify":' "$line_modify" '}', + fi + line_file="$line" + line_exists= + line_modify= + fi + done < "$1" + if [ -n "$line_file" ] && [ -n "$line_exists" ] && [ -n "$line_modify" ] && "$line_exists"; then + echo '{"path":' "\"$line_file\"," '"modify":' "$line_modify" '}' + fi + echo "]" +} + +compute_version() { + _compute_version "$@" | jq -r tostring +} diff --git a/out b/out index 0617957..b45c92b 100755 --- a/out +++ b/out @@ -1 +1,37 @@ #!/usr/bin/env sh + +set -e +set -o pipefail + +. ./common + +cd "$1" +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" +ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF + set -e + cd "$(get_directory)" + tar xf "$remote_tarfile" + rm "$remote_tarfile" + 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": $version +} +EOF