38 lines
1.1 KiB
Shell
Executable file
38 lines
1.1 KiB
Shell
Executable file
#!/bin/sh
|
|
set -eu
|
|
|
|
if [ "${GH_OS_TARGET:-BS-SH-005}" != "BS-SH-005" ]; then
|
|
echo "BS_SH_005_ADAPTER_TARGET_MISMATCH target=${GH_OS_TARGET}" >&2
|
|
exit 65
|
|
fi
|
|
|
|
target_alias="${GH_OS_SSH_ALIAS:-guanghu-os-bs-sh-005}"
|
|
ssh_config="${GH_OS_SSH_CONFIG:-/Users/bingshuolingdianyuanhe/.ssh/guanghu-os-bs-sh-005.conf}"
|
|
control_socket="${GH_OS_TUNNEL_SOCKET:-/Users/bingshuolingdianyuanhe/.ssh/guanghu-os-bs-sh-005-tunnel.sock}"
|
|
command="${1:-status}"
|
|
|
|
case "$command" in
|
|
start)
|
|
if ssh -F "$ssh_config" -S "$control_socket" -O check "$target_alias" >/dev/null 2>&1; then
|
|
echo "GUANGHU_OS_TUNNEL_ALREADY_RUNNING"
|
|
exit 0
|
|
fi
|
|
exec ssh \
|
|
-F "$ssh_config" \
|
|
-M -S "$control_socket" -fN \
|
|
-o ExitOnForwardFailure=yes \
|
|
-L 18077:127.0.0.1:8077 \
|
|
-L 13080:127.0.0.1:3080 \
|
|
"$target_alias"
|
|
;;
|
|
status)
|
|
exec ssh -F "$ssh_config" -S "$control_socket" -O check "$target_alias"
|
|
;;
|
|
stop)
|
|
exec ssh -F "$ssh_config" -S "$control_socket" -O exit "$target_alias"
|
|
;;
|
|
*)
|
|
echo "usage: tunnel.sh start|status|stop" >&2
|
|
exit 2
|
|
;;
|
|
esac
|