Implement out.

This commit is contained in:
redxef 2022-05-06 03:10:47 +02:00
parent d67112e046
commit 13b1d7f0b1
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
3 changed files with 95 additions and 47 deletions

48
check
View file

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

58
common
View file

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

36
out
View file

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