From 01401759b7aceab4bb9be43c13f443f72b231fec Mon Sep 17 00:00:00 2001 From: redxef Date: Fri, 6 May 2022 03:44:58 +0200 Subject: [PATCH] Add cleanup. --- check | 3 +++ common | 6 +++++- in | 3 +++ out | 28 +++++++++++++++++++--------- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/check b/check index 3a5f1e1..ac4e9de 100755 --- a/check +++ b/check @@ -1,7 +1,10 @@ #!/usr/bin/env sh set -e +set -o pipefail +[ -e /opt/resource/common ] && cd /opt/resource/ . ./common compute_version "$(fetch_file_infos get_files)" +cleanup diff --git a/common b/common index b42b81a..4a1a510 100755 --- a/common +++ b/common @@ -45,6 +45,10 @@ write_config() { return 0 } +cleanup() { + rm -r /tmp/* +} + INPUT_PATH="$(save_input)" read_config "$INPUT_PATH" CONFIG_PATH="$(write_config)" @@ -65,7 +69,7 @@ get_command() { } get_directory() { - jq -r '.params.directory // "/"' < "$INPUT_PATH" + jq -r '.params.directory // ""' < "$INPUT_PATH" } get_workdir() { diff --git a/in b/in index 6842d56..b1c5546 100755 --- a/in +++ b/in @@ -3,6 +3,7 @@ set -e set -o pipefail +[ -e /opt/resource/common ] && cd /opt/resource/ . ./common cd "$1" @@ -37,3 +38,5 @@ jq -r tostring << EOF "version": $(get_version) } EOF + +cleanup diff --git a/out b/out index b45c92b..16985c8 100755 --- a/out +++ b/out @@ -3,19 +3,24 @@ set -e set -o pipefail +[ -e /opt/resource/common ] && cd /opt/resource/ . ./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" +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 - cd "$(get_directory)" - tar xf "$remote_tarfile" - rm "$remote_tarfile" + if [ -n "$(get_directory)" ]; then + cd "$(get_directory)" + tar xf "$remote_tarfile" + rm "$remote_tarfile" + fi if [ "$(get_command)" = "null" ]; then exit 0 fi @@ -32,6 +37,11 @@ version="$(compute_version "$(fetch_file_infos get_files_for_new_version)")" jq -r tostring << EOF { - "version": $version + "version": { + "files": $version, + "command": true + } } EOF + +cleanup