You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/scripts/check

67 lines
1.8 KiB

#!/bin/bash
# Purpose: check/validate YAML config files (syntax, encoding, ...)
################################################################################
set -e
set -u
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
if ! [ -r ${FUNCTIONS}/main ] ; then
printf "Error: ${FUNCTIONS}/main could not be read. Exiting.\n" >&2
exit 1
fi
. ${FUNCTIONS}/main
check_config_encoding() {
log_debug "Checking encoding for $config_files"
for f in $config_files ; do
if [ -r "$f" ] && ! file -L "$f" | grep -qe "UTF-8" -qe "ASCII" ; then
log_error "Encoding check of ${f} fails: neither ASCII nor UTF-8."
log_error "Please convert ${f} to UTF-8."
log_info
log_info "NOTE:"
log_info "* Check encoding via:"
log_info " # file ${f}"
log_info "* To convert ISO-8859/latin1 to UTF-8 execute:"
log_info " # iconv -f latin1 -t utf8 < ${f} > ${f}.tmp && mv ${f}.tmp ${f}"
exit 1
fi
done
}
check_config_syntax() {
log_debug "Checking for valid YAML syntax for $config_files"
for f in $config_files ; do
if [ -r "$f" ] ; then
# use YAML::Tiny for checking
log_debug "Validating main YAML syntax of ${f}"
if ! "${HELPER}/validate-yml" "${f}" 2>/dev/null ; then
log_error "Invalid file syntax in ${f}:"
"${HELPER}/validate-yml" "${f}"
exit 1
fi
fi
done
}
check_configs() {
check_config_encoding
check_config_syntax
}
if [ "$*" = "" ] ; then
config_files="${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES:-} ${CONSTANTS_CONFIG:-}"
else
config_files="$*"
fi
check_configs
exit 0
## END OF FILE #################################################################