diff --git a/tstream b/tstream index 69d3005..c9f5cd9 100755 --- a/tstream +++ b/tstream @@ -1,7 +1,7 @@ #!/bin/sh # Kimapr's streaming setup # how to use: -# install ncat, lua (tested with 5.4.3), and script +# install tmux, ncat, lua (tested with 5.4.3), and script # mkdir ~/stream # make a text file ~/stream/welcome, it will be displayed on stream startup. # make a text file ~/stream/the_end, it will be displayed on stream end. @@ -10,6 +10,25 @@ # end the stream by exitting from the shell in the stream window # you can also replay past streams using `scriptreplay -O live -T live-timing` in ~/stream/hist/*/ +echo "checking dependencies..." +if ! tmux -V; then + echo "tmux not installed!" + exit 1 +fi +if ! ncat --version; then + echo "ncat not installed!" + exit 1 +fi +if ! lua -v; then + echo "lua not installed!" + exit 1 +fi +if ! script --version; then + echo "script not installed!" + exit 1 +fi +echo "all tests pass!" + echo "usage: tstream [max bandwidth in KiB/s (per-client)]" port=$1 width=$2 @@ -18,15 +37,20 @@ bandwidth=$4 if [ "x$bandwidth" = "x" ]; then bandwidth=32 fi -randid=`head -c 16 /dev/urandom | xxd -p` +unset TMUX +randid=`head -c 4 /dev/urandom | xxd -p` name=`date -u +%Y-%m-%d_%H-%M-%S_UTC` -tmux new-session -d -s wstream_$randid "clear;cat ~/stream/welcome;$SHELL" -tmux resize-window -t wstream_$randid -x $width -y $(($height - 1)) +tmux new-session -d -s wstream_$randid "tmux set status-left-length 100;clear;cat ~/stream/welcome;$SHELL" +tmux resize-window -t wstream_$randid -x $(($width)) -y $(($height - 1)) tmux set-option -t wstream_$randid status-right "? viewers" cat >/tmp/tstream-helper_$randid </tmp/tstream-cat_$randid < /tmp/tstream-count_$randid sh -c "\$vcrefresh" /tmp/tstream-smarttail_$randid echo \$((\$(cat /tmp/tstream-count_$randid) - 1)) > /tmp/tstream-count_$randid +sleep 1 sh -c "\$vcrefresh" EOF chmod +x /tmp/tstream-cat_$randid @@ -163,6 +197,7 @@ chmod +x /tmp/tstream-refresh_$randid touch /tmp/tstream-seektimes_$randid { while true; do + tmux set -t wstream_$randid status-left "`date +%H:%M` " sleep 5 echo "$(lua -e "local file=io.open(\"$HOME/stream/hist/$name/live\")print(file:seek(\"end\")..\" \"..os.time())file:close()")" >>/tmp/tstream-seektimes_$randid /tmp/tstream-refresh_$randid @@ -175,7 +210,7 @@ tmux kill-session -t wstream_$randid tmux kill-session -t stream_$randid touch /tmp/tstream-death_$randid echo PLEASE WAIT... -sleep 2; +sleep 1; rm /tmp/tstream-death_$randid rm /tmp/tstream-helper_$randid rm /tmp/tstream-refresh_$randid diff --git a/tstream-client b/tstream-client new file mode 100755 index 0000000..4b14cbf --- /dev/null +++ b/tstream-client @@ -0,0 +1,69 @@ +#!/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 < /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