#!/bin/sh

####################################
#
# Script to compress html-files, search index files and
# images of wikipedia for viewing on UNIX-PDAs.
# Works in conjunction with wiki2staticz.pl
#
# Author: Markus Baumeister
# License: GPL
# You might find more info at: http://www.retsiemuab.de/wiki2zaurus
#
####################################

source parameters

cd ${wikipath}/${lang}

for d1 in ? ; do
   if (( ${#d1} == 1 )); then
     echo $d1
     cd $d1
     for d2 in ??; do
       cd $d2
       for d3 in ???; do
         ls $d3 | awk -- "{ print \"$d3/\"\$1 }" >files
         tar cf - -T files | gzip -9 >${d3}.tgz
         rm -rf $d3 files
       done
       cd ..
     done 
     cd ..
   fi
done

echo Now compressing search indices

cd search
for d1 in _ 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z ; do
   echo -n  $d1 " "
   jsname="${d1}?.js ${d1}??.js ${d1}.js"
   tar cf -  $jsname 2>/dev/null  | gzip -9 >${d1}.tgz
   rm -f $jsname
done
echo Now clearing empty image files

cd ../..
find media -size 0 -exec rm {} \; -print

echo "Everything compressed and cleaned up"


