Add noexec /tmp detection — fall back to /usr/local/src for staging
Lint Scripts / powershell-lint (push) Failing after 13m25s
Lint Scripts / shellcheck (push) Failing after 17m44s

Scripts auto-detect noexec /tmp by attempting to execute a test script.
If /tmp is noexec, staging directory falls back to /usr/local/src.
Supports mixed fleets with both noexec and standard /tmp mounts.

Updated: deploy-exporter (1.1), install-node-exporter (1.2),
install-prometheus-stack (3.2), update-prometheus-stack (1.02),
install-snort (1.02), install-ntfy-server (1.1), install-bot-monitor (1.2)
This commit is contained in:
2026-05-26 16:16:33 +02:00
parent 166e07085a
commit d0d51be49a
7 changed files with 127 additions and 42 deletions
+21 -9
View File
@@ -1,7 +1,7 @@
#!/bin/bash
################################################################################
# Script Name: install-bot-monitor.sh
# Version: 1.1
# Version: 1.2
# Description: Install the bot-monitor script, known agents whitelist, and
# daily cron job. Detects unknown user agents in web server logs
# and sends alerts via ntfy and/or Prometheus textfile metrics.
@@ -375,7 +375,19 @@ step "Installing bot-monitor script"
SCRIPT_FILE="/usr/local/bin/bot-monitor.sh"
cat > /tmp/bot-monitor.sh.tmp << 'SCRIPTEOF'
# Detect noexec /tmp — fall back to /usr/local/src
STAGE_DIR="/tmp"
_exec_test=$(mktemp /tmp/.exec_test.XXXXXX 2>/dev/null)
if [[ -n "$_exec_test" ]]; then
printf '#!/bin/sh\nexit 0\n' > "$_exec_test"
chmod +x "$_exec_test"
"$_exec_test" 2>/dev/null || STAGE_DIR="/usr/local/src"
rm -f "$_exec_test"
else
STAGE_DIR="/usr/local/src"
fi
cat > ${STAGE_DIR}/bot-monitor.sh.tmp << 'SCRIPTEOF'
#!/bin/bash
# /usr/local/bin/bot-monitor.sh
# Detects unknown user agents in yesterday's web server logs.
@@ -478,12 +490,12 @@ find "$STATE_DIR" -name "unknown-*.txt" -mtime +30 -delete 2>/dev/null || true
SCRIPTEOF
# Replace placeholders with actual values
sed -i "s|__LOG_DIR__|${LOG_DIR}|g" /tmp/bot-monitor.sh.tmp
sed -i "s|__LOG_PATTERN__|${LOG_PATTERN}|g" /tmp/bot-monitor.sh.tmp
sed -i "s|__NTFY_URL__|${NTFY_URL}|g" /tmp/bot-monitor.sh.tmp
sed -i "s|__TEXTFILE_DIR__|${TEXTFILE_DIR}|g" /tmp/bot-monitor.sh.tmp
sed -i "s|__TEXTFILE_ENABLED__|${TEXTFILE_ENABLED}|g" /tmp/bot-monitor.sh.tmp
sed -i "s|__MIN_REQUESTS__|${MIN_REQUESTS}|g" /tmp/bot-monitor.sh.tmp
sed -i "s|__LOG_DIR__|${LOG_DIR}|g" ${STAGE_DIR}/bot-monitor.sh.tmp
sed -i "s|__LOG_PATTERN__|${LOG_PATTERN}|g" ${STAGE_DIR}/bot-monitor.sh.tmp
sed -i "s|__NTFY_URL__|${NTFY_URL}|g" ${STAGE_DIR}/bot-monitor.sh.tmp
sed -i "s|__TEXTFILE_DIR__|${TEXTFILE_DIR}|g" ${STAGE_DIR}/bot-monitor.sh.tmp
sed -i "s|__TEXTFILE_ENABLED__|${TEXTFILE_ENABLED}|g" ${STAGE_DIR}/bot-monitor.sh.tmp
sed -i "s|__MIN_REQUESTS__|${MIN_REQUESTS}|g" ${STAGE_DIR}/bot-monitor.sh.tmp
if [[ "$DRY_RUN" == "true" ]]; then
echo " Would install: ${SCRIPT_FILE}"
@@ -497,7 +509,7 @@ else
cp "$SCRIPT_FILE" "${SCRIPT_FILE}.bak.$(date +%s)"
warn "Existing script backed up"
fi
mv /tmp/bot-monitor.sh.tmp "$SCRIPT_FILE"
mv ${STAGE_DIR}/bot-monitor.sh.tmp "$SCRIPT_FILE"
chmod +x "$SCRIPT_FILE"
info "Installed: ${SCRIPT_FILE}"
fi