txthole (907B)
1 #!/bin/sh 2 # simple pastebin server 3 # 4 # Sample usage (assuming ./txthole.sh is running): 5 # cat /my/file |nc host 2023 # put file 6 # echo "my text" |nc host 2023 # put text 7 # echo paste-code |nc host 2023 # get 8 9 pastes="/tmp/pastes" 10 fifo="/tmp/txthole.fifo" 11 port="2023" 12 pubhost="" 13 14 run() { 15 paste="$1" 16 label="$(basename "$paste" |cut -d. -f2)" 17 18 read s 19 p="$pastes/txthole.$s.paste" 20 if [ -f "$p" ]; then 21 cat "$p" 22 else 23 echo "$pubhost/$label" 24 fi 25 } 26 27 main() { 28 pubhost="$1" 29 30 if [ -z "$pubhost" ]; then 31 echo "Usage: $(basename "$0") <pubhost>" 32 exit 1 33 fi 34 35 mkdir -pm 0740 "$pastes" 36 rm -f "$fifo" 37 mkfifo "$fifo" 38 while : ; do 39 paste="$(mktemp -q "$pastes/txthole.XXXXX.paste")" 40 chmod g+r "$paste" # the webserver needs to read 41 cat "$fifo" |tee -a "$paste" | run "$paste" | nc -4Nl "$port" > "$fifo" 42 [ "$(wc -c "$paste" |cut -d' ' -f1)" -eq 0 ] && rm -f "$paste" 43 done 44 rm -f "$fifo" 45 } 46 47 main $@