-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote
executable file
·32 lines (24 loc) · 892 Bytes
/
remote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
JSON_FILE=$REMOTE_SSH_CONFIG_PATH
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
if ! [ -f "$JSON_FILE" ]; then
echo "Error: File '$JSON_FILE' does not exist." >&2
exit 1
fi
DATA=$(cat $JSON_FILE)
export SSH_SERVER=$(echo $DATA | jq -r '.server')
export SSH_PORT=$(echo $DATA | jq -r '.port')
export SSH_USERNAME=$(echo $DATA | jq -r '.username')
export SSH_KEY_PATH=$(echo $DATA | jq -r '.keyPath')
export SSH_PORT_FORWARD=$(echo $DATA | jq -r '.portForward')
SSH_PORT_FORWARD=$1
IFS=',' read -ra PORT_ARRAY <<< "$SSH_PORT_FORWARD"
PORT_FORWARDING=""
for PORT in "${PORT_ARRAY[@]}"; do
PORT_MAPPING="$PORT:localhost:$PORT"
PORT_FORWARDING+=" -L $PORT_MAPPING"
done
ssh -o TCPKeepAlive=yes -o ServerAliveCountMax=20 -o ServerAliveInterval=15 -q $PORT_FORWARDING -l $SSH_USERNAME -p $SSH_PORT -i $SSH_KEY_PATH $SSH_SERVER