TT#15824 Fix shellcheck warnings

Change-Id: I1e35b67b06ef7e628a34d113a328b5aea2758801
changes/35/13135/4
Alexander Lutay 8 years ago
parent 46c0acdf22
commit 6e554b5717

@ -17,7 +17,7 @@ CONFIG_POOL="${CONFIG_POOL:-/etc}"
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
. ${FUNCTIONS}/main
. "${FUNCTIONS}"/main
# main script
@ -37,15 +37,15 @@ export output_file="${y}" # like /etc/mysql/my.cnf, export variable
if [ -r "${NGCPCTL_MAIN}/templates/${output_file}.prebuild" ] ; then
log_info "Executing prebuild for ${output_file}"
bash "${NGCPCTL_MAIN}/templates/${output_file}.prebuild"
elif [ -r "${NGCPCTL_MAIN}/templates/$(dirname ${output_file})/ngcpcfg.prebuild" ] ; then
elif [ -r "${NGCPCTL_MAIN}/templates/$(dirname "${output_file}")/ngcpcfg.prebuild" ] ; then
log_info "Executing prebuild for ${output_file}"
bash "${NGCPCTL_MAIN}/templates/$(dirname ${output_file})/ngcpcfg.prebuild"
bash "${NGCPCTL_MAIN}/templates/$(dirname "${output_file}")/ngcpcfg.prebuild"
fi
# if output directory does not exist yet, create it
if ! [ -d "$(dirname ${output_file})" ] ; then
if ! [ -d "$(dirname "${output_file}")" ] ; then
umask 0022 # directory permissions should be '755'
mkdir -p "$(dirname ${output_file})"
mkdir -p "$(dirname "${output_file}")"
fi
# assume safe defaults
@ -85,9 +85,9 @@ chmod a-w "${output_file}"
if [ -r "${NGCPCTL_MAIN}/templates/${output_file}.postbuild" ] ; then
log_info "Executing postbuild for ${output_file}"
bash "${NGCPCTL_MAIN}/templates/${output_file}.postbuild"
elif [ -r "${NGCPCTL_MAIN}/templates/$(dirname ${output_file})/ngcpcfg.postbuild" ] ; then
elif [ -r "${NGCPCTL_MAIN}/templates/$(dirname "${output_file}")/ngcpcfg.postbuild" ] ; then
log_info "Executing postbuild for ${output_file}"
bash "${NGCPCTL_MAIN}/templates/$(dirname ${output_file})/ngcpcfg.postbuild"
bash "${NGCPCTL_MAIN}/templates/$(dirname "${output_file}")/ngcpcfg.postbuild"
fi
exit $RC

