#!/bin/sh
 
 # gmsunzip
 # ========
 
 # This file is part of Gerolf Markup Shredder, 
 # written by G. D. Brettschneider (1999-2008). All rights reserved.
 # Send corrections to: MarkupShredder(at)Gerolf.org (www.Gerolf.org)
 # Subject: GMS shell scripts

 export GMSdateGMSUNZIP=20080107
 GMS_VERSION="0.08a"
 GMS_VERS="008a" 
 
 # ============================================================================
 
 if [ "$1" = "" ]; then   
    xterm -fg black -bg white -e "$0" -shell
    exit
 fi
  
 left="Running:      GMS unzip ..."
 right="Gerolf Markup Shredder $GMS_VERSION"
 arg="///////////////////////////////////////"
 quit="[Ctrl+C] to quit ..."
  
 if [ "$0" != "./gmsunzip" ]; then   
   test=$(dirname "$0")
     export GMS_ROOT=$test
     if [ -d "$GMS_ROOT" ]; then cd "$GMS_ROOT"; fi
   test=
 fi 
 
 
 # Any OS messages: -----------------------------------------------------------
 
 setterm -clear
 echo " $left                       $right"
 echo " $arg$arg"
 echo
 echo "               Welcome to Gerolf Markup Shredder,"
 echo "               the typesetting program that uses TeX"
 echo "               for document conversion from HTML to PDF."
 echo
 echo "               The latest version of GMS can always be found at:"
 echo "                 http://www.Gerolf.org"
 echo  
 echo "               You should have installed a browser for hypertext"
 echo "               markup files and a reader for portable document files."
 echo
 echo "               HTML Browsers are available at:"
 echo "                 http://www.konqueror.org"
 echo "                 http://www.mozilla.org"
 echo "                 http://wp.netscape.com/download"
 echo "                 http://www.opera.com"
 echo
 echo "               Adobe Acrobat Reader for PDF can be downloaded from:"
 echo "                 http://www.adobe.com/products/acrobat/alternate.html"
 echo
 echo " $arg$arg"
 echo  -n "               Press [Enter] to continue or $quit"
 read
   
 setterm -clear
 echo " $left                       $right"
 echo " $arg$arg"
 echo
 echo "               GMS unzip will create the following directory structure:"
 echo
 echo "               [GMS_ROOT] .......'../gmsNNNx', '../gerolf'"
 echo "                     +- batch ... DOS/Windows scripts"
 echo "                     +- bin ..... DOS/Windows/Linux executables"
 echo "                     +- data .... Codepages and hyphenation patterns"
 echo "                     +- doc ..... HTML template files, tested with GMS"
 echo "                     +- etc ..... Configuration, setup and start files"
 echo "                     +- fonts ... PostScript, TrueType and TeX fonts"
 echo "                     +- shell ... Linux scripts for Bash"
 echo "                     +- tex ..... TeX macro scripts"
 echo "                     '- tmp ..... Temporary files"
 echo 
 echo 
 echo 
 echo 
 echo 
 echo 
 echo 
 echo " $arg$arg"
 echo  -n "               Press [Enter] to continue or $quit"
 read
    
 # File extraction: -----------------------------------------------------------
 
 if [ ! -f /usr/bin/unzip ]; then
   setterm -clear
   echo " $left                       $right"
   echo " $arg$arg"
   echo
   echo "               Missing '/usr/bin/unzip' binary."
   echo
   echo "               Please install 'unzip' from your system disk."
   echo
   echo  -n "               Press [Enter] to continue or $quit"
   read
 fi
 
 setterm -clear
 echo " $left                       $right"
 echo " $arg$arg"
 echo
 
 # unzip option:
 # -u: update existing files
 # -o: overwrite existing files without prompting
 
 e="Extracting:  "
 m="Missing:     "
 GMS_UNZIP="unzip -u -o"
 
 arg1="gms$GMS_VERS.zip"
   if [ ! -f $arg1 ]; then echo " $m $arg1 (required)"; fi
   if [ -f $arg1 ]; then echo " $e $arg1 ..."; fi
   if [ -f $arg1 ]; then $GMS_UNZIP $arg1 > gmsunzip.log; fi
 arg1=
    
 if [ ! -f texhyph.zip ]; then echo " $m texhyph.zip (required)"; fi
 if [ -f texhyph.zip ]; then echo " $e texhyph.zip ..."; fi
 if [ -f texhyph.zip ]; then $GMS_UNZIP texhyph.zip >> gmsunzip.log; fi
    
 if [ ! -f bindos1.zip ]; then echo " $m bindos1.zip (required on Dos)"; fi
 if [ -f bindos1.zip ]; then echo " $e bindos1.zip ..."; fi
 if [ -f bindos1.zip ]; then $GMS_UNZIP bindos1.zip >> gmsunzip.log; fi
 
 if [ ! -f bindos2.zip ]; then echo " $m bindos2.zip (required on Dos)"; fi
 if [ -f bindos2.zip ]; then echo " $e bindos2.zip ..."; fi
 if [ -f bindos2.zip ]; then $GMS_UNZIP bindos2.zip >> gmsunzip.log; fi
   
 if [ ! -f docdemo.zip ]; then echo " $m docdemo.zip (recommended)"; fi
 if [ -f docdemo.zip ]; then echo " $e docdemo.zip ..."; fi
 if [ -f docdemo.zip ]; then $GMS_UNZIP docdemo.zip >> gmsunzip.log; fi
  
 if [ ! -f docw3c.zip ]; then echo " $m docw3c.zip (recommended)"; fi
 if [ -f docw3c.zip ]; then echo " $e docw3c.zip ..."; fi
 if [ -f docw3c.zip ]; then $GMS_UNZIP docw3c.zip >> gmsunzip.log; fi
 
 if [ ! -f docweb.zip ]; then echo " $m docweb.zip (recommended)"; fi
 if [ -f docweb.zip ]; then echo " $e docweb.zip ..."; fi
 if [ -f docweb.zip ]; then $GMS_UNZIP docweb.zip >> gmsunzip.log; fi
 
 if [ ! -f fontst1p.zip ]; then echo " $m fontst1p.zip (recommended)"; fi
 if [ -f fontst1p.zip ]; then echo " $e fontst1p.zip ..."; fi
 if [ -f fontst1p.zip ]; then $GMS_UNZIP fontst1p.zip >> gmsunzip.log; fi
 
 if [ ! -f fontst1u.zip ]; then echo " $m fontst1u.zip (recommended)"; fi
 if [ -f fontst1u.zip ]; then echo " $e fontst1u.zip ..."; fi
 if [ -f fontst1u.zip ]; then $GMS_UNZIP fontst1u.zip >> gmsunzip.log; fi
 
 if [ ! -f fontsttf.zip ]; then echo " $m fontsttf.zip (recommended)"; fi
 if [ -f fontsttf.zip ]; then echo " $e fontsttf.zip ..."; fi
 if [ -f fontsttf.zip ]; then $GMS_UNZIP fontsttf.zip >> gmsunzip.log; fi
 
 if [ ! -f fontst1c.zip ]; then echo " $m fontst1c.zip (optional)"; fi
 if [ -f fontst1c.zip ]; then echo " $e fontst1c.zip ..."; fi
 if [ -f fontst1c.zip ]; then $GMS_UNZIP fontst1c.zip >> gmsunzip.log; fi
 
 if [ ! -f fontst1d.zip ]; then echo " $m fontst1d.zip (optional)"; fi
 if [ -f fontst1d.zip ]; then echo " $e fontst1d.zip ..."; fi
 if [ -f fontst1d.zip ]; then $GMS_UNZIP fontst1d.zip >> gmsunzip.log; fi
 
 if [ ! -f fontst1e.zip ]; then echo " $m fontst1e.zip (optional)"; fi
 if [ -f fontst1e.zip ]; then echo " $e fontst1e.zip ..."; fi
 if [ -f fontst1e.zip ]; then $GMS_UNZIP fontst1e.zip >> gmsunzip.log; fi
 
 if [ ! -f binwin.zip ]; then echo " $m binwin.zip (required on Windows)"; fi
 if [ -f binwin.zip ]; then echo " $e binwin.zip ..."; fi
 if [ -f binwin.zip ]; then $GMS_UNZIP binwin.zip >> gmsunzip.log; fi
 
 if [ ! -f binlinux.zip ]; then echo " $m binlinux.zip (required on Linux)"; fi
 if [ -f binlinux.zip ]; then echo " $e binlinux.zip ..."; fi
 if [ -f binlinux.zip ]; then $GMS_UNZIP binlinux.zip >> gmsunzip.log; fi
 
 # Additional archives:
 
 if [ -f fontsin.zip ]; then $GMS_UNZIP fontsin.zip >> gmsunzip.log; fi
 if [ -f fontsth.zip ]; then $GMS_UNZIP fontsth.zip >> gmsunzip.log; fi
 
 unset e
 unset m
 unset GMS_UNZIP
           
 if [ ! -f "$GMS_ROOT/etc/gmssetup" ]; then
   if [ -f "$PWD/etc/gmssetup" ]; then export GMS_ROOT="$PWD"; fi; fi
    
 if [ -f "$GMS_ROOT/etc/gmssetup" ]; then
   chmod 755 "$GMS_ROOT/etc/gmssetup"
   chmod 755 "$GMS_ROOT/etc/folder"
   
   # Create [GMS_ROOT] level link to gmssetup:
     GMS_LINK="$GMS_ROOT/gmssetup"
     echo "#!/bin/sh" > "$GMS_LINK"
     echo " cd \"$GMS_ROOT/etc\"" >> "$GMS_LINK"
     echo " \"$GMS_ROOT/etc/gmssetup\" \$1" >> "$GMS_LINK"
     chmod 755 "$GMS_LINK"
     
     GMS_LINK="$HOME/Desktop/gmssetup"
     echo "#!/bin/sh" > "$GMS_LINK"
     echo " cd \"$GMS_ROOT/etc\"" >> "$GMS_LINK"
     echo " \"$GMS_ROOT/etc/gmssetup\" \$1" >> "$GMS_LINK"
     chmod 755 "$GMS_LINK"
               
   # Create desktop link to gmssetup:
   # if [ ! -d "$HOME/Desktop" ]; then mkdir "$HOME/Desktop"; fi
   # GMS_LINK="$HOME/Desktop/gmssetup.desktop"
   # echo "[Desktop Entry]" > "$GMS_LINK"
   # echo "Exec=\"$GMS_ROOT/gmssetup\"" >> "$GMS_LINK"
   # echo "Icon=run" >> "$GMS_LINK"
   # echo "Name=gmssetup" >> "$GMS_LINK"
   # echo "Terminal=true" >> "$GMS_LINK"
   # echo "Type=Application" >> "$GMS_LINK"
   # chmod 755 "$GMS_LINK"
                          
   # Done GMS unzip message:
     echo
     echo
     echo " Done:         GMS unzip."
     echo
     echo " $arg$arg"
     echo  -n "               Press [Enter] to run GMS setup or $quit"
     read  
          
   # Run GMS setup:
     cd "$GMS_ROOT/etc"
     setterm -clear
     source "$GMS_ROOT/etc/gmssetup" -shell
     
   export GMS_LINK=
 else   
   setterm -reset
   echo " $left                       $right"
   echo " $arg$arg"
   echo
   echo "               Did not find GMS setup script in directory"
   echo "                '$PWD/etc'."
   echo
   echo "               Repeat installation procedure in terminal."
   echo "               Download an updated version of GMS from"
   echo "                'http://www.Gerolf.org'."
   echo
   read
 fi
