#!/bin/bash VERSION=1.16 set -a #------------ Start of editable section ------------------------------ # Where is the wiki dir. You must change this, or execute this script from # wiki dir if data and templates dirs are subdirs. DIR=/var/www/htdocs/wiki # Change below for non-standard installs # Where are the data files (used to find Main/WebList.txt ) data=$DIR/data # Where ate the template files templates=$DIR/templates # name of Main web, change if you renamed it (%MAINWEB% in config) main=Main #------------ End of editable section -------------------------------- # usage: # without arguments: generates the templates # -d: generate a distrib in /tmp # -i: outputs a template for main.WebList # lists of hierarchical webs: bullet list in topic main.WebList # Format: space-separated items # 1 level one bullet / web group / hue [ options] [ / comments ] # hue is a 2-digit hex # background is the optional hex of the color (without #-prefix) # options can be: # EMPTY means that the group is empty and has only a list of sub-webs # as its web home and no topic list # 2 level two bullet / web name [ / comments ] # 3 other colors are set in TWiki Preferences: KSCOLORBG, KSCOLORHEADER, KCCOLORUNSEL # comments can be on following lines after a web, but indented # group is array of group names groupnum their number # webs is array of the subgroup (space-separated list) # colors is array of the hues # webnames is array of all webs, comments is their comments, index nweb # .color is appended to webname if it is a group # emptygroup is array of empty groups # doc in $DIR/pub/Plugins/KoalaSkin/TWikiKoalaSkin.txt # # TODO: # - hidden webs # - share CSS + include site CSS # - tabs as links (to other webs) # Variables introduced by Wenzel, Fabio 2002-08-12 myindex=100 myempty="__" # End of variables introduced by Wenzel weblist=$data/$main/WebList.txt verbose=true nbsp=' ' # 0xA0 KSCOLORBG='#FFFFFF' KSCOLORUNSEL='#e0e0c0' KSCOLORSEL='#ffddaa' KSICON='' KSHELP='%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/TWiki/WelcomeGuest' KSLMARGIN=150 KSTABWIDTH=80 KSNOEXPAND=false breakafterwebs= grouphasbreak= if [ "$OSTYPE" = cygwin ]; then CC=gcc; else CC=cc; fi expansed_files='style view twiki edit attach changeform moveattachment renamebase rdiff search searchbookview searchformat searchmeta searchrenameview sitemap preview oopsmore changes ks_leftbar' ktemp=/tmp/koalaskin-generate.$$ # options echo "Koala Skin generator, v$VERSION" stripimages=cat while test -z "${1##-*}" -a -n "$1";do case "$1" in -i) do_weblist_template=true;; -d) do_generate_distrib=true;; *) echo "See: http://twiki.org/cgi-bin/view/Plugins/KoalaSkin"; exit;; esac;shift done error () { echo "ERROR: $*" >&2; exit -1 } V () { if $verbose;then echo "$@";fi } if test -d "$DIR";then cd "$DIR";fi if test ! -e data/$main/WebList.txt -o ! -d templates -o ! -d data; then if test ! -e $weblist -o ! -d $templates -o ! -s $data; then error "I could not find the topic WebList. Did you create one? If you did, I cannot find its file at data/$main/WebList.txt Please check and edit the variables at the top of the bin/koalaskin-generate script: DIR, data, templates, main... Or execute the script from your wiki install dir!" fi else data=data;templates=templates;weblist=data/$main/WebList.txt fi main () { init curgroup=0 V -n "Templates:" while let 'curgroup store_options $nweb "$rest" $web ## <-- comment="$color $rest" check_dir $web lastwebname="${group[i]}.$web" else breakafterwebs="$breakafterwebs|$lastwebname" grouphasbreak="$grouphasbreak|${group[i]}" fi ;; # web =[*]) if test -n "$web"; then let i=i+1;group[i]=$web; webs[i]='';colors[i]="$color" groupnum[i]=$nweb webnames[nweb]="$web.$color" store_comments $nweb "$comment" let nweb=nweb+1 store_options $i "$rest" check_dir $web fi ;; # comment =*) while test "$bullet" != "${bullet#=}"; do bullet="${bullet#=}";done comment="$comment ${bullet##=} $web $color $rest" ;; # rest *) store_comments $nweb "$comment" esac ;; esac fi done store_comments $nweb "$comment" sed -e 's/background:[^;}]*;*//g' < $templates/style.koala.tmpl | expand_global_vars > $templates/styleneutral.koala.tmpl lastgroup=$i; let i=i+1; ngroups=$i if test -n "$KSNOICONS";then stripimages=strip_images;fi n=0 # Introduced by Wenzel, Fabio 2002-08-02 echo "myempty= $myempty" #End of introduced by Wenzel V "Web Groups:" while let 'n0"; then let nweb1="$1-1" if test -z "${comments[nweb1]}"; then comments[nweb1]="$2" fi fi } # $1 = webnum, $2 = comment # return comment without options store_options () { has_opt=true comment="$2" while $has_opt; do case "$comment" in EMPTY*) comment="${comment#EMPTY}";comment="${comment## }" emptygroup[$1]='[EMPTY]' ;; # Introduced by Wenzel, Fabio 2002-08-12 HIDE*) echo "test for hide: $1 $2 success" comment="${comment#HIDE}";comment="${comment## }" hidegroup[$1]='[HIDE]' myempty=`echo $myempty $3` ;; # End introduced by Wenzel *) has_opt=false;; esac done } generate_sitemaps () { generate_sitemap | $stripimages > $templates/sitemapwebs.koala.tmpl nwebdir=0 V -n "Sitemaps: " while test -n "${webnames[nwebdir]}"; do webdir="${webnames[nwebdir]}"; webdir="${webdir%.*}" V -n " $webdir" generate_sitemap "$webdir" | $stripimages > $templates/$webdir/sitemapwebs.koala.tmpl let nwebdir=nwebdir+1 done V } # $1 = web generate_sitemap () { nweb=0 width=$KSTABWIDTH margin="      " echo "" echo "" while test -n "${webnames[nweb]}"; do webname="${webnames[nweb]}";web="${webname%.*}" if test "$1" = "$web"; then class=selectedWeb; else class=web fi if test "$web" != "${webnames[nweb]}"; then # we start a new group ingroup=true color="${webname#*.}";color1=`color1 $color`;color2=`color2 $color` echo "" echo "" if test -z "$1"; then add_style_colors $web $color1 $color2; fi let nweb=nweb+1 done echo "" echo "
" else # we are in a subweb if $ingroup; then ingroup=false echo "" fi echo -n "
$margin" fi echo "$web ${comments[nweb]}
" } # groupmap is a subset of the sitemap reduced to the group generate_groupmaps () { curgroup=0 while let 'curgroup${group[curgroup]} ${comments[gn]}

