]> git.donarmstrong.com Git - debhelper.git/blob - dh_compress
r86: 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 # Returns a list of all the files that we want to compress,
10 # (ignoring any files we were asked to exclude on the command
11 # line). Assummes we are already in the temp directory.
12 filelist () {
13         if [ "$compress" ]; then
14                 # The config file is a sh script that outputs the files to be compressed
15                 # (typically using find).
16                 sh $olddir/$compress 2>/dev/null
17         else
18                 # By default fall back on what the policy manual says to compress.
19                 find usr/info usr/man usr/X11*/man -type f ! -name "*.gz" 2>/dev/null || true
20                 find usr/doc -type f \( -size +4k -or -name "changelog*" \) \
21                         ! -name "*.htm*" ! -name "*.gif" ! -name "*.gz" \
22                         ! -name "copyright" 2>/dev/null || true
23         fi
24 }
25
26 # Returns a list of all the files we want to compress,
27 # after taking command line exclusions into account.
28 # Call only if DH_EXCLUDE_GREP is non-empty.
29 filelist_excluded () {
30         # Use grep -F so we don't have to worry about regexp's.
31         filelist | grep -v -F \
32                 "`echo "$DH_EXCLUDE_GREP" | tr "|" "\n"`"
33 }
34
35 for PACKAGE in $DH_DOPACKAGES; do
36         TMP=`tmpdir $PACKAGE`
37         compress=`pkgfile $PACKAGE compress`
38
39         # Run the file name gathering commands from within the directory
40         # structure that will be effected.
41         olddir=`pwd`
42         # Can't use doit here, that breaks --no-act mode.
43         verbose_echo "cd $TMP"
44         cd "$TMP"
45
46         # Get the list of files to compress.
47         if [ "$DH_EXCLUDE_GREP" ]; then
48                 files=`filelist_excluded`
49         else
50                 files=`filelist`
51         fi
52
53         if [ "$files" ]; then
54                 # This is just a cosmetic fix.
55                 files=`echo $files | tr "\n" " "`
56         
57                 doit "gzip -f9 $files" || true
58         fi
59
60         # Change back to old pwd.
61         verbose_echo "cd $olddir"
62         cd "$olddir"
63
64         # Fix up symlinks that were pointing to the uncompressed files.
65         for file in `find $TMP -type l`; do
66                 DIRECTORY=`expr $file : "\(.*\)/[^/]*"`
67                 NAME=`expr $file : ".*/\([^/]*\)"`
68                 LINKVAL=`ls -l $DIRECTORY/$NAME | awk '{ print $11;}'`
69                 if [ ! -e $DIRECTORY/$LINKVAL -a -f $DIRECTORY/$LINKVAL.gz ]; then
70                         doit "rm $DIRECTORY/$NAME"
71                         doit "ln -s $LINKVAL.gz $DIRECTORY/$NAME.gz"
72                 fi
73         done
74 done