From d1436b81a89103598c96d5abb9e8bff83272c606 Mon Sep 17 00:00:00 2001
From: sspark <sspark@onioi.com>
Date: Sat, 17 Sep 2022 01:51:32 +0000
Subject: [PATCH] fix ssh tunnel issue

---
 gwinstall.sh |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/gwinstall.sh b/gwinstall.sh
index 88639eb..be858b7 100755
--- a/gwinstall.sh
+++ b/gwinstall.sh
@@ -1,20 +1,29 @@
 #!/bin/bash
 
 export FWD_PORT=10000
+export SSH_SERVER=root@onio.iptime.org
+
+install_ssh_key()
+{
+    sudo ssh-keygen
+    sudo ssh-copy-id -p 12222 $SSH_SERVER
+}
+
+test_tunnel()
+{
+    sudo /usr/bin/ssh -NT -o ServerAliveInterval=5 -o ExitOnForwardFailure=yes -gnN -R 127.0.0.1:$FWD_PORT:localhost:22 -p 12222 $SSH_SERVER
+}
 
 install_tunnel()
 {
-    sudo ssh-keygen
-    sudo ssh-copy-id -p 12222 root@onio.iptime.org
-
 echo "
 [Unit]
 Description=SSH Tunnel with target server
 After=network.target
 
 [Service]
-ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -R 127.0.0.1:$FWD_PORT:localhost:22 -p 12222 root@onio.iptime.org
-RestartSec=5
+ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=5 -o ExitOnForwardFailure=yes -gnN -R 127.0.0.1:$FWD_PORT:localhost:22 -p 12222 $SSH_SERVER
+RestartSec=10
 Restart=always
 
 [Install]
@@ -47,6 +56,15 @@
 }
 
 case "$1" in
+    copykey)
+        echo -e "ssh_key copying... server: $SSH_SERVER"
+        install_ssh_key
+        ;;
+    test)
+        echo -e "tunnel test... port: $2"
+        FWD_PORT=$2
+        test_tunnel
+        ;;        
     tunnel)
         echo -e "tunnel install... port: $2"
         FWD_PORT=$2
@@ -57,11 +75,11 @@
         install_packages
         ;;
     USBWiFi)
-        echo -e "USBWiFi install..."
+        echo -e "USBWiFi make install..."
         install_USBWiFi
         ;;
     *)
-        echo -e "Usage:\n$0 {tunnel 10000|packages|USBWiFi}"
+        echo -e "Usage:\n$0 {copykey|test 10000|tunnel 10000|packages|USBWiFi}"
         exit 1
 esac
 

--
Gitblit v1.9.3