Spaces:
Paused

userrein commited on
Commit
4e176c6
·
verified ·
1 Parent(s): 3935c13

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +36 -29
start.sh CHANGED
@@ -1,37 +1,44 @@
1
  #!/bin/bash
2
 
3
- # Start SSH server
4
  /usr/sbin/sshd
5
  echo "[*] SSH server jalan..."
6
 
7
- # Ambil username lokal
8
  USER_LOCAL=$(whoami)
9
  echo "[*] Username lokal: $USER_LOCAL"
10
 
11
- # Jalankan tunnel reverse SSH ke Pinggy tanpa binary
12
- # Port 22 lokal (SSH) akan diteruskan ke Pinggy
13
-
14
- (
15
- ssh -o StrictHostKeyChecking=no \
16
- -o UserKnownHostsFile=/dev/null \
17
- -o ServerAliveInterval=60 \
18
- -o ExitOnForwardFailure=yes \
19
- -p 443 \
20
- -R0:localhost:22 tcp@a.pinggy.io -N -T
21
-
22
- sleep 5
23
-
24
- )
25
-
26
- # Cek public domain & port dari Pinggy
27
- # Pinggy biasanya mengeluarkan baris seperti:
28
- # Access your server at tcp://xxxxx.pinggy.link:NNNN
29
- TAIL=$(tail -n 15 /root/.ssh/known_hosts 2>/dev/null)
30
-
31
- if grep -q "pinggy" <<< "$TAIL"; then
32
- echo "[*] Tunnel aktif — cek output log Pinggy untuk hostname & port"
33
- fi
34
-
35
- echo "[*] Anda bisa lihat logs container untuk hostname & port publik"
36
-
37
- /bin/bash
 
 
 
 
 
 
 
 
1
  #!/bin/bash
2
 
3
+ # === 1. Start SSH server ===
4
  /usr/sbin/sshd
5
  echo "[*] SSH server jalan..."
6
 
7
+ # === 2. Ambil username lokal ===
8
  USER_LOCAL=$(whoami)
9
  echo "[*] Username lokal: $USER_LOCAL"
10
 
11
+ # === 3. Jalankan Pinggy tunnel otomatis (loop reconnect) ===
12
+ LOG_FILE=/tmp/pinggy.log
13
+ rm -f $LOG_FILE
14
+
15
+ echo "[*] Menjalankan tunnel Pinggy, menunggu hostname & port publik..."
16
+ while true; do
17
+ # Jalankan tunnel reverse SSH ke Pinggy
18
+ ssh -o StrictHostKeyChecking=no \
19
+ -o UserKnownHostsFile=/dev/null \
20
+ -o ServerAliveInterval=60 \
21
+ -o ExitOnForwardFailure=yes \
22
+ -p 443 \
23
+ -R0:localhost:22 tcp@a.pinggy.io -N -T 2>&1 | tee -a $LOG_FILE &
24
+
25
+ # Tunggu beberapa detik agar tunnel aktif
26
+ sleep 5
27
+
28
+ # Ambil output terakhir dari log Pinggy yang mengandung hostname publik
29
+ LAST_LINE=$(tail -n 20 $LOG_FILE | grep 'tcp://')
30
+ if [[ -n "$LAST_LINE" ]]; then
31
+ HOST=$(echo "$LAST_LINE" | sed -E 's#.*tcp://([^:]+):([0-9]+).*#\1#')
32
+ PORT=$(echo "$LAST_LINE" | sed -E 's#.*tcp://([^:]+):([0-9]+).*#\2#')
33
+
34
+ echo "[*] Hostname publik: $HOST"
35
+ echo "[*] Port publik: $PORT"
36
+ echo "[*] SSH command terakhir siap copy-paste:"
37
+ echo "ssh $USER_LOCAL@$HOST -p $PORT"
38
+ else
39
+ echo "[!] Gagal ambil output Pinggy. Pastikan internet stabil."
40
+ fi
41
+
42
+ # Tunggu 60 detik sebelum reconnect jika tunnel putus
43
+ sleep 60
44
+ done