Code cleanup as reported by shellcheck
This commit is contained in:
parent
f97da29cee
commit
0f9adac2cd
1 changed files with 26 additions and 36 deletions
|
@ -43,14 +43,12 @@ valid_ip() {
|
|||
valid_ipv4() {
|
||||
local ip=$1
|
||||
local stat=1
|
||||
local ipaddr
|
||||
|
||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
OIFS=$IFS
|
||||
IFS='.'
|
||||
ip=($ip)
|
||||
IFS=$OIFS
|
||||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||||
IFS='.' read -ra ipaddr <<< "$ip"
|
||||
[[ ${ipaddr[0]} -le 255 && ${ipaddr[1]} -le 255 \
|
||||
&& ${ipaddr[2]} -le 255 && ${ipaddr[3]} -le 255 ]]
|
||||
stat=$?
|
||||
fi
|
||||
return $stat
|
||||
|
@ -73,7 +71,7 @@ getRecords() {
|
|||
if [[ ! -r "$file" ]]; then
|
||||
return 1
|
||||
else
|
||||
while read r;
|
||||
while read -r r;
|
||||
do
|
||||
r=$(trim "$r")
|
||||
[[ ${r:0:1} == '#' ]] && continue
|
||||
|
@ -138,11 +136,13 @@ getIPv6() {
|
|||
|
||||
getDnsNS() {
|
||||
local rec=$1
|
||||
local domain=$(sed 's/[^.]*\.\([^.]*\..*\)/\1/' <<<"$rec")
|
||||
local domain
|
||||
local result
|
||||
local err
|
||||
|
||||
result=$(dig +short @8.8.8.8 NS $domain | sed -e 's/.$//')
|
||||
domain=$(sed 's/[^.]*\.\([^.]*\..*\)/\1/' <<<"$rec")
|
||||
|
||||
result=$(dig +short @8.8.8.8 NS "$domain" | sed -e 's/.$//')
|
||||
err=$?
|
||||
|
||||
if [[ $err -eq 0 ]]
|
||||
|
@ -167,7 +167,7 @@ getDnsRecord() {
|
|||
do
|
||||
[[ "$i" = "ERROR" ]] && return 1
|
||||
|
||||
result=$(dig +short @${i} ${rectype} ${rec} | head -n1)
|
||||
result=$(dig +short @"$i" "$rectype" "$rec" | head -n1)
|
||||
err=$?
|
||||
|
||||
if [[ $err -ne 0 ]] || [[ -z "$result" ]]; then
|
||||
|
@ -189,7 +189,7 @@ getIPv6Prefix() {
|
|||
local result
|
||||
local err
|
||||
|
||||
if valid_ipv6 $rec
|
||||
if valid_ipv6 "$rec"
|
||||
then
|
||||
result=$(echo "$rec" | cut -d':' -f1-4)
|
||||
result="${result}::/64"
|
||||
|
@ -260,12 +260,12 @@ log() {
|
|||
}
|
||||
|
||||
logerr() {
|
||||
>&2 log $*
|
||||
>&2 log "$@"
|
||||
}
|
||||
|
||||
run-parts() {
|
||||
# Ignore *~ and *, scripts
|
||||
for i in $(LC_ALL=C; echo ${1%/}/*[^~,]) ; do
|
||||
for i in $(LC_ALL=C; echo "${1%/}"/*[^~,]) ; do
|
||||
[[ -d $i ]] && continue
|
||||
# Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} scripts
|
||||
[[ "${i%.cfsaved}" != "${i}" ]] && continue
|
||||
|
@ -301,24 +301,25 @@ run-parts() {
|
|||
run-hook() {
|
||||
local hook_dir=$1
|
||||
local errors=0
|
||||
local hook_script
|
||||
shift
|
||||
|
||||
if [[ ! -d "${hook_dir}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
while read s
|
||||
while read -r hook_script
|
||||
do
|
||||
log "Running agent: $(basename "$s")"
|
||||
log "Running agent: $(basename "$hook_script")"
|
||||
DIP_FUNCTIONS="$(readlink -f "$0")" \
|
||||
DIP_AGENT_NAME="$(basename "$(readlink -f "$s")")" \
|
||||
DIP_AGENT_EXEC="$(basename "$s")" \
|
||||
DIP_AGENT_DIR="$(dirname "$(readlink -f "$s")")" \
|
||||
DIP_AGENT_NAME="$(basename "$(readlink -f "$hook_script")")" \
|
||||
DIP_AGENT_EXEC="$(basename "$hook_script")" \
|
||||
DIP_AGENT_DIR="$(dirname "$(readlink -f "$hook_script")")" \
|
||||
DIP_BASE_DIR="${script_dir}" \
|
||||
DIP_CUR_IP="$1" \
|
||||
DIP_OLD_IP="$2" \
|
||||
DIP_RECORD="$3" \
|
||||
"$s" $*
|
||||
"$hook_script" "$@"
|
||||
err=$?
|
||||
|
||||
if [[ $err -ne 0 ]]; then
|
||||
|
@ -400,7 +401,7 @@ check-update() {
|
|||
[[ -z "$iptype" ]] && return 1
|
||||
[[ -z "$record" ]] && return 1
|
||||
|
||||
getCurrentIP $iptype $record
|
||||
getCurrentIP "$iptype" "$record"
|
||||
err=$?
|
||||
|
||||
case $err in
|
||||
|
@ -427,7 +428,7 @@ check-update() {
|
|||
logerr "DEBUG: dig output '$externalip'"
|
||||
;;
|
||||
*) logerr "Unknown fatal error occurred"
|
||||
eclogerrho "(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }"
|
||||
logerr "(${BASH_SOURCE[0]}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }"
|
||||
exit $err
|
||||
;;
|
||||
esac
|
||||
|
@ -445,8 +446,8 @@ prog_lock() {
|
|||
LOCKFD=99
|
||||
|
||||
# PRIVATE
|
||||
_lock() { flock -$1 $LOCKFD; }
|
||||
_no_more_locking() { _lock u; _lock xn && rm -f $LOCKFILE; }
|
||||
_lock() { flock -"$1" $LOCKFD; }
|
||||
_no_more_locking() { _lock u; _lock xn && rm -f "$LOCKFILE"; }
|
||||
_prepare_locking() { eval "exec $LOCKFD>\"$LOCKFILE\""; trap _no_more_locking EXIT; }
|
||||
|
||||
# ON START
|
||||
|
@ -473,27 +474,16 @@ prog_lock() {
|
|||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
# Internal Initialization
|
||||
|
||||
prog_name=$(basename "$0")
|
||||
#prog_name=$(basename "$0")
|
||||
script_dir=$(dirname "$(readlink -f "$0")")
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
logerr "ERROR: Need to provide a DNS record or file to look-up"
|
||||
exit 1
|
||||
else
|
||||
if [[ -r "$1" ]]; then
|
||||
record_file=$1
|
||||
else
|
||||
record=$1
|
||||
fi
|
||||
fi
|
||||
|
||||
prog_lock
|
||||
|
||||
|
||||
# Main
|
||||
if [[ -r "${script_dir}/plugins/${1}" ]]; then
|
||||
# shellcheck source=plugins/update-ipv4
|
||||
source "${script_dir}/plugins/${1}"
|
||||
plugin_name=${1,,}
|
||||
else
|
||||
logerr "ERROR: Unknown plugin '${1}'"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue