70 lines
1.5 KiB
Bash
Executable file
70 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
if ! tmux -V 2>/dev/null >/dev/null; then
|
|
echo "tmux not installed!"
|
|
exit 1
|
|
fi
|
|
if ! lua -v 2>/dev/null >/dev/null; then
|
|
echo "lua not installed!"
|
|
exit 1
|
|
fi
|
|
if ! nc -h 2>/dev/null >/dev/null; then
|
|
echo "nc not installed!"
|
|
exit 1
|
|
fi
|
|
RANDID=$(cat /dev/urandom | head -c 4 | xxd -p)
|
|
TMPDIR=/tmp/tstream_client_$RANDID
|
|
mkdir $TMPDIR
|
|
mkfifo $TMPDIR/datout
|
|
mkfifo $TMPDIR/nc_in
|
|
mkfifo $TMPDIR/nc_out
|
|
mkfifo $TMPDIR/arg_width
|
|
mkfifo $TMPDIR/arg_height
|
|
cat >$TMPDIR/ncread <<EOF
|
|
#!/usr/bin/env lua
|
|
local nc_out=io.open("$TMPDIR/nc_out")
|
|
local nc_in=io.open("$TMPDIR/nc_in","w")
|
|
local function wrfile(name,str)
|
|
local file=io.open("$TMPDIR/"..name,"w")
|
|
file:write(tostring(str))
|
|
file:close()
|
|
end
|
|
while true do
|
|
local line=nc_out:read()
|
|
if not line then
|
|
wrfile("arg_width","40")
|
|
wrfile("arg_height","10")
|
|
wrfile("datout","error occured\n")
|
|
error("what!")
|
|
end
|
|
if line:match("SIZE .+") then
|
|
local w,h=line:match("SIZE (.-) (.+)")
|
|
w,h=tonumber(w),tonumber(h)
|
|
wrfile("arg_width",w)
|
|
wrfile("arg_height",h)
|
|
break
|
|
end
|
|
end
|
|
nc_in:write("\n")
|
|
nc_in:flush()
|
|
local datout=io.open("$TMPDIR/datout","w")
|
|
while true do
|
|
datout:write(nc_out:read(1))
|
|
datout:flush()
|
|
end
|
|
EOF
|
|
chmod +x $TMPDIR/ncread
|
|
|
|
$TMPDIR/ncread &
|
|
{ cat $TMPDIR/nc_in | nc $@ | tee $TMPDIR/nc_out > /dev/null; } &
|
|
echo run
|
|
WIDTH=$(head -n 1 $TMPDIR/arg_width)
|
|
echo width $WIDTH
|
|
HEIGHT=$(head -n 1 $TMPDIR/arg_height)
|
|
echo height $HEIGHT
|
|
tmux new "tmux resize-window -x $WIDTH -y $HEIGHT;tmux set status off; cat $TMPDIR/datout"
|
|
jobs
|
|
kill %1
|
|
kill %2
|
|
rm -rf $TMPDIR
|
|
wait
|