summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2013-08-09 20:30:58 +0200
committerFlorian Bruhin <git@the-compiler.org>2013-08-09 20:30:58 +0200
commit7cdfa26585b67260db424c84389714a6a2216d12 (patch)
tree9fe66c37ea361bf45cc6f5b218940109ec9b318e
parent41e9612bd2c2473ee1a6d4b1c1be6abc46224301 (diff)
downloadsshtunnel-7cdfa26585b67260db424c84389714a6a2216d12.tar.gz
sshtunnel-7cdfa26585b67260db424c84389714a6a2216d12.zip
Add print command
-rwxr-xr-xsshtunnel28
1 files changed, 23 insertions, 5 deletions
diff --git a/sshtunnel b/sshtunnel
index 98632aa..09ab221 100755
--- a/sshtunnel
+++ b/sshtunnel
@@ -85,6 +85,7 @@ Usage: $0 [-c <config>] <command> [<name>]
Commands:
start <name>: Starts the tunnel named <name>
stop <name>: Stops the tunnel named <name>
+ print <name>: Validate config and print command that would be run
start-all: Start all configured tunnels
stop-all: Stop running tunnels
list: List running tunnels
@@ -122,7 +123,7 @@ parseargs() {
case "$g_cmd" in
start-all|stop-all|list) # Valid commands without arg
;;
- start|stop|systemd-start) # Valid commands with argument
+ start|stop|systemd-start|print) # Valid commands with argument
if (( $# < 1 )); then
usage
die "Command $g_cmd needs an argument!"
@@ -187,7 +188,12 @@ cmd_stop_all() {
}
# Actually start a tunnel, gets called from systemd
-cmd_systemd_start() {
+# Positional parameters:
+# run Execute command
+# print Print commandline
+# And any combination thereof. Without any parameter, the profile gets
+# validated only.
+cmd_profile() {
local ssh
local ssh_opts_global
local monitoring
@@ -201,6 +207,16 @@ cmd_systemd_start() {
local ssh_opts_local
local name
local autossh_env
+ local do_print
+ local do_exec
+
+ while :; do
+ case "$1" in
+ print) do_print=1; shift ;;
+ run) do_exec=1; shift ;;
+ *) break ;;
+ esac
+ done
name="$g_arg"
@@ -208,7 +224,7 @@ cmd_systemd_start() {
die "Tunnel $name does not exist!"
fi
- tunnel_cmd=()
+ tunnel_cmd=('exec' '--')
ssh=$(conf_key ssh ssh auto)
if [[ "$ssh" == auto ]]; then
@@ -259,7 +275,8 @@ cmd_systemd_start() {
host=$(conf_key "tunnel.$name" host) || die "host not set"
tunnel_cmd+=("$user@$host")
- echo "${tunnel_cmd[@]}"
+ [[ "$do_print" ]] && echo "${tunnel_cmd[@]}"
+ [[ "$do_exec" ]] && "${tunnel_cmd[@]}"
}
parseargs "$@"
@@ -271,5 +288,6 @@ case "$g_cmd" in
start-all) cmd_start_all ;;
stop-all) cmd_stop_all ;;
list) cmd_list ;;
- systemd-start) cmd_systemd_start ;;
+ print) cmd_profile print ;;
+ systemd-start) cmd_profile run ;;
esac