db2categories.sh - gopher-lawn - The gopher lawn gopher directory project.
 (HTM) git clone git://bitreich.org/gopher-lawn/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/gopher-lawn/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
       ---
       db2categories.sh (1299B)
       ---
            1 #!/bin/sh
            2 
            3 set -x
            4 
            5 titlemaxlength=74
            6 
            7 if [ $# -gt 0 ];
            8 then
            9         inputfile="$1"
           10 else
           11         inputfile="/dev/stdin"
           12 fi
           13 
           14 printdbtmpl() {
           15         linetype="c"
           16         linetypetext="category"
           17         host="server"
           18         port="port"
           19         name="$1"
           20         selector="$2"
           21         linkname="$3"
           22         title="${name}"
           23         description="$4"
           24         parent="root"
           25         keywords="${name}"
           26 
           27         tmplfile="${name}.${linetypetext}"
           28 
           29         [ -e "$tmpfile" ] && return
           30 
           31         ustitle="$(printf "%s\n" "${title}" \
           32                 | tr 'a-z' 'A-Z' \
           33                 | sed 's,[a-zA-Z0-9],&_,g; s, ,__,g; s,_$,,; s,___,__,g')"
           34 
           35         printf "Type: %s\n" "${linetypetext}" > "${tmplfile}"
           36         printf "Name: %s\n" "${name}" >> "${tmplfile}"
           37         printf "Selector: %s\n" "${selector}" >> "${tmplfile}"
           38         printf "Host: %s\n" "${host}" >> "${tmplfile}"
           39         printf "Port: %s\n" "${port}" >> "${tmplfile}"
           40         printf "LinkName: %s\n" "${linkname}" >> "${tmplfile}"
           41         printf "Title: %s\n" "${ustitle}" >> "${tmplfile}"
           42         printf "Description: %s\n" "${description}" >> "${tmplfile}"
           43         printf "Parent: %s\n" "${parent}" >> "${tmplfile}"
           44         printf "Keywords: %s\n" "${keywords}" >> "${tmplfile}"
           45         printf "\n" >> "${tmplfile}"
           46 }
           47 
           48 cat "${inputfile}" \
           49 | grep Category \
           50 | cut -d ':' -f 2 \
           51 | sed -s 's:,:\n:g' \
           52 | cut -d' ' -f 2 \
           53 | sort \
           54 | uniq \
           55 | while read -r category;
           56 do
           57         printdbtmpl "${category}" \
           58                 "/lawn/${category}" \
           59                 "${category}" \
           60                 "${category}"
           61 done
           62