diff --git a/README.md b/README.md index b29f9e8..cad2114 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ sudo ./setup_dante.sh -a 203.0.113.5 -a 198.51.100.0/24 -p 1090 The script will: -1. Install the `dante-server` package via `apt` if it is not already installed. +1. Verify whether the `dante-server` package is already present and only install it when required. 2. Detect the default network interface used for outbound traffic. 3. Back up any existing `/etc/danted.conf` file with a timestamp suffix. 4. Write a new configuration that only allows the specified client networks and uses a passwordless SOCKS policy for those clients. 5. Enable and restart the `danted` systemd service. -After the script completes successfully, the Dante server will be listening on the requested port and only the IPs/CIDR blocks that remain after applying any `-a` and `-r` options will be permitted. +After the script completes successfully, the Dante server will be listening on the requested port and only the IPs/CIDR blocks that remain after applying any `-a` and `-r` options will be permitted. Re-running the script will preserve the existing allow-list entries and append any new IPs you provide with `-a`. diff --git a/setup_dante.sh b/setup_dante.sh index ee8cc90..1ee4001 100755 --- a/setup_dante.sh +++ b/setup_dante.sh @@ -189,6 +189,31 @@ restart_service() { systemctl restart danted } +is_package_installed() { + local package=$1 + + if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q "install ok installed"; then + return 0 + fi + + return 1 +} + +ensure_dante_installed() { + local package="dante-server" + + echo "[INFO] Checking for $package package..." + if is_package_installed "$package"; then + echo "[INFO] $package is already installed. Skipping installation." + return + fi + + echo "[INFO] Installing Dante server package..." + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y "$package" +} + main() { require_root @@ -233,6 +258,10 @@ main() { read_existing_allow_list "$config_path" + if [[ ${#ALLOW_LIST[@]} -gt 0 ]]; then + echo "[INFO] Detected existing allowed clients: ${ALLOW_LIST[*]}" + fi + if [[ ${#ALLOW_LIST[@]} -eq 0 && ${#ADD_LIST[@]} -eq 0 ]]; then echo "[ERROR] No existing allow-list entries found. Use -a to specify at least one client IP/CIDR." >&2 usage @@ -260,10 +289,7 @@ main() { exit 1 fi - echo "[INFO] Installing Dante server package..." - export DEBIAN_FRONTEND=noninteractive - apt-get update - apt-get install -y dante-server + ensure_dante_installed local iface iface=$(get_default_interface)