WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Script to compress man and info pages  (Read 2173 times)

Offline Jason W

  • Administrator
  • Hero Member
  • *****
  • Posts: 9730
Script to compress man and info pages
« on: November 04, 2010, 05:22:31 PM »
Run this script in a directory with extensions that need their man pages compressed.  Can choose from gzip or bzip2 format by altering the variable near the top. 

Code: [Select]
#!/bin/sh
. /etc/init.d/tc-functions
PKG=tcztemp.1234567

DIR0=`pwd`

#Choose "gzip" or "bzip2"
COMP="bzip2"

for T in `ls *.tcz`; do
unset LINK MAN RUN INFO
[ -d "$PKG" ] && rm -rf "$PKG"
unsquashfs -d "$PKG" "$T" >/dev/null

for D in `find "$PKG" -type d -name info`; do
cd "$D"


#Convert hard links to symbolic links
for I in `ls`; do for F in `find . -xdev -samefile "$I" -not -name "$I"`; \
do ln -sf "$I" "$F"; done ; done
#Fix links about to be broken
        for eachpage in `find . -type l` ; do
if echo $eachpage | grep -v ".bz2$" | grep -v ".gz$" > /dev/null 2>&1; then
   if ! readlink $eachpage | grep ".bz2" >/dev/null && ! readlink $eachpage \
| grep ".gz" >/dev/null; then
     INFOLINK=1
    if [ "$COMP" == "gzip" ]; then 
     ln -s $(readlink $eachpage).gz $eachpage.gz
             rm $eachpage
    fi
    if [ "$COMP" == "bzip2" ]; then 
     ln -s $(readlink $eachpage).bz2 $eachpage.bz2
             rm $eachpage
    fi
   
   fi
   
  fi

        done

 if ls *.info* > /dev/null 2>&1; then
  for I in `ls *.info*`; do
     if file "$I" | grep -v "symbolic link" > /dev/null; then
       INFO=1
       if [ "$COMP" == "gzip" ]; then
          gzip -9 "$I"
       fi
       if [ "$COMP" == "bzip2" ]; then
          bzip2 -9 "$I"
       fi
        if [ ! "$RUN1" == "1" ]; then
  echo "${BLUE}"$T":  ${YELLOW}Compressing info pages..${NORMAL}"
  RUN1=1
        fi
     fi
 
  done
 fi
 cd "$DIR0"

done


for D in `find "$PKG" -type d -name man`; do
   cd "$D"
    for manpagedir in `find . -type d -name "man*"` ; do
DIR1=`pwd`
        cd $manpagedir

#Convert hard links to symbolic
for I in `ls`; do for F in `find . -xdev -samefile "$I" -not -name "$I"`; \
do ln -sf "$I" "$F"; done ; done


#Fix links about to be broken
        for eachpage in `find . -type l` ; do
if echo $eachpage | grep -v ".bz2$" | grep -v ".gz$" > /dev/null 2>&1; then
   if ! readlink $eachpage | grep ".bz2" >/dev/null && ! readlink $eachpage \
| grep ".gz" >/dev/null; then
     LINK=1
    if [ "$COMP" == "gzip" ]; then 
     ln -s $(readlink $eachpage).gz $eachpage.gz
             rm $eachpage
    fi
    if [ "$COMP" == "bzip2" ]; then 
     ln -s $(readlink $eachpage).bz2 $eachpage.bz2
             rm $eachpage
    fi
   
   fi
   
  fi
if [ "$LINK" == "1" ] && [ ! "$RUN" == "1" ]; then
echo "${BLUE}"$T":  ${YELLOW}Fixing manpage symlinks..${NORMAL}"
RUN=1
fi
        done

#Compress man pages
        for I in `ls`; do
     if file "$I" | grep -v "symbolic link" | grep "text" > /dev/null; then
     MAN=1
       if [ "$COMP" == "gzip" ]; then
          gzip -9 "$I"
       fi
       if [ "$COMP" == "bzip2" ]; then
          bzip2 -9 "$I"
       fi

     fi
done
          if [ "$MAN" == "1" ] && [ ! "$RUN2" == "1" ]; then
echo "${BLUE}"$T":  ${YELLOW}Compressing manpages..${NORMAL}"
RUN2=1
          fi
        cd "$DIR1"
    done
  cd "$DIR0"
done
 

cd "$DIR0"
if [ "$LINK" == "1" ] || [ "$MAN" == "1" ] || [ "$INFO" == "1" ]; then
 echo "${BLUE}"$T": ${YELLOW}Repacking with compressed man pages..${NORMAL}"
 sleep 1
 cd "$PKG"
 find `ls` -not -type d > ../"$T".list
 cd ..
 mksquashfs "$PKG" "$T" -noappend > /dev/null 2>&1
 md5sum "$T" > "$T".md5.txt
 cd "$DIR0"
else
 echo "${BLUE}"$T":  ${GREEN}No uncompressed man pages to deal with.${NORMAL}"
 sleep 1
fi
rm -rf "$PKG"

done