summaryrefslogtreecommitdiff
path: root/dh_compress
blob: 1b58f70a19f85a7a6cbb268f634487d3cd4e6cc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh -e
#
# Compresses files and makes sure that symlinks pointing to the 
# compressed files get fixed.

PATH=debian:$PATH:/usr/lib/debhelper
. dh_lib

# Returns a list of all the files that we want to compress,
# (ignoring any files we were asked to exclude on the command
# line). Assummes we are already in the temp directory.
filelist () {
	if [ "$compress" ]; then
		# The config file is a sh script that outputs the files to be compressed
		# (typically using find).
		sh $olddir/$compress 2>/dev/null
	else
		# By default fall back on what the policy manual says to compress.
		find usr/info usr/man usr/X11*/man -type f ! -name "*.gz" 2>/dev/null || true
		find usr/doc -type f \( -size +4k -or -name "changelog*" \) \
			! -name "*.htm*" ! -name "*.gif" ! -name "*.gz" \
			! -name "copyright" 2>/dev/null || true
	fi
}

# Returns a list of all the files we want to compress,
# after taking command line exclusions into account.
# Call only if DH_EXCLUDE_GREP is non-empty.
filelist_excluded () {
	# Use grep -F so we don't have to worry about regexp's.
	(filelist | grep -v -F \
		"`echo "$DH_EXCLUDE_GREP" | tr "|" "\n"`") || true
}

for PACKAGE in $DH_DOPACKAGES; do
	TMP=`tmpdir $PACKAGE`
	compress=`pkgfile $PACKAGE compress`

	# Run the file name gathering commands from within the directory
	# structure that will be effected.
	olddir=`pwd`
	# Can't use doit here, that breaks --no-act mode.
	verbose_echo "cd $TMP"
	cd "$TMP"

	# Get the list of files to compress.
	if [ "$DH_EXCLUDE_GREP" ]; then
		files=`filelist_excluded`
	else
		files=`filelist`
	fi

	if [ "$files" ]; then
		# This is just a cosmetic fix.
		files=`echo $files | tr "\n" " "`
	
		doit "gzip -f9 $files" || true
	fi

	# Change back to old pwd.
	verbose_echo "cd $olddir"
	cd "$olddir"

	# Fix up symlinks that were pointing to the uncompressed files.
	for file in `find $TMP -type l`; do
		DIRECTORY=`expr $file : "\(.*\)/[^/]*"`
		NAME=`expr $file : ".*/\([^/]*\)"`
		LINKVAL=`ls -l $DIRECTORY/$NAME | awk '{ print $11;}'`
		if [ ! -e $DIRECTORY/$LINKVAL -a -f $DIRECTORY/$LINKVAL.gz ]; then
			doit "rm $DIRECTORY/$NAME"
			doit "ln -s $LINKVAL.gz $DIRECTORY/$NAME.gz"
		fi
	done
done