Bug#543512: update-fonts-alias should skip removed fonts
On Wed, Sep 02, 2009 at 02:42:08PM -0400, Joey Hess wrote:
> Theppitak Karoonboonyanan wrote:
> > + push @alias_postinst, "\tsed -i \'\\\\\\\\,/etc/X11/fonts/$f/$package.alias,d\' $alias_exclude";
> > + push @alias_postrm, "\tsed -i \'\\\\\\\\,/etc/X11/fonts/$f/$package.alias,d\' $alias_exclude";
>
> I have a rule of thumb: When you have to put more than two backslashes
> in a row in your code, you're doing something wrong.
Indeed.
> My first suggestion would be that update-fonts-alias be passed
> the file to exclude and handle whatever bookkeeping (exclude list or
> whatever) it needs to, instead of requiring maintainer scripts sed it
> and get it right. That seems the most maintainable.
>
> Alternatively, putting this code in the autoscript file itself,
> and just substituting in the name of the alias file, should eliminate
> much of the obvious ugliness.
The latter choice would be too complicated if the font package ships more
than one alias file. So, I take the former.
debhelper patch looks cleaner, and I hope the added options are OK for
xfonts-utils.
Regards,
--
Theppitak Karoonboonyanan
http://linux.thai.net/~thep/
Index: debhelper-7.4.0+nmu1/dh_installxfonts
===================================================================
--- debhelper-7.4.0+nmu1.orig/dh_installxfonts 2009-09-02 18:50:35.000000000 +0700
+++ debhelper-7.4.0+nmu1/dh_installxfonts 2009-09-05 10:30:29.000000000 +0700
@@ -61,19 +61,23 @@
# Figure out what commands the postinst and postrm will need
# to call.
my @cmds;
+ my @cmds_postinst;
+ my @cmds_postrm;
foreach my $f (@fontdirs) {
# This must come before update-fonts-dir.
push @cmds, "update-fonts-scale $f"
if -f "$tmp/etc/X11/fonts/$f/$package.scale";
push @cmds, "update-fonts-dir --x11r7-layout $f";
- push @cmds, "update-fonts-alias $f"
- if -f "$tmp/etc/X11/fonts/$f/$package.alias";
+ if (-f "$tmp/etc/X11/fonts/$f/$package.alias") {
+ push @cmds_postinst, "update-fonts-alias --include /etc/X11/fonts/$f/$package.alias $f";
+ push @cmds_postrm, "update-fonts-alias --exclude /etc/X11/fonts/$f/$package.alias $f";
+ }
}
autoscript($package, "postinst", "postinst-xfonts",
- "s:#CMDS#:".join(";", @cmds).":;");
+ "s:#CMDS#:".join(";", @cmds).";".join(";", @cmds_postinst).":;");
autoscript($package, "postrm", "postrm-xfonts",
- "s:#CMDS#:".join(";", @cmds).":;");
+ "s:#CMDS#:".join(";", @cmds).";".join(";", @cmds_postrm).":;");
addsubstvar($package, "misc:Depends", "xfonts-utils");
}
Index: xfonts-utils-7.4+2.1/debian/local/update-fonts-alias
===================================================================
--- xfonts-utils-7.4+2.1.orig/debian/local/update-fonts-alias 2009-09-02 22:11:23.000000000 +0700
+++ xfonts-utils-7.4+2.1/debian/local/update-fonts-alias 2009-09-05 10:09:11.000000000 +0700
@@ -43,7 +43,7 @@
message "usage error: $*"
fi
cat <<EOF
-Usage: $PROGNAME DIRECTORY ...
+Usage: $PROGNAME [OPTIONS] DIRECTORY ...
$PROGNAME { -h | --help }
This program combines X font alias information from several packages into a
single file that is placed in each specified X font directory DIRECTORY. This
@@ -51,35 +51,68 @@
update-fonts-alias(8) for more information.
Options:
-h, --help display this usage message and exit
+ -i, --include ALIAS-FILE drop ALIAS-FILE from exlude list if any
+ -x, --exclude ALIAS-FILE add ALIAS-FILE to exclude list
EOF
}
X11R7_LAYOUT=
-
-# Validate arguments.
-case "$1" in
- -h|--help)
- usage
- exit 0
- ;;
- -7|--x11r7-layout)
- X11R7_LAYOUT=true
- shift
- ;;
-esac
-
-case "$1" in
- -*)
- usage "unrecognized option" >&2
- exit 2
- ;;
-esac
+INCLUDE_ALIAS=
+EXCLUDE_ALIAS=
+EXCLUDE_CONF=/etc/fonts/excluded-aliases
+
+# Validate options.
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -7|--x11r7-layout)
+ X11R7_LAYOUT=true
+ shift
+ ;;
+ -i|--include)
+ if [ $# -lt 2 ]; then
+ usage "alias file to include is missing" >&2
+ exit 2
+ fi
+ INCLUDE_ALIAS="$INCLUDE_ALIAS $2"
+ shift 2
+ ;;
+ -x|--exclude)
+ if [ $# -lt 2 ]; then
+ usage "alias file to exclude is missing" >&2
+ exit 2
+ fi
+ EXCLUDE_ALIAS="$EXCLUDE_ALIAS $2"
+ shift 2
+ ;;
+ -*)
+ usage "unrecognized option" >&2
+ exit 2
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
if [ $# -eq 0 ]; then
usage "one or more font directories must be specified" >&2
exit 2
fi
+# Remove aliases to be included from exclude list
+for f in $INCLUDE_ALIAS; do
+ sed -i "\\,$f,d" $EXCLUDE_CONF
+done
+# Add aliases to be excluded to exclude list
+for f in $EXCLUDE_ALIAS; do
+ sed -i "\\,$f,d" $EXCLUDE_CONF
+ echo "$f" >> $EXCLUDE_CONF
+done
+
while [ -n "$1" ]; do
# Try to be clever about the argument; were we given an absolute path?
if expr "$1" : "/.*" >/dev/null 2>&1; then
@@ -129,30 +162,33 @@
continue
fi
- # Are there any files to process?
- if [ "$(echo "$ETCDIR"/*.alias "$ETC7DIR"/*.alias)" != "$ETCDIR/*.alias $ETC7DIR/*.alias" ]
- then
- if [ -n "$X11R7DIR" ] && [ -d "$X11R7DIR" ]; then
- # Write the new alias file in a temporary location in case we are
- # interrupted.
- cat >"$X11R7DIR/fonts.alias.update-new" <<EOF
+ if [ -n "$X11R7DIR" ] && [ -d "$X11R7DIR" ]; then
+ # Write the new alias file in a temporary location in case we are
+ # interrupted.
+ cat >"$X11R7DIR/fonts.alias.update-new" <<EOF
!! fonts.alias -- automatically generated file. DO NOT EDIT.
!! To modify, see update-fonts-alias(8).
EOF
- for FILE in "$ETCDIR"/*.alias "$ETC7DIR"/*.alias; do
- [ -e "$FILE" ] || continue
- echo "!! $FILE" >>"$X11R7DIR/fonts.alias.update-new"
- cat "$FILE" >>"$X11R7DIR/fonts.alias.update-new"
- done
- mv "$X11R7DIR/fonts.alias.update-new" "$X11R7DIR/fonts.alias"
- fi
- else
- if [ -n "$X11R7DIR" ] && [ -d "$X11R7DIR" ]; then
- # There are no files to process; remove any alias file already in
- # the font directory.
- rm -f "$X11R7DIR/fonts.alias"
- # Remove the font directory if it is empty.
- rmdir "$X11R7DIR" >/dev/null 2>&1 || true
+ has_data=0
+ for FILE in "$ETCDIR"/*.alias "$ETC7DIR"/*.alias; do
+ [ -e "$FILE" ] || continue
+
+ # Skip excluded aliases
+ grep -v '^!!' /etc/fonts/excluded-aliases | grep $FILE >/dev/null 2>&1 && continue
+
+ echo "!! $FILE" >>"$X11R7DIR/fonts.alias.update-new"
+ cat "$FILE" >>"$X11R7DIR/fonts.alias.update-new"
+ has_data=1
+ done
+ if [ $has_data -eq 1 ]; then
+ mv "$X11R7DIR/fonts.alias.update-new" "$X11R7DIR/fonts.alias"
+ else
+ rm -f "$X11R7DIR/fonts.alias.update-new"
+ # There are no files to process; remove any alias file already in
+ # the font directory.
+ rm -f "$X11R7DIR/fonts.alias"
+ # Remove the font directory if it is empty.
+ rmdir "$X11R7DIR" >/dev/null 2>&1 || true
fi
fi
done
Index: xfonts-utils-7.4+2.1/debian/local/excluded-aliases
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ xfonts-utils-7.4+2.1/debian/local/excluded-aliases 2009-09-02 22:17:50.000000000 +0700
@@ -0,0 +1 @@
+!! Excluded alias files to be ignored by update-fonts-alias(8)
Index: xfonts-utils-7.4+2.1/debian/xfonts-utils.install
===================================================================
--- xfonts-utils-7.4+2.1.orig/debian/xfonts-utils.install 2009-09-02 22:14:08.000000000 +0700
+++ xfonts-utils-7.4+2.1/debian/xfonts-utils.install 2009-09-02 22:17:03.000000000 +0700
@@ -10,6 +10,7 @@
usr/share/man/man1/ucs2any.1
usr/share/aclocal/fontutil.m4
usr/lib/pkgconfig/fontutil.pc
+../local/excluded-aliases etc/fonts
../local/update-fonts-alias usr/sbin
../local/update-fonts-dir usr/sbin
../local/update-fonts-scale usr/sbin
Reply to: