Apply shellcheck recommendations and add simple pipeline
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Alexander Schäferdiek 2022-07-10 20:47:46 +02:00
parent 9c79b41909
commit 0ee7b03df8
12 changed files with 63 additions and 18 deletions

8
.drone.yml Normal file
View file

@ -0,0 +1,8 @@
kind: pipeline
name: default
steps:
- name: test
image: koalaman/shellcheck-alpine:latest
commands:
- find usr/local/bin -type f -exec shellcheck {} \;

View file

@ -0,0 +1,10 @@
[Unit]
Description=Run dynv6
OnFailure=systemd_failure_notify@%n.service
[Service]
Type=oneshot
ExecStart=dynv6
[Install]
WantedBy=default.target

View file

@ -0,0 +1,9 @@
[Unit]
Description=Run dynv6
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target

View file

@ -38,6 +38,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -65,7 +66,7 @@ source_config() {
source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf" source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf"
if [ "$UPDATES_AMOUNT" -gt "0" ]; then if [ "$UPDATES_AMOUNT" -gt "0" ]; then
mailx -s "[updates $HOSTNAME]" $CHECK_UPDATES_MAIL_ADDRESS << EOF mailx -s "[updates $HOSTNAME]" "$CHECK_UPDATES_MAIL_ADDRESS" << EOF
There are $UPDATES_AMOUNT updates available on $HOSTNAME. There are $UPDATES_AMOUNT updates available on $HOSTNAME.
$UPDATES $UPDATES

View file

@ -42,6 +42,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -70,12 +71,12 @@ source_config "$1" "$HOME/.disk_space_alert.conf" "/etc/disk_space_alert.conf"
for point in "${DISK_SPACE_ALERT_MOUNTPOINTS[@]}" for point in "${DISK_SPACE_ALERT_MOUNTPOINTS[@]}"
do do
CURRENT=$(df $point | grep $point | awk '{ print $5}' | sed 's/%//g') CURRENT=$(df "$point" | grep "$point" | awk '{ print $5}' | sed 's/%//g')
CURRENT_SPACE=$(df $point | grep $point | awk '{ print $5}' | sed 's/%//g') CURRENT_SPACE=$(df "$point" | grep "$point" | awk '{ print $5}' | sed 's/%//g')
CURRENT_INODES=$(df -i $point | grep $point | awk '{ print $5}' | sed 's/%//g') CURRENT_INODES=$(df -i "$point" | grep "$point" | awk '{ print $5}' | sed 's/%//g')
if [ "$CURRENT" -gt "$DISK_SPACE_ALERT_THRESHOLD" ] ; then if [ "$CURRENT" -gt "$DISK_SPACE_ALERT_THRESHOLD" ] ; then
mailx -s "[disk $HOSTNAME] $point" $DISK_SPACE_ALERT_MAIL_ADDRESS << EOF mailx -s "[disk $HOSTNAME] $point" "$DISK_SPACE_ALERT_MAIL_ADDRESS" << EOF
Your $point partition remaining free space is critically low. Used space: $CURRENT_SPACE%. Used inodes: $CURRENT_INODES%. Your $point partition remaining free space is critically low. Used space: $CURRENT_SPACE%. Used inodes: $CURRENT_INODES%.
EOF EOF
fi fi

View file

@ -44,6 +44,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -110,13 +111,14 @@ function log() {
local STATUS=$2; local STATUS=$2;
local MESSAGE=$3; local MESSAGE=$3;
# shellcheck disable=SC2155
local SHOULD_LOG=$(shouldLog "$STATUS"); local SHOULD_LOG=$(shouldLog "$STATUS");
if [ "$SHOULD_LOG" = "true" ]; then if [ "$SHOULD_LOG" = "true" ]; then
local SUBJECT="[docker $HOSTNAME] $STATUS $CONTAINER"; local SUBJECT="[docker $HOSTNAME] $STATUS $CONTAINER";
echo "$SUBJECT: $MESSAGE"; echo "$SUBJECT: $MESSAGE";
if [ "$DOCKER_CHECK_MAIL_ENABLED" = true ]; then if [ "$DOCKER_CHECK_MAIL_ENABLED" = true ]; then
echo $MESSAGE|mailx -Ssendwait -s "$SUBJECT" $DOCKER_CHECK_MAIL_ADDRESS; echo "$MESSAGE"|mailx -Ssendwait -s "$SUBJECT" "$DOCKER_CHECK_MAIL_ADDRESS";
fi fi
fi fi
} }
@ -125,35 +127,38 @@ function log() {
function checkContainer() { function checkContainer() {
local CONTAINER=$1; local CONTAINER=$1;
# shellcheck disable=SC2268
if [ "x${CONTAINER}" == "x" ]; then if [ "x${CONTAINER}" == "x" ]; then
log "$CONTAINER" "UNKNOWN" "Container ID or Friendly Name Required" log "$CONTAINER" "UNKNOWN" "Container ID or Friendly Name Required"
return; return;
fi fi
# shellcheck disable=SC2268
if [ "x$(which docker)" == "x" ]; then if [ "x$(which docker)" == "x" ]; then
log "$CONTAINER" "UNKNOWN" "Missing docker binary" log "$CONTAINER" "UNKNOWN" "Missing docker binary"
return; return;
fi fi
docker info > /dev/null 2>&1 docker info > /dev/null 2>&1
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log "$CONTAINER" "UNKNOWN" "Unable to talk to the docker daemon" log "$CONTAINER" "UNKNOWN" "Unable to talk to the docker daemon"
return; return;
fi fi
RUNNING=$(docker inspect --format="{{.State.Running}}" $CONTAINER 2> /dev/null) RUNNING=$(docker inspect --format="{{.State.Running}}" "$CONTAINER" 2> /dev/null)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
log "$CONTAINER" "UNKNOWN" "$CONTAINER does not exist." log "${CONTAINER}" "UNKNOWN" "$CONTAINER does not exist."
return; return;
fi fi
if [ "$RUNNING" == "false" ]; then if [ "$RUNNING" == "false" ]; then
log "$CONTAINER" "CRITICAL" "$CONTAINER is not running." log "${CONTAINER}" "CRITICAL" "$CONTAINER is not running."
return; return;
fi fi
RESTARTING=$(docker inspect --format="{{.State.Restarting}}" $CONTAINER) RESTARTING=$(docker inspect --format="{{.State.Restarting}}" "$CONTAINER")
if [ "$RESTARTING" == "true" ]; then if [ "$RESTARTING" == "true" ]; then
log "$CONTAINER" "WARNING" "$CONTAINER state is restarting." log "$CONTAINER" "WARNING" "$CONTAINER state is restarting."

View file

@ -40,6 +40,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -91,6 +92,7 @@ check_required;
# DO NOT TOUCH BELOW # DO NOT TOUCH BELOW
currentDir=$(pwd) currentDir=$(pwd)
echo "Current directory is '${currentDir}'"
cd "${DOCKER_COMPOSE_UPDATE_BASEDIR}"; cd "${DOCKER_COMPOSE_UPDATE_BASEDIR}";
for dir in *; do for dir in *; do
@ -131,6 +133,7 @@ for dir in *; do
set +e; set +e;
fi fi
# shellcheck disable=SC2034
res=$(eval "${updateCommand}") res=$(eval "${updateCommand}")
if [[ "${DOCKER_COMPOSE_UPDATE_FAIL_ON_UPDATE_ERROR}" == "false" ]]; then if [[ "${DOCKER_COMPOSE_UPDATE_FAIL_ON_UPDATE_ERROR}" == "false" ]]; then

View file

@ -38,6 +38,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -124,7 +125,7 @@ if [ "${DYNV6_IPV6_ENABLED}" = "true" ]; then
touch "${ipv6AddressLocalFile}"; touch "${ipv6AddressLocalFile}";
fi fi
if grep --color=never -Fxq ${ipv6Address} "${ipv6AddressLocalFile}"; then if grep --color=never -Fxq "${ipv6Address}" "${ipv6AddressLocalFile}"; then
echo "IPv6 is still ${ipv6Address}"; echo "IPv6 is still ${ipv6Address}";
else else
echo "IPv6 changed" echo "IPv6 changed"

View file

@ -41,6 +41,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -71,6 +72,7 @@ source_config "$1" "$HOME/.memory_usage_alert.conf" "/etc/memory_usage_alert.con
# DO NOT TOUCH BELOW # DO NOT TOUCH BELOW
total=$(free -mt | grep Total | awk '{print $2}') total=$(free -mt | grep Total | awk '{print $2}')
used=$(free -mt | grep Total | awk '{print $3}') used=$(free -mt | grep Total | awk '{print $3}')
# shellcheck disable=SC2004
free=$(($total-$used)) free=$(($total-$used))
if [[ "$free" -le $MEMORY_USAGE_ALERT_THRESHOLD ]]; then if [[ "$free" -le $MEMORY_USAGE_ALERT_THRESHOLD ]]; then

View file

@ -38,6 +38,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -66,11 +67,11 @@ source_config "$1" "$HOME/.smartctl_tests_long.conf" "/etc/smartctl_tests_long.c
echo "Starting long tests for ..."; echo "Starting long tests for ...";
for d in ${SMARTCTL_TESTS_LONG_DEVICES[@]}; do for d in "${SMARTCTL_TESTS_LONG_DEVICES[@]}"; do
DEVICE="/dev/"$d; DEVICE="/dev/$d";
echo $DEVICE; echo "$DEVICE";
smartctl -t long $DEVICE; smartctl -t long "$DEVICE";
mailx -s "[smartd $HOSTNAME] queued long test" $SMARTCTL_TESTS_LONG_MAIL_ADDRESS << EOF mailx -s "[smartd $HOSTNAME] queued long test" "$SMARTCTL_TESTS_LONG_MAIL_ADDRESS" << EOF
Queued a smartd long test for $DEVICE. Queued a smartd long test for $DEVICE.
EOF EOF
done done

View file

@ -48,6 +48,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -105,10 +106,12 @@ function checkService() {
local RESULT=0; local RESULT=0;
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
# shellcheck disable=SC2091
if ! $($USER_COMMAND); then if ! $($USER_COMMAND); then
RESULT=1; RESULT=1;
fi fi
else else
# shellcheck disable=SC2091
if ! $($ROOT_COMMAND) && ! $($USER_COMMAND); then if ! $($ROOT_COMMAND) && ! $($USER_COMMAND); then
RESULT=1; RESULT=1;
fi fi
@ -119,7 +122,7 @@ function checkService() {
echo "-> $SUBJECT: $MESSAGE"; echo "-> $SUBJECT: $MESSAGE";
if [ "$SYSTEMD_CHECK_MAIL_ENABLED" = true ]; then if [ "$SYSTEMD_CHECK_MAIL_ENABLED" = true ]; then
echo $MESSAGE|mailx -Ssendwait -s "$SUBJECT" $SYSTEMD_CHECK_MAIL_ADDRESS; echo "$MESSAGE"|mailx -Ssendwait -s "$SUBJECT" "$SYSTEMD_CHECK_MAIL_ADDRESS";
fi fi
fi fi

View file

@ -54,6 +54,7 @@ apply_config() {
fi fi
set -a; set -a;
# shellcheck disable=SC1090
source "$config"; source "$config";
set +a; set +a;
} }
@ -82,4 +83,4 @@ source_config "$2" "$HOME/.systemd_failure_notify.conf" "/etc/systemd_failure_no
SUBJECT="[systemd $SYSTEMD_FAILURE_NOTFY_HOSTNAME for $SYSTEMD_FAILURE_NOTFY_USER] $SYSTEMD_FAILURE_NOTFY_SERVICE RUN FAILED" SUBJECT="[systemd $SYSTEMD_FAILURE_NOTFY_HOSTNAME for $SYSTEMD_FAILURE_NOTFY_USER] $SYSTEMD_FAILURE_NOTFY_SERVICE RUN FAILED"
MESSAGE="$SYSTEMD_FAILURE_NOTFY_SERVICE run failed" MESSAGE="$SYSTEMD_FAILURE_NOTFY_SERVICE run failed"
echo $MESSAGE|mailx -Ssendwait -s "$SUBJECT" $SYSTEMD_FAILURE_NOTIFY_MAIL_ADDRESS; echo "$MESSAGE"|mailx -Ssendwait -s "$SUBJECT" "$SYSTEMD_FAILURE_NOTIFY_MAIL_ADDRESS";