Apply shellcheck recommendations and add simple pipeline
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
parent
9c79b41909
commit
0ee7b03df8
12 changed files with 63 additions and 18 deletions
8
.drone.yml
Normal file
8
.drone.yml
Normal 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 {} \;
|
10
etc/systemd/system/dynv6.service
Normal file
10
etc/systemd/system/dynv6.service
Normal file
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Run dynv6
|
||||
OnFailure=systemd_failure_notify@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=dynv6
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
9
etc/systemd/system/dynv6.timer
Normal file
9
etc/systemd/system/dynv6.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run dynv6
|
||||
|
||||
[Timer]
|
||||
OnCalendar=hourly
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
|
@ -38,6 +38,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -65,7 +66,7 @@ source_config() {
|
|||
source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf"
|
||||
|
||||
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.
|
||||
|
||||
$UPDATES
|
||||
|
|
|
@ -42,6 +42,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
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[@]}"
|
||||
do
|
||||
CURRENT=$(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=$(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')
|
||||
|
||||
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%.
|
||||
EOF
|
||||
fi
|
||||
|
|
|
@ -44,6 +44,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -110,13 +111,14 @@ function log() {
|
|||
local STATUS=$2;
|
||||
local MESSAGE=$3;
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local SHOULD_LOG=$(shouldLog "$STATUS");
|
||||
if [ "$SHOULD_LOG" = "true" ]; then
|
||||
local SUBJECT="[docker $HOSTNAME] $STATUS $CONTAINER";
|
||||
echo "$SUBJECT: $MESSAGE";
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -125,35 +127,38 @@ function log() {
|
|||
function checkContainer() {
|
||||
local CONTAINER=$1;
|
||||
|
||||
# shellcheck disable=SC2268
|
||||
if [ "x${CONTAINER}" == "x" ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "Container ID or Friendly Name Required"
|
||||
return;
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2268
|
||||
if [ "x$(which docker)" == "x" ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "Missing docker binary"
|
||||
return;
|
||||
fi
|
||||
|
||||
docker info > /dev/null 2>&1
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ]; then
|
||||
log "$CONTAINER" "UNKNOWN" "Unable to talk to the docker daemon"
|
||||
return;
|
||||
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
|
||||
log "$CONTAINER" "UNKNOWN" "$CONTAINER does not exist."
|
||||
log "${CONTAINER}" "UNKNOWN" "$CONTAINER does not exist."
|
||||
return;
|
||||
fi
|
||||
|
||||
if [ "$RUNNING" == "false" ]; then
|
||||
log "$CONTAINER" "CRITICAL" "$CONTAINER is not running."
|
||||
log "${CONTAINER}" "CRITICAL" "$CONTAINER is not running."
|
||||
return;
|
||||
fi
|
||||
|
||||
RESTARTING=$(docker inspect --format="{{.State.Restarting}}" $CONTAINER)
|
||||
RESTARTING=$(docker inspect --format="{{.State.Restarting}}" "$CONTAINER")
|
||||
|
||||
if [ "$RESTARTING" == "true" ]; then
|
||||
log "$CONTAINER" "WARNING" "$CONTAINER state is restarting."
|
||||
|
|
|
@ -40,6 +40,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -91,6 +92,7 @@ check_required;
|
|||
|
||||
# DO NOT TOUCH BELOW
|
||||
currentDir=$(pwd)
|
||||
echo "Current directory is '${currentDir}'"
|
||||
cd "${DOCKER_COMPOSE_UPDATE_BASEDIR}";
|
||||
|
||||
for dir in *; do
|
||||
|
@ -131,6 +133,7 @@ for dir in *; do
|
|||
set +e;
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
res=$(eval "${updateCommand}")
|
||||
|
||||
if [[ "${DOCKER_COMPOSE_UPDATE_FAIL_ON_UPDATE_ERROR}" == "false" ]]; then
|
||||
|
|
|
@ -38,6 +38,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -124,7 +125,7 @@ if [ "${DYNV6_IPV6_ENABLED}" = "true" ]; then
|
|||
touch "${ipv6AddressLocalFile}";
|
||||
fi
|
||||
|
||||
if grep --color=never -Fxq ${ipv6Address} "${ipv6AddressLocalFile}"; then
|
||||
if grep --color=never -Fxq "${ipv6Address}" "${ipv6AddressLocalFile}"; then
|
||||
echo "IPv6 is still ${ipv6Address}";
|
||||
else
|
||||
echo "IPv6 changed"
|
||||
|
|
|
@ -41,6 +41,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -71,6 +72,7 @@ source_config "$1" "$HOME/.memory_usage_alert.conf" "/etc/memory_usage_alert.con
|
|||
# DO NOT TOUCH BELOW
|
||||
total=$(free -mt | grep Total | awk '{print $2}')
|
||||
used=$(free -mt | grep Total | awk '{print $3}')
|
||||
# shellcheck disable=SC2004
|
||||
free=$(($total-$used))
|
||||
|
||||
if [[ "$free" -le $MEMORY_USAGE_ALERT_THRESHOLD ]]; then
|
||||
|
|
|
@ -38,6 +38,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -66,11 +67,11 @@ source_config "$1" "$HOME/.smartctl_tests_long.conf" "/etc/smartctl_tests_long.c
|
|||
|
||||
echo "Starting long tests for ...";
|
||||
|
||||
for d in ${SMARTCTL_TESTS_LONG_DEVICES[@]}; do
|
||||
DEVICE="/dev/"$d;
|
||||
echo $DEVICE;
|
||||
smartctl -t long $DEVICE;
|
||||
mailx -s "[smartd $HOSTNAME] queued long test" $SMARTCTL_TESTS_LONG_MAIL_ADDRESS << EOF
|
||||
for d in "${SMARTCTL_TESTS_LONG_DEVICES[@]}"; do
|
||||
DEVICE="/dev/$d";
|
||||
echo "$DEVICE";
|
||||
smartctl -t long "$DEVICE";
|
||||
mailx -s "[smartd $HOSTNAME] queued long test" "$SMARTCTL_TESTS_LONG_MAIL_ADDRESS" << EOF
|
||||
Queued a smartd long test for $DEVICE.
|
||||
EOF
|
||||
done
|
||||
|
|
|
@ -48,6 +48,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
set +a;
|
||||
}
|
||||
|
@ -105,10 +106,12 @@ function checkService() {
|
|||
local RESULT=0;
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
# shellcheck disable=SC2091
|
||||
if ! $($USER_COMMAND); then
|
||||
RESULT=1;
|
||||
fi
|
||||
else
|
||||
# shellcheck disable=SC2091
|
||||
if ! $($ROOT_COMMAND) && ! $($USER_COMMAND); then
|
||||
RESULT=1;
|
||||
fi
|
||||
|
@ -119,7 +122,7 @@ function checkService() {
|
|||
echo "-> $SUBJECT: $MESSAGE";
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ apply_config() {
|
|||
fi
|
||||
|
||||
set -a;
|
||||
# shellcheck disable=SC1090
|
||||
source "$config";
|
||||
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"
|
||||
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";
|
Loading…
Reference in a new issue