This web is just a group of sub-webs:" > $templates/${group[curgroup]}/groupmap.koala.tmpl sed -e '/^$/,/^$/d' \ -e '/^$/,/^$/d' \ -e '/^/,//d' \ < $templates/${group[curgroup]}/sitemapwebs.koala.tmpl \ >> $templates/${group[curgroup]}/groupmap.koala.tmpl # fi let curgroup=curgroup+1 done } color1 () { case $1 in ??) hsv2rgb "${1}ffa0";; # hue ??????) echo "$1";; # rgb-color esac } color2 () { case $1 in ??) hsv2rgb "${1}30f0";; # hue ??????) hue=`rgb2hsv $1`; hsv2rgb "${hue%????}30f0";; # rgb-color esac } color3 () { case $1 in ??) hsv2rgb "${1}ff60";; # hue ??????) hue=`rgb2hsv $1`; hsv2rgb "${hue%????}ff60";; # rgb-color esac } # add a CSS style for color of each web to all stylesheets # $1 = web, $2 = color1, $3 = color2 add_style_colors () { for i in $templates/*/style.koala.tmpl;do (echo ".bg1-${1}{background: #$2;color:white;}" echo ".bg2-${1}{background: #$3;color:white;}") >> $i done } # $1 = group, $2 = webs, $3 = hue # globals: curgroup, lastgroup (indexes) generate_group_skin () { KSCOLORWEB=`color1 $3` KSCOLORWEBFILL=`color2 $3` KSCOLORWEBFG=`color3 $3` KSCOLORWEBUNSEL=$KSCOLORWEB # Create the per-web CSS stylesheets style.koala.tmpl # and menu bars websbar.koala.tmpl for web in $1 $2;do empty_flag= V -n " $web" check_dir $web KSWEBSEARCH="`generate_search_options $web $1 \"$2\"`" if [ "$web" = "$1" -a -n "${emptygroup[curgroup]}" ];then empty_flag=true;fi generate_group_css $web $1 "$2" "$empty_flag" generate_websbar $web "$1" "$2" | $stripimages >$templates/$web/websbar.koala.tmpl done } check_dir () { if test ! -d $data/$1; then error "Could not find Web $1" fi if test ! -d $templates/$1;then mkdir $templates/$1;chmod a+rwx $templates/$1 fi } generate_group_css () { # $1=web $2=group $3=subwebs $4=emptyflag for t in $expansed_files do if [ -n "$4" ];then empty=remove_empty EMPTYGROUPHEADER="%TMPL:INCLUDE{\"groupmap\"}%" else empty=cat EMPTYGROUPHEADER= fi expand_vars "$1" "$2" "$3" $templates $t.koala.tmpl done if $KSNOEXPAND;then :;else expand_template_includes $templates $1; fi } # $1=web $2=group $3=subwebs $4=templatesdir $5=templatesfile expand_vars () { sed -e "s/%KSCOLORWEB%/#$KSCOLORWEB/g" \ -e "s/%KSCOLORWEBFILL%/#$KSCOLORWEBFILL/g" \ -e "s/%KSCOLORWEBFG%/#$KSCOLORWEBFG/g" \ -e "s/%KSCOLORWEBUNSEL%/#$KSCOLORWEBUNSEL/g" \ -e "s|%KSWEBSEARCH%|$KSWEBSEARCH|"g \ -e "s/%WEB%/$1/g" -e "s/%WEBGROUP%/$2 $3/g" \ -e "s/%%/%WEB%/g" \ -e "s/%WEBGROUPLEADER%/$2/g" \ -e "s/%KSCOLORUNSEL%/$KSCOLORUNSEL/g" \ -e "s/%KSLMARGIN%/$KSLMARGIN/g" \ -e "s/%KSTABWIDTH%/$KSTABWIDTH/g" \ -e "s/%KSCOLORSEL%/$KSCOLORSEL/g" \ -e "s/%KSCOLORBG%/$KSCOLORBG/g" \ -e "s/%EMPTYGROUPHEADER%/$EMPTYGROUPHEADER/g" \ -e "s|%KSICON%|$KSICON|g" \ -e "s|%KSHELP%|$KSHELP|g" \ < "$4/$5" | $stripimages | $empty > "$4/$1/$5" } expand_global_vars () { sed -e "s/%KSCOLORUNSEL%/$KSCOLORUNSEL/g" \ -e "s/%KSCOLORSEL%/$KSCOLORSEL/g" \ -e "s/%KSCOLORBG%/$KSCOLORBG/g" \ -e "s/%KSLMARGIN%/$KSLMARGIN/g" \ -e "s/%KSTABWIDTH%/$KSTABWIDTH/g" \ -e "s|%KSICON%|$KSICON|g" \ -e "s|%KSHELP%|$KSHELP|g" } # $1=template dir, $2=web expand_template_includes () { included_tmpls=`grep '%TMPL:INCLUDE{' $1/$2/*.koala.tmpl|sed -e 's/.*%TMPL:INCLUDE{"\([^"]*\)"}%.*/\1/'|sort|uniq` rm -f $ktemp for i in $included_tmpls; do if test -e $1/$2/$i.koala.tmpl;then file=$1/$2/$i.koala.tmpl else file=$1/$i.koala.tmpl fi echo "/%TMPL:INCLUDE{\"$i\"}%/{s/%TMPL:INCLUDE{[^}]*}%// r$file }" >> $ktemp done dirty=true while $dirty; do dirty=false for i in `grep -l '%TMPL:INCLUDE{"' $1/$2/*.koala.tmpl`; do mv $i $i.bak; sed -f $ktemp < $i.bak > $i if cmp -s $i $i.bak;then echo;echo "Warning! $i inchanged!" echo "TMPL:INCLUDE lefts:" grep "%TMPL:INCLUDE{" $i fi rm -f $i.bak dirty=true done done } remove_empty () { sed -e '/^$/,/^$/d' } generate_search_options () { # $1=web $2=group $3=subwebs if test "$1" = "$2"; then groupsel='selected'; websel='' else groupsel=''; websel='selected' fi echo "" } generate_websbar () { # $1=web $2=group $3=webs # group row let curgroup_prev=curgroup-1; let curgroup_next=curgroup+1 echo "$group_start" i=0 while let 'i #if [ -z "${hidegroup[aa]}" ]; then #echo "$tab">>tabs.txt if (echo $myempty | grep $tab >/dev/null) then echo "empty $tag" >>tabs.txt else webs_tab '%SCRIPTURL%/view%SCRIPTSUFFIX%/'$tab'/WebHome' $tab $sel fi ##wenzel<-- if [ $lastweb = $j ]; then : else case $2.$tab in ${breakafterwebs#|}) echo "$webs_break";; *) echo "$webs_sep";; esac fi let j=j+1 done if [ "$j" = 0 ]; then echo "";fi echo "$webs_end" } check_forgotten_dirs () { for d in $data/[A-Z]*;do if test -d "$d"; then notfound=true for w in ${webnames[@]}; do if test "${d##*/}" = "${w%%.*}"; then notfound=false; break fi done if $notfound; then echo "*** WARNING: web ${d##*/} is not described" fi fi done } # remove tags, filter strip_images () { sed -e s'|]*KoalaSkin[^>]*>||g' } ################################################################### BARS DEFS # fixed group_start="" group_end="
" group_sep="|" webs_start="" webs_break="
$nbsp" webs_start_break="
$nbsp" webs_end="
" webs_sep="
|
" # variable group_tab () { # $1=url $2=name $3=selected or "", optional $4=width echo "" } webs_tab () { # $1=url $2=name $3=selected or "", optional $4=width echo "" } ###################################################################### INITS weblist_template () { cat <<\EOF ---+ List of all Webs For the Plugins.KoalaSkin Format: space-separated items 1 _3 spaces_ * webgroupname hue [options][comments]
hue can bit 2 hex digits, or the 6 hex digits for the RGB value
options can be: * EMPTY the group is not to be used per se, only its sub-webs 1 _6 spaces_ * webname [comments]
comments can be continued on the following lines. If no webname, starts a new row of tabs (useful for webs too numerous to fit on a line) 1 other colors are set in the TWiki syntax:
_6 spaces_ * Set *VARIABLE* = _value_
variables being: * KSCOLORBG the color of the page background * KSCOLORUNSEL color of tabs of unselected web groups * KSCOLORSEL color of the text of the selected tab * KSICON upper-left wiki icon IMG tag, with dims * KSHELP url of the help page (for the help icon) * KSNOICONS set to true to disable icons for buttons on the upper right: Home/Edit/Attach/Sitemap/Help * KSLMARGIN left margin (default 150) * KSTABWIDTH minimum width of web tabs (default 80) * KSNOEXPAND if not equal to "false", do not expand template includes to save space but consume CPU. --- * Set KSCOLORBG = #FFFEE4 * Set KSCOLORUNSEL = #e0e0c0 * Set KSCOLORSEL = #ffff80 * Set KSICON = click on the %WIKITOOLNAME% logo to go to homepage EOF } generate_distrib () { tar cf - \ bin/searchmulti \ bin/savemulti \ bin/koalaskin-generate \ templates/sitemap.koala.tmpl \ templates/style.koala.tmpl \ templates/twiki.koala.tmpl \ templates/view.koala.tmpl \ templates/edit.koala.tmpl \ templates/preview.koala.tmpl \ templates/attach.koala.tmpl \ templates/changeform.koala.tmpl \ templates/moveattachment.koala.tmpl \ templates/oopsmore.koala.tmpl \ templates/renamebase.koala.tmpl \ templates/rdiff.koala.tmpl \ templates/search.koala.tmpl \ templates/searchbookview.koala.tmpl \ templates/searchformat.koala.tmpl \ templates/searchmeta.koala.tmpl \ templates/searchrenameview.koala.tmpl \ templates/changes.koala.tmpl \ templates/ks_leftbar.koala.tmpl \ pub/Plugins/KoalaSkin/home.gif \ pub/Plugins/KoalaSkin/edit.gif \ pub/Plugins/KoalaSkin/attach.gif \ pub/Plugins/KoalaSkin/help.gif \ pub/Plugins/KoalaSkin/print.gif \ pub/Plugins/KoalaSkin/sitemap.gif \ pub/Plugins/KoalaSkin/TWikiKoalaSkin.txt \ | gzip -9 > /tmp/TWikiKoalaSkin.tgz cp pub/Plugins/KoalaSkin/TWikiKoalaSkin.txt /tmp echo "generated /tmp/TWikiKoalaSkin.tgz and /tmp/TWikiKoalaSkin.txt" } ###################################################################### COLORS rgb2hsv=/tmp/rgb2hsvhex hsv2rgb=/tmp/hsv2rgbhex rgb2hsv () { $rgb2hsv "$@" } hsv2rgb () { $hsv2rgb "$@" } colorname2rgb () { grep -i "^[ ]*[0-9][0-9]*[ ][ ]*[0-9][0-9]*[ ][ ]*[0-9][0-9]*[ ][ ]*$1\$" /usr/X11R6/lib/X11/rgb.txt | ( read R G B rest; echo "${hex[$R]}${hex[$G]}${hex[$B]}" if [ -z "$B" ]; then echo "Error: colorname not found: $1" >&2; exit 1; fi if $verbose; then echo "$1: ($R,$G,$B): ${hex[$R]}${hex[$G]}${hex[$B]}" 1>&2; fi ) } tolower () { echo "$1" | tr '[A-Z]' '[a-z]' } hex=(00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF) generate_rgb2hsvhex () { if [ -x $rgb2hsv ]; then : else rm -rf $rgb2hsv ${rgb2hsv}.c cat > ${rgb2hsv}.c << \EOF /* code stolen from GTK */ #include #define MIN(a,b) (ab?a:b) #define NO_HUE -1 /* Input: r, g, b as hex-webstring Outputs: h, s, v as hex-webstring */ gtk_color_selection_rgb_to_hsv (double r, double g, double b, double *h, double *s, double *v) { double max, min, delta; max = r; if (g > max) max = g; if (b > max) max = b; min = r; if (g < min) min = g; if (b < min) min = b; *v = max; if (max != 0.0) *s = (max - min) / max; else *s = 0.0; if (*s == 0.0) *h = -1.0; else { delta = max - min; if (r == max) *h = (g - b) / delta; else if (g == max) *h = 2.0 + (b - r) / delta; else if (b == max) *h = 4.0 + (r - g) / delta; *h = *h * 60.0; if (*h < 0.0) *h = *h + 360; } } int main (int argc, char **argv) { int ri, gi, bi, hi, si, vi; double r, g, b, h, s, v; if (argc == 2) { sscanf(argv[1], "%2x%2x%2x", &ri, &gi, &bi); r = ri; r /= 255; g = gi; g /= 255; b = bi; b /= 255; gtk_color_selection_rgb_to_hsv(r, g, b, &h, &s, &v); hi = (h/360)*255; si = s*255; vi = v*255; printf("%02x%02x%02x\n", hi,si, vi); return 0; } else return 1; } EOF $CC -O -o $rgb2hsv ${rgb2hsv}.c if [ "$OSTYPE" = cygwin ]; then chmod a+x $rgb2hsv; fi rm -f ${rgb2hsv}.c fi if [ "`/tmp/rgb2hsvhex 123456`" != 94c956 ]; then error "/tmp/rgb2hsvhex incorrectly compiled!" fi } generate_hsv2rgbhex () { if [ -x $hsv2rgb ]; then : else rm -rf $hsv2rgb ${hsv2rgb}.c cat > ${hsv2rgb}.c << \EOF /* code stolen from GTK */ #include #define MIN(a,b) (ab?a:b) #define NO_HUE -1 /* Input: r, g, b as hex-webstring Outputs: h, s, v as hex-webstring */ void gtk_color_selection_hsv_to_rgb (double h, double s, double v, double *r, double *g, double *b) { int i; double f, w, q, t; if (s == 0.0) s = 0.000001; if (h == -1.0) { *r = v; *g = v; *b = v; } else { if (h == 360.0) h = 0.0; h = h / 60.0; i = (int) h; f = h - i; w = v * (1.0 - s); q = v * (1.0 - (s * f)); t = v * (1.0 - (s * (1.0 - f))); switch (i) { case 0: *r = v; *g = t; *b = w; break; case 1: *r = q; *g = v; *b = w; break; case 2: *r = w; *g = v; *b = t; break; case 3: *r = w; *g = q; *b = v; break; case 4: *r = t; *g = w; *b = v; break; case 5: *r = v; *g = w; *b = q; break; } } } int main (int argc, char **argv) { int ri, gi, bi, hi, si, vi; double r, g, b, h, s, v; if (argc == 2) { sscanf(argv[1], "%2x%2x%2x", &hi, &si, &vi); h = hi * 360; h /= 255; s = si; s /= 255; v = vi; v /= 255; gtk_color_selection_hsv_to_rgb(h, s, v, &r, &g, &b); ri = r*255; gi = g*255; bi = b*255; printf("%02x%02x%02x\n", ri, gi, bi); return 0; } else return 1; } EOF $CC -O -o $hsv2rgb ${hsv2rgb}.c if [ "$OSTYPE" = cygwin ]; then chmod a+x $hsv2rgb; fi rm -f ${hsv2rgb}.c fi if [ "`/tmp/hsv2rgbhex 123456`" != 564b44 ]; then error "/tmp/hsv2rgbhex incorrectly compiled!" fi } ###################################################################### MAIN if [ -n "$do_weblist_template" ]; then weblist_template elif [ -n "$do_generate_distrib" ]; then generate_distrib else sed -e 's/ /=/g' -e 's/ //g' $weblist | main fi rm -f $ktemp exit 0 ### EMACS MODES ### Local Variables: *** ### mode:ksh *** ### End: ***
$2$2