56 lines
987 B
Bash
56 lines
987 B
Bash
#!/bin/sh
|
|
|
|
set -x
|
|
|
|
createsrv () {
|
|
# $1 - port
|
|
# $2 - write location
|
|
# $3 - read location
|
|
[ -p "$2" ] || mkfifo "$2"
|
|
[ -e "$3" ] || touch "$3"
|
|
|
|
nc -l "$1" <"$2" >>"$3" & exec 3>"$2"
|
|
}
|
|
die () {
|
|
# $1 - error message
|
|
printf "%s\n" $1
|
|
exit 1
|
|
}
|
|
checkuid () {
|
|
[ $(whoami) = "root" ] && \
|
|
die "You must execute shellgopher as root."
|
|
}
|
|
writefile () {
|
|
# $1 - file
|
|
foo cat "$1" >&3
|
|
}
|
|
ioblock () {
|
|
# $1 - io to block
|
|
while [ "$(wc -l $1 | awk -F' ' '{print $1}')" -eq 0 ]; do :; done
|
|
}
|
|
ioflush () {
|
|
# $1 - io to flush
|
|
rm "$1"
|
|
touch "$1"
|
|
}
|
|
mktmp () {
|
|
t=$(mktemp)
|
|
rm "$t"
|
|
mkdir "$t"
|
|
printf "%s\n" "$t"
|
|
}
|
|
tmplocation=$(mktmp)
|
|
writelocation="${tmplocation}/write"
|
|
readlocation="${tmplocation}/read"
|
|
|
|
checkuid
|
|
createsrv 70 "${writelocation}" "${readlocation}"
|
|
printf "server created\n"
|
|
while true; do
|
|
ioblock "${readlocation}"
|
|
printf "iHello there! This is a test\tfake\t\t0\r\n.\r\n" >&3
|
|
printf "file served\n"
|
|
ioflush "${readlocation}"
|
|
done
|
|
exit 1
|