summaryrefslogtreecommitdiff
path: root/burrow
blob: be0739f62b5854b32277d047259044f06cfe8b68 (plain)
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
#!/bin/sh

### read from $1 and print on stdout a list of DIR selectors
### one per line, terminated by a line with ".\r\n"
## function
get_dirs(){
	OLDIFS=$IFS
	#IFS=$'\t\n'
##	IFS="$(echo t | tr t \\t)
##"
	IFS="|"
	while read name sel host port; do
##		echo " --- name: \"$name\""
##		echo " --- sel: \"$sel\""
##		echo " --- host: \"$host\""
##		echo " --- port: \"$port\""
		TYPE=$(echo "$name" | cut -c 1)
##		echo " --- TYPE \"$TYPE\""
##		echo "$TYPE, $name, $sel, $host, $port"
		[ "${TYPE}" = "1" ] && {
			port=$(echo $port | sed -r -e 's/\r//g')
			dir_id=$(echo "${TYPE}|${sel}|${host}|${port}" | sed 's/^1||/1|\/|/g')
			sid=$(echo "${dir_id}" | sha256sum | cut -d " " -f 1 )
			echo "${dir_id}|${sid}"
		}
	done 
	IFS=$OLDIFS
}


FIN=${1:-"/dev/stdin"}
SRC="$2"

cat "$FIN" | sed -r -e 's/\t/|/g' | get_dirs