-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnetcatLoanerPseudoServer.sh
More file actions
executable file
·82 lines (72 loc) · 2.79 KB
/
netcatLoanerPseudoServer.sh
File metadata and controls
executable file
·82 lines (72 loc) · 2.79 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# DEPRECATED - I BASICALLY NEVER USE THIS THING. keeping it around as it was interesting
# and led to a better solution, and the first time I really used netcat.
# NOTE - this script runs in a loop - kick it off in its own terminal and then
# CTRL-C it to stop it (it will perform some cleanup when cancelled this way)
# INSTRUCTIONS FOR DOING SOMETHING USEFUL WITH THIS SCRIPT...this takes about 10 minutes to do.
#
# 1. ON MY LOANER, INSTALL BREW (this will likely also install the Xcode developer tools)
# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# brew doctor
#
# 2. INSTALL NODE
# brew install node
#
# (for 3-4, see http://chromix.smblott.org/#_installation)
#
# 3. INSTALL CHROMI EXTENSION IN CHROME BROWSER
# https://chrome.google.com/webstore/detail/chromi/eeaebnaemaijhbdpnmfbdboenoomadbo
#
# 4. INSTALL CHROMIX SERVER
# sudo npm install -g chromix
#
# now you can do something like have Vim in my office tmux session fire off a command that goes
# over netcat to my loaner laptop and reloads the webpage. Neat!
#
# I have a nice function defined in functions.vim so in my vimrc I can just setup:
# map \ :call SendNetcatCommand("<LOANER_MACHINE_IP>", <LOANER_MACHINE_PORT>, "something")<enter>
#
# on a per-loaner basis I can set what commands I care about, see "random" below as an example
# This script creates a fifo (named pipe) and then runs netcat on port 4099, redirecting output
# to this named pipe. Then it reads commands coming over netcat and does something with them.
#
# if one were completely trusting, could just pass these along to bash. In our case, we'll listen
# for some very particular things and do some very particular things in response - we are NOT
# going to allow arbitrary stuff to be executed over netcat!
#
# this is hopefully not too dangerous...
# PART ONE - create the named pipe
namedPipe="/tmp/netcat4099"
rm ${namedPipe}
mkfifo ${namedPipe}
# PART TWO - kick off my listeners
nc -k -l 4099 > ${namedPipe} &
netcatPid=$!
chromix-server &
chromixPid=$!
# WATCH FOR CTRL-C - this is the only way to kill it
trap ctrl_c INT
function ctrl_c() {
echo "user cancelled; kill ${netcatPid} and ${chromixPid}, and rm ${namedPipe}..."
kill ${netcatPid}
kill ${chromixPid}
rm ${namedPipe}
exit
}
echo "started netcat with pid ${netcatPid} and chromix with pid ${chromixPid}"
# PART THREE - handle commands coming in over netcat
while true
do
if read line <$namedPipe; then
echo "READ LINE FROM NETCAT: [${line}]"
if [[ "$line" == 'random' ]]; then
echo "command 'random' means reload random.org..."
chromix with 'random.org' reload
elif [[ "$line" == 'news2015' ]]; then
echo "command 'news2015' means reload news2015"
chromix with 'news2015' reload
else
echo "(unsupported command)"
fi
fi
done