]> git.donarmstrong.com Git - debhelper.git/blob - dh_compress
r22: Initial Import
[debhelper.git] / dh_compress
1 #!/bin/sh -e
2 #
3 # Compresses files and makes sure that symlinks pointing to the 
4 # compressed files get fixed.
5
6 PATH=debian:$PATH:/usr/lib/debhelper
7 . dh_lib
8
9 for PACKAGE in $DH_DOPACKAGES; do
10         TMP=`tmpdir $PACKAGE`
11         EXT=`pkgext $PACKAGE`
12
13         # Run the file name gatering commands from within the directory
14         # structure that will be effected.
15         olddir=`pwd`
16         cd $TMP
17
18         if [ -f debian/${EXT}compress ]; then
19                 # The config file is a sh script that outputs the files to be compressed
20                 # (typically using find).
21                 files=`sh debian/${EXT}compress 2>/dev/null`
22         else
23                 # By default fall back on what the policy manual says to compress.
24                 files=`
25                         find usr/info usr/man usr/X11*/man -type f 2>/dev/null ;
26                         find usr/doc -type f \( -size +4k -or -name "changelog*" \) \
27                                 ! -name "*.htm*" ! -name "*.gif" \
28                                 ! -name "copyright" 2>/dev/null
29                 `
30         fi
31
32         if [ "$files" ]; then
33                 # This is just a cosmetic fix.
34                 files=`echo $files | tr "\n" " "`       
35         
36                 doit "gzip -9 $files" || true
37         fi
38
39         # Change back to old pwd.
40         cd $olddir
41
42         # Fix up symlinks that were pointing to the uncompressed files.
43         for file in `find $TMP -type l`; do
44                 DIRECTORY=`expr $file : "\(.*\)/[^/]*"`
45                 NAME=`expr $file : ".*/\([^/]*\)"`
46                 LINKVAL=`ls -l $DIRECTORY/$NAME | awk '{ print $11;}'`
47                 if [ ! -e $DIRECTORY/$LINKVAL -a -f $DIRECTORY/$LINKVAL.gz ]; then
48                         doit "rm $DIRECTORY/$NAME"
49                         doit "ln -s $LINKVAL.gz $DIRECTORY/$NAME.gz"
50                 fi
51         done
52 done