# Include utilities. Use installed version if available and
# use build version if it isn't.
+# shellcheck disable=SC1091
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
printf "Checking if there is a database initialized already... Please ignore errors.\n"
result=$(cql_execute "DESCRIBE tables;")
+ # Shellcheck complaints about missing quotes and word splitting here. There
+ # is no problem here as wc -w always returns a single number.
+ # shellcheck disable=SC2046
if [ $(echo "$result" | grep "<empty>" | wc -w) -gt 0 ]; then
printf "Creating and initializing tables using script %s...\n" $scripts_dir/cql/dhcpdb_create.cql
cql_execute_script $scripts_dir/cql/dhcpdb_create.cql
then
echo "Output file, $file, exists and will be overwritten."
echo "Do you wish to continue? (y/n)"
- read ans
+ read -r ans
if [ "${ans}" != "y" ]
then
echo "$command aborted by user."
fi
# Now translate tabs to commas.
- cat $tmp_file | tr '\t' ',' >$dump_file
+ tr '\t' ',' < $tmp_file >$dump_file
retcode=$?
if [ $retcode -ne 0 ]; then
log_error "lease-dump: reformatting failed";
# Prints keactrl usage.
usage() {
+ # Shellcheck is too picky about this. This will work as long as keactrl
+ # script is not renamed to something with spaces or installed into a dir
+ # with spaces.
+ #
+ #shellcheck disable=SC2086
printf "usage is %s command [-c keactrl-config-file] [-s server[,server,..]]\n" \
- "$( basename -- ${0} )"
+ "$(basename -- ${0})"
printf "commands: start stop reload status version\n"
}
# Grab the PID if the file exists
if [ -e "${_pid_file}" ]; then
_pid=$(cat "${_pid_file}")
- if [ $? -ne 0 ]; then
+ retcode=$?
+ if [ $retcode -ne 0 ]; then
log_error "Error reading PID file: ${_pid_file}"
fi
else
if [ ${_pid} -gt 0 ]; then
# Use ps to check if PID is alive
ps -p ${_pid} 1>/dev/null
- if [ $? -eq 0 ]; then
+ retcode=$?
+ if [ $retcode -eq 0 ]; then
# No error, so PID IS ALIVE
_running=1
fi
process is not running\n"
else
kill "-${sig}" "${_pid}"
- if [ $? -ne 0 ]; then
+ retcode=$?
+ if [ $retcode -ne 0 ]; then
log_error "Failed to send signal ${sig} to process ${proc_name}, PID {$_pid}.\n"
fi
fi
# already running.
start_server() {
binary_path=${1} # Full path to the binary.
- full_command=$@ # Binary and arguments.
+ full_command=$* # Binary and arguments.
# Extract the name of the binary from the path.
local binary_name
binary_name=$(basename -- "${binary_path}")
else
log_info "Reloading ${binary_name}..."
kill -${sig} ${_pid}
- if [ $? -ne 0 ]; then
+ retcode=$?
+ if [ $retcode -ne 0 ]; then
log_error "Reload failed, could not send signal ${sig} \
to process ${proc_name}, PID ${_pid}.\n"
fi
if [ -e "${binary_path}" ]; then
ver=$(${binary_path} -v)
- if [ $? -ne 0 ]; then
+ retcode=$?
+ if [ $retcode -ne 0 ]; then
log_error "Error checking version of binary file: ${binary_path}"
fi
else
fi
# Include the configuration file.
+# Shellcheck complaints about not being to follow the source. Let's ingore it.
+# shellcheck disable=SC1090
. "${keactrl_conf}"
# Get location of the DHCPv4 server binary.
# shellcheck disable=SC2154
run_conditional "dhcp4" "start_server ${dhcp4_srv} -c ${kea_dhcp4_config_file} ${args}" 1
run_conditional "dhcp6" "start_server ${dhcp6_srv} -c ${kea_dhcp6_config_file} ${args}" 1
+ # shellcheck disable=SC2154
run_conditional "dhcp_ddns" "start_server ${dhcp_ddns_srv} -c ${kea_dhcp_ddns_config_file} \
${args}" 1
run_conditional "ctrl_agent" "start_server ${ctrl_agent_srv} -c ${kea_ctrl_agent_config_file} \
status)
kea4_status="inactive"
+ #shellcheck disable=SC2046
check_running $(basename -- "${dhcp4_srv}")
if [ ${_running} -eq 1 ]; then
kea4_status="active"
printf "DHCPv4 server: %s\n" "${kea4_status}"
kea6_status="inactive"
+ #shellcheck disable=SC2046
check_running $(basename -- "${dhcp6_srv}")
if [ ${_running} -eq 1 ]; then
kea6_status="active"
printf "DHCPv6 server: %s\n" "${kea6_status}"
d2_status="inactive"
+ #shellcheck disable=SC2046
check_running $(basename -- "${dhcp_ddns_srv}")
if [ ${_running} -eq 1 ]; then
d2_status="active"
printf "DHCP DDNS: %s\n" "${d2_status}"
agent_status="inactive"
+ #shellcheck disable=SC2046
check_running $(basename -- "${ctrl_agent_srv}")
if [ ${_running} -eq 1 ]; then
agent_status="active"
if [ "${have_netconf}" -eq 1 ]; then
netconf_status="inactive"
+ #shellcheck disable=SC2046
check_running $(basename -- "${netconf_srv}")
if [ "${_running}" -eq 1 ]; then
netconf_status="active"