refactor
This commit is contained in:
58
scripts/validate.sh
Executable file
58
scripts/validate.sh
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user