@ -12,7 +12,7 @@ if [ "$MYSQLID" = "2" ] ; then
SUFF="2"
fi
if ! [ $COUNT -ge 0 2>/dev/null ] ; then
if [ $COUNT -le 0 ] ; then
echo "Usage: $0 <number_of_seconds> [<mysqlid>]" >&2
exit 1
fi
@ -31,14 +31,17 @@ mysqld_get_param() {
}
mysqld_status () {
ping_output=$(/usr/bin/mysqladmin --defaults-group-suffix=$SUFF \
--defaults-file=/etc/mysql/debian.cnf ping 2>&1)
ping_alive=$(( ! $? ))
if /usr/bin/mysqladmin --defaults-group-suffix=$SUFF \
--defaults-file=/etc/mysql/debian.cnf ping 2>&1 ; then
ping_alive=1
else
ping_alive=0
fi
ps_alive=0
pidfile=$(mysqld_get_param pid-file)
if [ -f "$pidfile" ] && ps $(cat $pidfile) &>/dev/null ; then
if [ -f "$pidfile" ] && ps "$(cat "$pidfile")" &>/dev/null ; then
ps_alive=1
fi
@ -51,7 +54,7 @@ mysqld_status () {
}
printf "Checking MySQL service status (for a maximum of %s seconds): " "$COUNT"
for i in $(seq 1 $COUNT) ; do
for _ in $(seq 1 $COUNT) ; do
if mysqld_status check_alive warn; then
printf "available.\n"
exit 0

@ -15,7 +15,7 @@ FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
SCRIPTS="${SCRIPTS:-/usr/share/ngcp-ngcpcfg/scripts/}"
if ! [ -r "${FUNCTIONS}/main" ] ; then
printf "Error: ${FUNCTIONS}/main could not be read. Exiting.\n" >&2
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}" >&2
exit 1
fi
@ -29,7 +29,7 @@ if [[ "${1:-}" == "decrypt" ]] ; then
fi
}
else
. ${FUNCTIONS}/main
. "${FUNCTIONS}"/main
fi
# helper functions
@ -46,7 +46,7 @@ usage() {
[ "${1:-}" = "1" ] && exec >&2
printf "%s - Configuration Management System\n\n" "$PN"
printf "Usage: $PN <action> [<opts>]
printf "Usage: %s <action> [<opts>]
Actions:
check [<path>] validate YAML configuration files
@ -58,7 +58,7 @@ Actions:
status [<opts>] display status of configuration file
log [<opts>] show log of config changes
show [<id>] show latest config change (or <id> if specified)
"
" "$PN"
# display only if ngcp-ngcpcfg-ha is available
if [ -r /usr/share/ngcp-ngcpcfg/functions/ha_features ] ; then
@ -91,9 +91,9 @@ Actions:
}
version() {
versinfo=$(dpkg-query -f '${Version}' -W ngcp-ngcpcfg 2>/dev/null)
versinfo=$(dpkg-query -f "\${Version}" -W ngcp-ngcpcfg 2>/dev/null)
[ -n "${versinfo:-}" ] || versinfo='information not available'
printf "ngcpcfg, version ${versinfo}\n"
printf "ngcpcfg, version %s\n" "${versinfo}"
}
case ${1:-} in

@ -16,7 +16,6 @@ if ! [ -r "${FUNCTIONS}"/main ] ; then
exit 1
fi
timestamp_replacementchars=''
. "${FUNCTIONS}"/main
# based on check_local_state() from scripts/status

