Skip to content

Commit 80d87e5

Browse files
committed
Allow configuration of port numbers
1 parent d85d982 commit 80d87e5

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.default.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHISEL_LOCAL_PORT=${CHISEL_LOCAL_PORT:-5022}
2+
CHISEL_REMOTE_PORT=${CHISEL_REMOTE_PORT:-2022}

push.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
set -e # exit on error
44

55
cd `dirname $0`
6+
source .default.sh
67

78
appname="cf-ssh-chisel-$USER"
89

910
# Generate a key to identify the server (if one doesn't already exist)
1011
# TODO: put all generated files (this and id_rsa.pub) into a single directory
1112
if [ ! -r ssh_host_rsa_key ]; then
1213
ssh-keygen -t rsa -f ssh_host_rsa_key -N '' -C "chisel-ssh identity for $appname"
13-
echo '[localhost]:5022' `cat ssh_host_rsa_key.pub` >> ~/.ssh/known_hosts
14+
echo '[localhost]:$CHISEL_LOCAL_PORT' `cat ssh_host_rsa_key.pub` >> ~/.ssh/known_hosts
1415
fi
1516

1617
if [ ! -r id_rsa.pub ]; then
@@ -27,7 +28,7 @@ have one.
2728
Host chisel
2829
ForwardAgent yes
2930
HostName localhost
30-
Port 5022
31+
Port $CHISEL_LOCAL_PORT
3132
User vcap
3233
Compression yes
3334
_EOF_

tunnel

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e # exit on error
55
cd `dirname $0`
66

77
appname="cf-ssh-chisel-$USER"
8+
echo "Starting $appname forwarding local port ${CHISEL_LOCAL_PORT:=5022} to remote port ${CHISEL_REMOTE_PORT:=2022}"
89

910
echo "Checking if $appname is running"
1011
cf app $appname > /dev/null # Make sure app is there
@@ -22,18 +23,20 @@ url=`cf app $appname | egrep 'routes|urls' | awk '{print $2}'`
2223
echo "$url" | grep "$appname" | grep -q predix.io || { echo "URL doesn't look sane: $url"; exit 2; }
2324

2425
# If there's an existing client running, kill it
25-
client_pids=`ps auxww | grep ./chisel | grep 5022:2022 | grep -v grep | awk '{print $2}'`
26+
client_pids=`ps auxww | grep ./chisel | grep ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT} | grep -v grep | awk '{print $2}'`
2627
if [ -n "$client_pids" ]; then
2728
kill $client_pids
2829
fi
2930

3031
echo "Starting client, connecting to $url"
31-
./chisel client --keepalive 10s https://$url 5022:2022 > /dev/null &
32+
cmd="./chisel client --keepalive 10s https://$url ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT}"
33+
echo "Running in background: $cmd"
34+
$cmd > /dev/null &
3235

3336
cat <<_EOF_
3437
You can now connect via
3538
36-
ssh vcap@localhost -p 5022
39+
ssh vcap@localhost -p ${CHISEL_LOCAL_PORT}
3740
3841
or **IF** you added an entry to ~/.ssh/config:
3942

0 commit comments

Comments
 (0)