#!/usr/bin/env sh 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)"