From d0d37bac24d5ba9402897d3df93979bea39ede11 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Thu, 27 Jun 2024 23:11:49 +0330 Subject: [PATCH] Check port is in use --- install.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 92f18f3..a325eb9 100644 --- a/install.sh +++ b/install.sh @@ -38,8 +38,15 @@ echo -e "\n" # Step 7: Ask for the port number and validate input while true; do read -p "Enter the port number you want to use (1-65535): " port - if [[ $port =~ ^[0-9]+$ ]] && [ "$port" -ge 1 ] && [ "$port" -le 65535 ]; then - break + if [[ $port =~ ^[0-9]+$ ]] && (( port >= 1 && port <= 65535 )); then + # Check if the port is in use + if ss -tuln | grep -q ":$port\b"; then + clear + echo -e "\e[91mPort $port is already in use. Please choose another port.\e[0m" + echo + else + break + fi else echo "Invalid port number. Please enter a number between 1 and 65535." fi