Files
dn42-registry/check-my-stuff
2026-01-25 10:30:16 +00:00

91 lines
1.9 KiB
Bash
Executable File

#!/bin/sh -e
###########################################################################
#
# dn42 registry - object validation
#
###########################################################################
mntner="$1"
if [ -z "$mntner" ]
then
>&2 echo "Usage: $0 YOUR-MNT"
exit 1
fi
check_script='utils/schema-check/dn42_schema_local.py'
###########################################################################
# determine registry directory
#
# this will fail if the script is in the PATH or is sourced but those
# both seem unlikely. In any case if it does fail an env var can be used
# to override the check
rdir="$REGDIR"
if [ -z "$rdir" ]
then
rdir=$(cd -- "$(dirname -- "$0")" && pwd)
fi
if ! [ -x "${rdir}/${check_script}" ]
then
>&2 cat <<EOF
ERROR: Unable to automatically find the registry directory,
or the script '$check_script' is not executable
You can set the directory manually using the
REGDIR environment variable.
For example:
REGDIR='path/to/registry' $0 $mntner
EOF
exit 1
fi
# switch to the registry directory
cd "$rdir"
###########################################################################
# perform the validation
if [ "$mntner" = "--all" ]
then
# check everything
if ! "$check_script" -v scan data/
then
>&2 echo 'Schema validation failed!'
exit 1
fi
else
# check single mntner
mfile="data/mntner/$mntner"
if ! [ -f "$mfile" ]
then
>&2 echo "MNTNER object does not exist: $mfile"
exit 1
fi
if ! "$check_script" -v scan data/ -f "$mfile"
then
>&2 echo 'Schema validation for mntner object failed!'
exit 1
fi
if ! "$check_script" -v scan data/ -m "$mntner"
then
>&2 echo 'Schema validation for related objects failed!'
exit 1
fi
fi
# all good
exit 0
###########################################################################
# end of file