mirror of
https://github.com/splunk/security_content
synced 2026-06-08 17:32:49 +00:00
9c183fa110
--------- Co-authored-by: pyth0n1c <87383215+pyth0n1c@users.noreply.github.com> Co-authored-by: Nasreddine Bencherchali <nasreddineb@splunk.com>
47 lines
969 B
Bash
Executable File
47 lines
969 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
printf 'Usage: %s <file.yml>\n' "${0##*/}" >&2
|
|
}
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
usage
|
|
exit 2
|
|
fi
|
|
|
|
file=$1
|
|
|
|
if [[ $file != *.yml ]]; then
|
|
printf 'Error: filename must include the .yml extension.\n' >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [[ ! -f $file ]]; then
|
|
printf 'Error: file not found: %s\n' "$file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -r $file || ! -w $file ]]; then
|
|
printf 'Error: file must be readable and writable: %s\n' "$file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v yq >/dev/null 2>&1; then
|
|
printf 'Error: yq is required but was not found on PATH.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! yq eval -e 'has("version")' "$file" >/dev/null; then
|
|
printf 'Error: expected a top-level Version field.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! yq eval -e 'has("date")' "$file" >/dev/null; then
|
|
printf 'Error: expected a top-level Date field.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
today=$(date +%F)
|
|
TODAY=$today yq eval -i '.version = ((.version | tonumber) + 1) | .date = strenv(TODAY)' "$file"
|