Files
bearnet/scripts/validate.sh
iceBear67 bf67b8b95f refactor
2026-07-05 13:49:09 +08:00

58 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
root="$PWD/image/overlay"
env_file="${1:-.env}"
if [ ! -f "$env_file" ]; then
echo "cannot find $env_file"
exit 1
fi
current_file=""
fail=0
while IFS= read -r line; do
case "$line" in
\#\ /*)
current_file="${line#\# }"
target="$root$current_file"
if [ ! -f "$target" ]; then
echo "missing file: $target" >&2
fail=1
current_file=""
fi
;;
\#\:*)
continue
;;
*=*)
if [ -z "$current_file" ]; then
echo "warning: value without file: $line" >&2
continue
fi
key="${line%%=*}"
target="$root$current_file"
if ! grep -q "_${key}_" "$target"; then
echo "missing variable: _${key}_ in $target" >&2
fail=1
fi
;;
"")
continue
;;
*)
echo "unknown line: $line" >&2
fail=1
;;
esac
done < "$env_file"
exit "$fail"