aboutsummaryrefslogtreecommitdiff
path: root/bin/netcom
blob: 283f8ea34ee4fc866a49ce8ab5889f2b77f224cc (plain)
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
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

#
# netcom
#
# Combine socat and picocom to attach to a raw network socket. In many ways
# this is similar to telnet but makes no attempt to be clever w.r.t. local
# echo (and this is what you want if you want if you are connecting to a
# raw network socket).
#

# check arguments
if [ $# -ne 2 ]
then
	echo "USAGE: netcom <host> <port>" >&2
	exit 1
fi

# configuration
host="$1"
port="$2"
link="$HOME/.netcom/pty.$$"

# create a pty with a named soft-link, waitslave will defer connection to the
# network until the pty is opened (and also causes socat to exit when the pty
# is closed)
mkdir -p `dirname "$link"`
rm -f "$link"
socat "pty,link=$link,waitslave" "tcp:$host:$port" &

# wait for the pty to be ready
while [ ! -e "$link" ]
do
	usleep 1000
done

# connect to the pty, disabling locking so we don't need to run as root
# and enabling Zmodem file transfers.
picocom --nolock --send-cmd sz --receive-cmd rz --nolock "$link"

# clean up the soft-link and wait for socat to exit
rm -f "$link"
wait