Snippets
Created by
Travis Wellman
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #!/bin/bash
nmap_svcs=/usr/share/nmap/nmap-services
known_tcp_ports_f () {
grep -v ^# $nmap_svcs |cut -f2 |grep -vE '/udp$' |grep -oE '^[0-9]+'
}
if [[ ! -v known_tcp_ports ]] && [ -r $nmap_svcs ]
then known_tcp_ports=($(known_tcp_ports_f))
fi
cksum_port () {
local inp_cksum=$(echo -n "$*" |cksum |cut -d' ' -f1)
if [[ ! -v known_tcp_ports ]]
then head -c4 <<<$inp_cksum
return $?
fi
for port_gen_offset in `seq 6`
do local potential_port=$(tail -c+$port_gen_offset <<<$inp_cksum |head -c4)
local c=0
until [ ! $c -lt ${#known_tcp_ports[*]} ] ||
[ $potential_port = ${known_tcp_ports[$c]} ]
do ((c++))
done
if [ $c -eq ${#known_tcp_ports[*]} ]
then echo $potential_port
return $?
fi
done
return 1
}
# options for all cases
if [[ ! -v hopts ]]
then hopts="-e UTF-8 --subdirectories"
fi
case "$1" in
[Dd]ocuments)
prefx=thelight
port=$(cksum_port documents)
rm -v ~/tmp/hatta-thelight.?????.out
hat_out=$(mktemp -p ~/tmp hatta-thelight.XXXXX.out)
hatta_cache=$HOME/tmp/hatta-documents
mkdir -p $hatta_cache
set -x
nohup python -m hatta $hopts \
-d ~/documents/wiki/pages \
-R ~/documents/wiki \
--port=$port \
-t $hatta_cache \
-n 'thelight wiki' &> $hat_out &
sleep 1
;;
career)
career_wiki_repo=$HOME/documents/career/wiki
port=$(cksum_port $career_wiki_repo)
rm -v ~/tmp/hatta-career.?????.out
hat_out=$(mktemp -p ~/tmp hatta-career.XXXXX.out)
hatta_cache=$HOME/tmp/hatta-career
mkdir -p $hatta_cache
set -x
nohup python -m hatta $hopts \
-d $career_wiki_repo \
-R $career_wiki_repo \
--port=$port \
-t $hatta_cache \
-n 'career wiki' &> $hat_out &
sleep 1
;;
/*)
bn="$(basename "$1")"
port=$(cksum_port $bn)
rm -v ~/tmp/hatta-$bn.?????.out
hat_out=$(mktemp -p ~/tmp hatta-$bn.XXXXX.out)
hatta_cache=$HOME/tmp/hatta-$bn
mkdir -p $hatta_cache
set -x
nohup python -m hatta $hopts \
-d "$1"/wiki \
-R "$1" \
--port=$port \
-t $hatta_cache \
-n "$bn wiki" &> $hat_out &
sleep 1
;;
*)
dirct="$(echo $HOME/*/$1/.hg |awk '{print $1}')"
dirct="$(dirname "$dirct")"
bn="$(basename "$dirct")"
port=$(cksum_port $bn)
rm -v ~/tmp/hatta-$bn.?????.out
hat_out=$(mktemp -p ~/tmp hatta-$bn.XXXXX.out)
hatta_cache=$HOME/tmp/hatta-$bn
mkdir -p $hatta_cache
set -x
nohup python -m hatta $hopts \
-d "$dirct"/wiki \
-R "$dirct" \
--port=$port \
-t $hatta_cache \
-n "$bn wiki" &> $hat_out &
sleep 1
;;
esac
if [[ -v hat_out ]] && [[ -v port ]]
then until curl -sf http://localhost:$port/ >/dev/null
do sleep 1
done
firefox http://localhost:$port/ &
tail $hat_out
fi
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.