Fix shellcheck warnings
This commit is contained in:
23
webdiff.sh
23
webdiff.sh
@@ -13,7 +13,7 @@ webdiff() {
|
|||||||
local retval=0
|
local retval=0
|
||||||
local diffname="$1"
|
local diffname="$1"
|
||||||
local diffurl="$2"
|
local diffurl="$2"
|
||||||
local diffline= # line count of current diff
|
local difflines= # line count of current diff
|
||||||
|
|
||||||
readonly _origin="$(cd "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
readonly _origin="$(cd "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
||||||
readonly newgrab="/tmp/webdiff/new_${diffname}"
|
readonly newgrab="/tmp/webdiff/new_${diffname}"
|
||||||
@@ -23,7 +23,8 @@ webdiff() {
|
|||||||
readonly wd_config="${_origin}/webdiff.conf"
|
readonly wd_config="${_origin}/webdiff.conf"
|
||||||
|
|
||||||
# end if no configuration is found
|
# end if no configuration is found
|
||||||
. "${wd_config}" 2>/dev/null || { printf "No configuration found\n"; return 1; }
|
# shellcheck disable=SC1090
|
||||||
|
. "${wd_config}" 2>/dev/null || { printf 'No configuration found\n'; return 1; }
|
||||||
|
|
||||||
# check parameter
|
# check parameter
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
@@ -33,33 +34,33 @@ webdiff() {
|
|||||||
shift 2
|
shift 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$(dirname "${newgrab}")" "$(dirname "${oldgrab}")"
|
mkdir -p "$(dirname "${newcurl}")" "$(dirname "${oldcurl}")"
|
||||||
|
|
||||||
# Save only the html <body> part for comparison
|
# Save only the html <body> part for comparison
|
||||||
curl -sL "${diffurl}" | grep -v "script id=" \
|
curl -sL "${diffurl}" | grep -v "script id=" \
|
||||||
| sed -n '/<body.*>/,/<\/body/p' > "${newgrab}" \
|
| sed -n '/<body.*>/,/<\/body/p' > "${newcurl}" \
|
||||||
|| { wd_callback_error "${diffname}" "${diffurl}" "curl"; return 1; }
|
|| { wd_callback_error "${diffname}" "${diffurl}" "curl"; return 1; }
|
||||||
|
|
||||||
# Apply custom sed command
|
# Apply custom sed command
|
||||||
if [[ "${1:-}" ]]; then
|
if [[ "${1:-}" ]]; then
|
||||||
cat "${newgrab}" | sed "$@" > "${newgrab}.2"
|
sed "$@" < "${newcurl}" > "${newcurl}.2"
|
||||||
mv "${newgrab}.2" "${newgrab}"
|
mv "${newcurl}.2" "${newcurl}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Initial diff shall not fail
|
# Initial diff shall not fail
|
||||||
[ ! -e "${oldgrab}" ] && cp "${newgrab}" "${oldgrab}"
|
[ ! -e "${oldcurl}" ] && cp "${newcurl}" "${oldcurl}"
|
||||||
|
|
||||||
# Write diff to file ${diffnow} and count lines
|
# Write diff to file ${diffnow} and count lines
|
||||||
difflines=$(diff "${newgrab}" "${oldgrab}" 2>/dev/null | tee "${diffnow}" | wc -l 2>/dev/null)
|
difflines=$(diff "${newcurl}" "${oldcurl}" 2>/dev/null | tee "${diffnow}" | wc -l 2>/dev/null)
|
||||||
[ $? -gt 1 ] && { wd_callback_error "${diffname}" "${diffurl}" "diff"; return 1; }
|
[ $? -gt 1 ] && { wd_callback_error "${diffname}" "${diffurl}" "diff"; return 1; }
|
||||||
|
|
||||||
if [ ${difflines} -ne 0 ]; then
|
if [ "${difflines}" -ne 0 ]; then
|
||||||
wd_callback_diff "${diffname}" "${diffurl}" "${difflines}" "${diffnow}"
|
wd_callback_diff "${diffname}" "${diffurl}" "${difflines}" "${diffnow}"
|
||||||
install -b -S "_$(date +%Y%m%d_%H%M%S).bck" "${newgrab}" "${oldgrab}"
|
install -b -S "_$(date +%Y%m%d_%H%M%S).bck" "${newcurl}" "${oldcurl}"
|
||||||
retval=1
|
retval=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "${newgrab}"
|
rm -f "${newcurl}"
|
||||||
|
|
||||||
return ${retval}
|
return ${retval}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user