]> git.plutz.net Git - bookman/blob - import.sh
bookmark creation dialog
[bookman] / import.sh
1 #!/bin/sh
2
3 HTTP_COOKIE='id=____________'
4 mkdir -p 'users/____________'
5 . ./index.cgi >&-
6
7 seq=$(date +%s)
8 seqid(){
9   { printf "$(
10       while [ -n "$seq" -a "${seq}" -gt 0 ]; do
11         # ^^ double condition seems necessary in dash
12         # (possibly due to faulty result caching?)
13         printf \\%o $((seq % 256))
14         seq=$((seq / 256))
15       done
16     )" | tac
17     head -c5 /dev/urandom
18   } \
19   | uuencode -m - \
20   | sed -n '2{y;+/;:_;;p}'
21 }
22
23
24 import="$1"
25 order=1000
26 BDB="users/$(genid)"
27
28 mkdir -p "${BDB}/favicons"
29
30 while read l; do
31   case "$l" in
32     folder=*)
33       fid="$(seqid)"
34       name="$(QUERY_STRING="$l" GET folder)"
35       file="${BDB}/${fid}.bm"
36       printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"$file"
37       order="$(($order + 1000))"
38       seq=$(($seq + 1))
39       printf 'Setting up Folder: %s\n' "$name"
40       ;;
41     title=*)
42       title="$(QUERY_STRING="$l" GET title)"
43       ;;
44     content=*)
45       uri="$(QUERY_STRING="$l" GET content |head -n1)"
46       if [ -f "$file" -a -n "$title" ]; then
47         bid=$(seqid)
48         printf '%s\t%s\t%s\n' "$bid" "$(HTML "$title")" "$uri" >>"$file"
49         getFavicon "$uri" "$bid" &
50         seq=$(($seq + 1))
51         printf 'Added record "%s" to %s\n' "$title" "$file"
52       fi
53       ;;
54   esac
55 done <"$import"
56
57 printf 'Finished import to collection: %s\n' "${BDB##*/}"