Add cleanup.

This commit is contained in:
redxef 2022-05-06 03:44:58 +02:00
parent 13b1d7f0b1
commit 01401759b7
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
4 changed files with 30 additions and 10 deletions

3
check
View file

@ -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

6
common
View file

@ -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() {

3
in
View file

@ -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

12
out
View file

@ -3,19 +3,24 @@
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
@ -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