@ -11,12 +11,12 @@ FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
SCRIPTS="${SCRIPTS:-/usr/share/ngcp-ngcpcfg/scripts/}"
if ! [ -r ${FUNCTIONS}/main ] ; then
printf "Error: ${FUNCTIONS}/main could not be read. Exiting.\n" >&2
if ! [ -r "${FUNCTIONS}"/main ] ; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}" >&2
exit 1
fi
. ${FUNCTIONS}/main
. "${FUNCTIONS}"/main
# Sanity check the YAML and schema files.
"${SCRIPTS}"/check
@ -33,7 +33,7 @@ killall tt2-daemon 2>/dev/null || true
rm -f /var/run/ngcpcfg.port
# Start new tt2-daemon Perl process
${HELPER}/tt2-daemon
"${HELPER}"/tt2-daemon
# Load all the configs in proper order and check their avialability and valid YAML syntax
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES:-} ${CONSTANTS_CONFIG:-} ; do
@ -50,7 +50,7 @@ build_config_files() {
for file in $(generate_template_list "$@") ; do
log_debug "${HELPER}/build_config $file"
"${HELPER}/build_config" "${file}"
RC=$(($RC + $?))
RC=$((RC + $?))
done
record_commit_id
@ -73,7 +73,7 @@ else
if [ -n "${EXTRA_CONFIG_FILES:-}" ] ; then
for file in $EXTRA_CONFIG_FILES ; do
if git diff-index --name-only HEAD | grep -qe -- "$(basename $file)" ; then
if git diff-index --name-only HEAD | grep -qe -- "$(basename "$file")" ; then
log_debug "modification in EXTRA_CONFIG_FILES file $file found"
trigger_rebuild=true
break # no reason for further checks
@ -82,11 +82,11 @@ else
fi
if git diff-index --name-only HEAD | grep \
-qe "$(basename $NGCPCTL_CONFIG)" \
-qe "$(basename $HOST_CONFIG)" \
-qe "$(basename $LOCAL_CONFIG)" \
-qe "$(basename $NETWORK_CONFIG)" \
-qe "$(basename $CONSTANTS_CONFIG)" ; then
-qe "$(basename "$NGCPCTL_CONFIG")" \
-qe "$(basename "$HOST_CONFIG")" \
-qe "$(basename "$LOCAL_CONFIG")" \
-qe "$(basename "$NETWORK_CONFIG")" \
-qe "$(basename "$CONSTANTS_CONFIG")" ; then
log_debug "modification in main configuration file found"
trigger_rebuild=true
fi
@ -108,9 +108,9 @@ else
# drop HA file suffix of all registered nodes
if [ -r /etc/ngcp-config/systems.cfg ] ; then
for host in $(cat /etc/ngcp-config/systems.cfg) ; do
build_file="${build_file%%.${host}}"
done
while IFS= read -r host ; do
build_file="${build_file%%.${host}}"
done < /etc/ngcp-config/systems.cfg
fi
build_file="${build_file%%.tt2}"
@ -128,7 +128,7 @@ else
done
log_debug "Executing: build_config_files ${file_list}"
build_config_files ${file_list}
build_config_files "${file_list}"
fi
fi

@ -24,7 +24,7 @@ fi
cd "$NGCPCTL_MAIN"
git show ${git_commit}
git show "${git_commit}"
exit 0

@ -11,19 +11,20 @@ else
bailout() { exit 1; }
fi
export testsuite="$(dirname $PWD/$0)"
testsuite="$(dirname "${PWD}/$0")"
export testsuite
TMPDIR="$(mktemp -d)"
echo "Switching to temporary directory $TMPDIR"
cd "$TMPDIR"
cp -a ${testsuite}/* .
cp -a "${testsuite}"/* .
export FUNCTIONS="$testsuite/../functions/"
export HELPER="$testsuite/../helper/"
export SCRIPTS="$testsuite/../scripts/"
echo -n "Testing ngcpcfg without any arguments: "
if $testsuite/../sbin/ngcpcfg 2>&1 | grep -q "^Usage:$" ; then
if "$testsuite"/../sbin/ngcpcfg 2>&1 | grep -q "^Usage:$" ; then
echo OK
else
echo "Error with executing ngcpcfg without any arguments" >&2
@ -31,7 +32,7 @@ else
fi
echo -n "Testing ngcpcfg --help: "
if $testsuite/../sbin/ngcpcfg --help 2>&1 | grep -q "^Usage:$" ; then
if "$testsuite"/../sbin/ngcpcfg --help 2>&1 | grep -q "^Usage:$" ; then
echo OK
else
echo "Error with executing ngcpcfg --help" >&2
@ -39,7 +40,7 @@ else
fi
echo -n "Testing ngcpcfg --version: "
if $testsuite/../sbin/ngcpcfg --version 2>&1 | grep -q "version" ; then
if "$testsuite"/../sbin/ngcpcfg --version 2>&1 | grep -q "version" ; then
echo OK
else
echo "Error with executing ngcpcfg --version" >&2
@ -47,12 +48,9 @@ else
fi
echo "Testing ngcpcfg build:"
$testsuite/../sbin/ngcpcfg build > build.log
"$testsuite"/../sbin/ngcpcfg build > build.log
oldIFS="$IFS"
IFS="
"
for line in $(cat build.log) ; do
while IFS= read -r line ; do
case "$line" in
Generating\ testsuite/*OK) echo generation OK ;;
Executing\ postbuild\ for\ testsuite/*) echo postbuild OK;;
@ -63,8 +61,7 @@ for line in $(cat build.log) ; do
bailout
;;
esac
done
IFS="$oldIFS"
done < build.log
# test main tt2 processing
if [[ $(cat testsuite/testtemplate) == "foo" ]] ; then

@ -23,11 +23,11 @@ bailout() {
trap bailout 1 2 3 3 6 9 14 15
OK() {
printf "ok ${1} ${2}\n"
printf "ok %s %s\n" "$1" "$2"
}
FAIL() {
printf "not ok ${1} ${2}\n"
printf "not ok %s %s\n" "$1" "$2"
RC=1
}
@ -112,7 +112,7 @@ assertEqualFiles testfiles/deployment.yml network-config/deployment.yml
# TAP output
printf "1..$count\n"
printf "1..%s\n" "${count}"
cat "$OUTPUT"
bailout

@ -11,19 +11,20 @@ else
bailout() { exit 1; }
fi
export testsuite="$(dirname $PWD/$0)"
testsuite="$(dirname "${PWD}/$0")"
export testsuite
TMPDIR="$(mktemp -d)"
echo "Switching to temporary directory $TMPDIR"
cd "$TMPDIR"
cp -a ${testsuite}/* .
cp -a "${testsuite}"/* .
export FUNCTIONS="$testsuite/../functions/"
export HELPER="$testsuite/../helper/"
export SCRIPTS="$testsuite/../scripts/"
echo -n "Testing ngcpcfg without any arguments: "
if $testsuite/../sbin/ngcpcfg 2>&1 | grep -q "^Usage:$" ; then
if "$testsuite"/../sbin/ngcpcfg 2>&1 | grep -q "^Usage:$" ; then
echo OK
else
echo "Error with executing ngcpcfg without any arguments" >&2
@ -31,7 +32,7 @@ else
fi
echo -n "Testing ngcpcfg --help: "
if $testsuite/../sbin/ngcpcfg --help 2>&1 | grep -q "^Usage:$" ; then
if "$testsuite"/../sbin/ngcpcfg --help 2>&1 | grep -q "^Usage:$" ; then
echo OK
else
echo "Error with executing ngcpcfg --help" >&2
@ -39,7 +40,7 @@ else
fi
echo -n "Testing ngcpcfg --version: "
if $testsuite/../sbin/ngcpcfg --version 2>&1 | grep -q "version" ; then
if "$testsuite"/../sbin/ngcpcfg --version 2>&1 | grep -q "version" ; then
echo OK
else
echo "Error with executing ngcpcfg --version" >&2
@ -47,21 +48,21 @@ else
fi
echo "Testing ngcpcfg values: database.dbhost"
value=$($testsuite/../sbin/ngcpcfg values database.dbhost)
value=$("$testsuite"/../sbin/ngcpcfg values database.dbhost)
if [ "${value}" != "localhost" ] ; then
echo "Error caught: database.dbhost != 'localhost'"
bailout
fi
echo "Testing ngcpcfg values: ossbss.provisioning.database.user"
value=$($testsuite/../sbin/ngcpcfg values ossbss.provisioning.database.user)
value=$("$testsuite"/../sbin/ngcpcfg values ossbss.provisioning.database.user)
if [ "${value}" != "soap" ] ; then
echo "Error caught: ossbss.provisioning.database.user != 'soap'"
bailout
fi
echo "Testing ngcpcfg values: www_admin.fees_csv.element_order"
value=$($testsuite/../sbin/ngcpcfg values www_admin.fees_csv.element_order)
value=$("$testsuite"/../sbin/ngcpcfg values www_admin.fees_csv.element_order)
if [ "${value}" != "destination zone zone_detail onpeak_init_rate \
onpeak_init_interval onpeak_follow_rate onpeak_follow_interval \
offpeak_init_rate offpeak_init_interval offpeak_follow_rate \

Loading…
Cancel
Save