summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2010-10-03 21:34:08 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2010-10-03 21:34:08 +0000
commitad9296cca4041096eb02a619949eb0dfccd390e8 (patch)
treeff8713dca919a98fe0c1c1e90a97dc2c79ee1df9
parente07a9ee0fbb5b965edc0f3f1e01b213197a602a7 (diff)
Allow overriding setting from command-line
Add command-line options to override various settings from the tarball as well as the base directory. Overriding the tunnel port may confuse the server and is thus not allowed. git-svn-id: svn+ssh://xorcom/home/svn/debs/components/rapid-tunneling@8401 283159da-0705-0410-b60c-f2062b4bb6ad
-rwxr-xr-xrapid-tunneling48
1 files changed, 42 insertions, 6 deletions
diff --git a/rapid-tunneling b/rapid-tunneling
index 19402ca..49c5656 100755
--- a/rapid-tunneling
+++ b/rapid-tunneling
@@ -2,22 +2,58 @@
set -e
+base_dir="$HOME/.rapid-tunneling"
+
+usage() {
+ me=`basename $0`
+ echo >&2 "$me: Initiate a Rapid-Tunneling tunnel."
+ echo >&2 "Usage:"
+ echo >&2 " $me [options] remote-access-NAME.tar.gz"
+ echo >&2 ""
+ echo >&2 "Options:"
+ echo >&2 " -b DIR Override Base Directory (Default: $base_dir)"
+ echo >&2 " -h HOST Connect to HOST rather the host from the tarball"
+ echo >&2 " -p PORT Connect to PORT rather the host from the tarball"
+ echo >&2 " -u USER Connect to USER rather the host from the tarball"
+ echo >&2 ""
+}
+
if [ -z "$1" ]; then
- echo "Usage: $0 <remote-access-file-name>" 1>&2
+ usage
exit 1
fi
if [ -r /etc/rapid-tunneling/client ]; then . /etc/rapid-tunneling/client; fi
-base_dir="$HOME/.rapid-tunneling"
+opt_host=''
+opt_port=''
+opt_tunnelport='' # For completeness
+opt_user=''
+
+while getopts b:h:p:u: opt; do
+ case "$opt" in
+ b) base_dir="$OPTARG";;
+ h) opt_host="$OPTARG";;
+ p) opt_port="$OPTARG";;
+ u) opt_user="$OPTARG";;
+ \?) usage; exit 1;;
+ esac
+done
+
+shift $((OPTIND - 1))
+
tmpdir=`mktemp -d rapid-tunneling.XXXXXX`
mkdir $tmpdir/recv $tmpdir/send
tar xzf "$1" -C $tmpdir/recv
-user=`cat $tmpdir/recv/user`
-host=`cat $tmpdir/recv/host`
-port=`cat $tmpdir/recv/port`
-tunnelport=`cat $tmpdir/recv/tunnelport`
+for arg in host port user tunnelport; do
+ opt_arg=opt_$arg
+ if [ "${!opt_arg}" ]; then
+ eval $arg="${!opt_arg}"
+ else
+ eval $arg=`cat $tmpdir/recv/$arg`
+ fi
+done
ssh-keygen -q -t rsa -C rapid-tunneling -N "" -f $tmpdir/send/key # public will be in key.pub
cp $tmpdir/recv/key $tmpdir/send/origkey