Add noexec /tmp detection — fall back to /usr/local/src for staging
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:
+21
-9
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user