]> git.plutz.net Git - bookman/commitdiff
Importer for old bookman files
authorpaul <paul@plutz.net>
Sat, 9 Dec 2017 15:24:05 +0000 (15:24 +0000)
committerpaul <paul@plutz.net>
Sat, 9 Dec 2017 15:24:05 +0000 (15:24 +0000)
svn path=/trunk/; revision=12

import.sh [new file with mode: 0755]

diff --git a/import.sh b/import.sh
new file mode 100755 (executable)
index 0000000..aec5ba1
--- /dev/null
+++ b/import.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+HTTP_COOKIE='id=____________'
+mkdir -p 'users/____________'
+. ./index.cgi >&-
+
+seq=$(date +%s)
+seqid(){
+  { printf "$(
+      while [ -n "$seq" -a "${seq}" -gt 0 ]; do
+        # ^^ double condition seems necessary in dash
+        # (possibly due to faulty result caching?)
+        printf \\%o $((seq % 256))
+        seq=$((seq / 256))
+      done
+    )" | tac
+    head -c5 /dev/urandom
+  } \
+  | uuencode -m - \
+  | sed -n '2{y;+/;:_;;p}'
+}
+
+
+import="$1"
+order=1000
+BDB="users/$(genid)"
+
+mkdir -p "${BDB}/favicons"
+
+while read l; do
+  case "$l" in
+    folder=*)
+      fid="$(seqid)"
+      name="$(QUERY_STRING="$l" GET folder)"
+      file="${BDB}/${fid}.bm"
+      printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"$file"
+      order="$(($order + 1000))"
+      seq=$(($seq + 1))
+      printf 'Setting up Folder: %s\n' "$name"
+      ;;
+    title=*)
+      title="$(QUERY_STRING="$l" GET title)"
+      ;;
+    content=*)
+      uri="$(QUERY_STRING="$l" GET content |head -n1)"
+      if [ -f "$file" -a -n "$title" ]; then
+        bid=$(seqid)
+        printf '%s\t%s\t%s\n' "$bid" "$(HTML "$title")" "$uri" >>"$file"
+        getFavicon "$uri" "$bid" &
+        seq=$(($seq + 1))
+        printf 'Added record "%s" to %s\n' "$title" "$file"
+      fi
+      ;;
+  esac
+done <"$import"
+
+printf 'Finished import to collection: %s\n' "${BDB##*/}"