From a50a272919e56eb412422845d1f6d50065e5b36e Mon Sep 17 00:00:00 2001 From: sengedev <136069154+sengedev@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:27:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=861Panel=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=8F=B7=E5=8F=AF=E8=83=BD=E4=BC=9A=E8=A2=AB=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 175b6a1..1b07230 100644 --- a/install.sh +++ b/install.sh @@ -192,14 +192,33 @@ function Install_Compose(){ function Set_Port(){ DEFAULT_PORT=`expr $RANDOM % 55535 + 10000` - + if command -v lsof >/dev/null 2>&1; then + while lsof -i:$DEFAULT_PORT; do + DEFAULT_PORT=`expr $RANDOM % 55535 + 10000` + done + elif command -v netstat >/dev/null; then + while netstat -tlun | grep -q ":$DEFAULT_PORT"; do + DEFAULT_PORT=`expr $RANDOM % 55535 + 10000` + done + fi while true; do read -p "设置 1Panel 端口(默认为$DEFAULT_PORT):" PANEL_PORT if [[ "$PANEL_PORT" == "" ]];then PANEL_PORT=$DEFAULT_PORT fi - + if command -v lsof >/dev/null 2>&1; then + if lsof -i:$PANEL_PORT; then + echo "端口$PANEL_PORT被占用,请重新输入..." + continue + fi + elif command -v netstat >/dev/null; then + if netstat -tlun | grep -q ":$DEFAULT_PORT"; then + echo "端口$PANEL_PORT被占用,请重新输入..." + continue + fi + fi + if ! [[ "$PANEL_PORT" =~ ^[1-9][0-9]{0,4}$ && "$PANEL_PORT" -le 65535 ]]; then echo "错误:输入的端口号必须在 1 到 65535 之间" continue From e89e90757b2ebb3148ec2116cf1f278b59655ec1 Mon Sep 17 00:00:00 2001 From: sengedev <136069154+sengedev@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:37:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=BA=86=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=8F=B7=E6=9F=A5=E8=AF=A2=E7=9A=84=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=B7=BB=E5=8A=A0=E4=BA=86ss=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加了ss命令,降低了端口冲突导致1Panel无法正常访问的几率。 --- install.sh | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/install.sh b/install.sh index 1b07230..ee128c6 100644 --- a/install.sh +++ b/install.sh @@ -192,37 +192,35 @@ function Install_Compose(){ function Set_Port(){ DEFAULT_PORT=`expr $RANDOM % 55535 + 10000` - if command -v lsof >/dev/null 2>&1; then - while lsof -i:$DEFAULT_PORT; do - DEFAULT_PORT=`expr $RANDOM % 55535 + 10000` - done - elif command -v netstat >/dev/null; then - while netstat -tlun | grep -q ":$DEFAULT_PORT"; do - DEFAULT_PORT=`expr $RANDOM % 55535 + 10000` - done - fi + while true; do read -p "设置 1Panel 端口(默认为$DEFAULT_PORT):" PANEL_PORT if [[ "$PANEL_PORT" == "" ]];then PANEL_PORT=$DEFAULT_PORT fi - if command -v lsof >/dev/null 2>&1; then - if lsof -i:$PANEL_PORT; then + + if ! [[ "$PANEL_PORT" =~ ^[1-9][0-9]{0,4}$ && "$PANEL_PORT" -le 65535 ]]; then + echo "错误:输入的端口号必须在 1 到 65535 之间" + continue + fi + + if command -v lsof >/dev/null 2>&1; then + if lsof -i:$PANEL_PORT >/dev/null 2>&1; then echo "端口$PANEL_PORT被占用,请重新输入..." continue fi - elif command -v netstat >/dev/null; then - if netstat -tlun | grep -q ":$DEFAULT_PORT"; then + elif command -v ss >/dev/null 2>&1; then + if ss -tlun | grep -q ":$PANEL_PORT " >/dev/null 2>&1; then + echo "端口$PANEL_PORT被占用,请重新输入..." + continue + fi + elif command -v netstat >/dev/null 2>&1; then + if netstat -tlun | grep -q ":$PANEL_PORT " >/dev/null 2>&1; then echo "端口$PANEL_PORT被占用,请重新输入..." continue fi - fi - - if ! [[ "$PANEL_PORT" =~ ^[1-9][0-9]{0,4}$ && "$PANEL_PORT" -le 65535 ]]; then - echo "错误:输入的端口号必须在 1 到 65535 之间" - continue - fi + fi log "您设置的端口为:$PANEL_PORT" break