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 #!/usr/bin/env sh
set -e set -e
set -o pipefail
[ -e /opt/resource/common ] && cd /opt/resource/
. ./common . ./common
compute_version "$(fetch_file_infos get_files)" compute_version "$(fetch_file_infos get_files)"
cleanup

6
common
View file

@ -45,6 +45,10 @@ write_config() {
return 0 return 0
} }
cleanup() {
rm -r /tmp/*
}
INPUT_PATH="$(save_input)" INPUT_PATH="$(save_input)"
read_config "$INPUT_PATH" read_config "$INPUT_PATH"
CONFIG_PATH="$(write_config)" CONFIG_PATH="$(write_config)"
@ -65,7 +69,7 @@ get_command() {
} }
get_directory() { get_directory() {
jq -r '.params.directory // "/"' < "$INPUT_PATH" jq -r '.params.directory // ""' < "$INPUT_PATH"
} }
get_workdir() { get_workdir() {

3
in
View file

@ -3,6 +3,7 @@
set -e set -e
set -o pipefail set -o pipefail
[ -e /opt/resource/common ] && cd /opt/resource/
. ./common . ./common
cd "$1" cd "$1"
@ -37,3 +38,5 @@ jq -r tostring << EOF
"version": $(get_version) "version": $(get_version)
} }
EOF EOF
cleanup

12
out
View file

@ -3,19 +3,24 @@
set -e set -e
set -o pipefail set -o pipefail
[ -e /opt/resource/common ] && cd /opt/resource/
. ./common . ./common
cd "$1" cd "$1"
if [ -n "$(get_directory)" ]; then
files="$(find . | sed -e '/^\.$/d' -e 's|^./||')" files="$(find . | sed -e '/^\.$/d' -e 's|^./||')"
tarfile="$(mktemp -tp /tmp)" tarfile="$(mktemp -tp /tmp)"
remote_tarfile="$(mktemp -u)" remote_tarfile="$(mktemp -u)"
tar -cf "$tarfile" ./* tar -cf "$tarfile" ./*
scp -F "$CONFIG_PATH" "$tarfile" "$HOSTNAME:$remote_tarfile" scp -F "$CONFIG_PATH" "$tarfile" "$HOSTNAME:$remote_tarfile"
fi
ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF ssh -F "$CONFIG_PATH" "$HOSTNAME" sh -s << EOF
set -e set -e
if [ -n "$(get_directory)" ]; then
cd "$(get_directory)" cd "$(get_directory)"
tar xf "$remote_tarfile" tar xf "$remote_tarfile"
rm "$remote_tarfile" rm "$remote_tarfile"
fi
if [ "$(get_command)" = "null" ]; then if [ "$(get_command)" = "null" ]; then
exit 0 exit 0
fi fi
@ -32,6 +37,11 @@ version="$(compute_version "$(fetch_file_infos get_files_for_new_version)")"
jq -r tostring << EOF jq -r tostring << EOF
{ {
"version": $version "version": {
"files": $version,
"command": true
}
} }
EOF EOF
cleanup