serve.bash
1 serve(){ 2 dir=${1:-`pwd`} 3 port=${2:-8080} 4 host=${3:-localhost} 5 tempconf=/tmp/lighttpd_${port}.conf 6 7 # Loop until we have a port unused by another lighttpd instance 8 while ls $tempconf &> /dev/null ; do 9 port=$(expr $port + 1 ) 10 tempconf=/tmp/lighttpd_${port}.conf 11 done 12 13 # Create the temporary config 14 echo "server.document-root = \"${dir}\" 15 server.port = $port 16 server.bind = \"$host\" 17 dir-listing.activate = \"enable\"" > $tempconf 18 echo "serving '$dir' on http://$host:$port" 19 20 lighttpd -Df $tempconf 21 22 # Cleanup, though a trap might be better 23 rm $tempconf 24 }