linux fixes

This commit is contained in:
first 2025-07-07 19:48:20 +00:00
parent 999657d3e5
commit 697b84b9b5

View file

@ -5,13 +5,6 @@
# This is a self-contained script for installing and uninstalling the SYNterloper # This is a self-contained script for installing and uninstalling the SYNterloper
# connection logging service. # connection logging service.
# #
# Usage for installation:
# sudo ./synterloper.sh
# sudo ./synterloper.sh install
#
# Usage for uninstallation:
# sudo /usr/local/sbin/synterloper uninstall
#
# --- Configuration --- # --- Configuration ---
LOG_DIR="/var/log/synterloper" LOG_DIR="/var/log/synterloper"
@ -54,6 +47,15 @@ install_synterloper() {
# Create the system service # Create the system service
if [ "${OS_TYPE}" = "Linux" ]; then if [ "${OS_TYPE}" = "Linux" ]; then
# Dynamically find command paths before creating the service.
echo "Detecting required command paths..."
if ! TCPDUMP_CMD_PATH=$(command -v tcpdump); then echo "Error: tcpdump not found in PATH."; exit 1; fi
if ! IP_CMD_PATH=$(command -v ip); then echo "Error: ip not found in PATH."; exit 1; fi
if ! GREP_CMD_PATH=$(command -v grep); then echo "Error: grep not found in PATH."; exit 1; fi
echo " - tcpdump found at: ${TCPDUMP_CMD_PATH}"
echo " - ip found at: ${IP_CMD_PATH}"
echo " - grep found at: ${GREP_CMD_PATH}"
echo "Creating systemd service: synterloper.service" echo "Creating systemd service: synterloper.service"
cat > /etc/systemd/system/synterloper.service <<EOF cat > /etc/systemd/system/synterloper.service <<EOF
[Unit] [Unit]
@ -61,10 +63,7 @@ Description=SYNterloper - TCP Port Connection Logger
After=network.target After=network.target
[Service] [Service]
Type=simple Type=simple
# ========================================================================================= ExecStart=/bin/sh -c 'exec ${TCPDUMP_CMD_PATH} -i \$(${IP_CMD_PATH} -4 route get 1.1.1.1 | ${GREP_CMD_PATH} -oP "dev \\K\\S+") -s ${SNAP_LEN} -w ${LOG_DIR}/capture-%%Y-%%m-%%d_%%H-%%M.pcap -G ${ROTATE_SECONDS} "tcp port ${CAPTURE_PORT}"'
# THE FIX IS HERE: All '%' are escaped as '%%' for systemd
# =========================================================================================
ExecStart=/bin/sh -c 'exec /usr/sbin/tcpdump -i \$(ip -4 route get 1.1.1.1 | grep -oP "dev \\K\\S+") -s ${SNAP_LEN} -w ${LOG_DIR}/capture-%%Y-%%m-%%d_%%H-%%M.pcap -G ${ROTATE_SECONDS} "tcp port ${CAPTURE_PORT}"'
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec=5
[Install] [Install]
@ -75,7 +74,6 @@ EOF
systemctl enable synterloper.service systemctl enable synterloper.service
systemctl start synterloper.service systemctl start synterloper.service
elif [ "${OS_TYPE}" = "FreeBSD" ]; then elif [ "${OS_TYPE}" = "FreeBSD" ]; then
# FreeBSD's rc.d system does not have this issue, so no change is needed here.
echo "Creating rc.d script: /usr/local/etc/rc.d/synterloper" echo "Creating rc.d script: /usr/local/etc/rc.d/synterloper"
cat > /usr/local/etc/rc.d/synterloper <<'EOF' cat > /usr/local/etc/rc.d/synterloper <<'EOF'
#!/bin/sh #!/bin/sh