[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

dh_installxfonts (Re: Installing an X fonts ..)



Hi,

After I read the X font not-yet policy, I wrote a simple
dh_installxfonts debhelper script which reduces the complexity of the
postinst/postrm.

Any correction will be appreciated.

-- 
Changwoo Ryu
#!/usr/bin/perl -w
#
# Integration with the Debian X11 font policy.

BEGIN { push @INC, "debian", "/usr/share/debhelper" }
use Dh_Lib;
init();

foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
    $TMP=tmpdir($PACKAGE);

    opendir DIR, "$TMP/usr/X11R6/lib/X11/fonts/" || next;
    @fontdirs = readdir DIR;
    closedir DIR;

    next if ($#fontdirs == 0);

    undef $fontdirs_str;
    undef $use_alias;
    undef $use_scale;

    foreach $f (@fontdirs) {
	unless ($f =~ /^\./) {
	    $fontdirs_str .= " " if $fontdirs_str;
	    $fontdirs_str .= $f;

	    if (-f "$TMP/etc/X11/fonts/$f/$PACKAGE.alias") {
		$use_alias = 1;
	    }
	    if (-f "$TMP/etc/X11/fonts/$f/$PACKAGE.scale") {
		$use_scale = 1;
	    }
	}
    }

    undef $updatecmds_str;
    $updatecmds_str .= "/usr/sbin/update-fonts-scale" if $use_scale;
    $updatecmds_str .= " " if $updatecmds_str;
    $updatecmds_str .= "/usr/bin/X11/mkfontdir";
    $updatecmds_str .= " " if $updatecmds_str;
    $updatecmds_str .= "/usr/sbin/update-fonts-alias" if $use_alias;

    autoscript($PACKAGE, "postinst", "postinst-xfonts",
	       "s:#FONTDIRS#:$fontdirs_str:;s:#UPDATECMDS#:$updatecmds_str:");
    autoscript($PACKAGE, "postrm", "postrm-xfonts",
	       "s:#FONTDIRS#:$fontdirs_str:;s:#UPDATECMDS#:$updatecmds_str:");
}



fontdirs="#FONTDIRS#"
updatecmds="#UPDATECMDS#"

for currentdir in $fontdirs; do
  longdir=/usr/lib/X11/fonts/$currentdir
  if [ -e $longdir ]; then
    if [ -d $longdir ]; then
      for currentcmd in $updatecmds; do
        if [ -e $currentcmd ]; then
          if [ -x $currentcmd ]; then
            shortcmd=$(basename $currentcmd)
            echo -n "Running $shortcmd in $currentdir font directory..."
            $currentcmd $longdir
            echo "done."
          else
            echo "Warning: $currentcmd not executable."
          fi
        else
          echo "Warning: $currentcmd not found."
        fi
      done
    else
      echo "Error: $longdir is not a directory!"
      exit 1
    fi
  else
    echo "Error: $longdir does not exist!"
    exit 1
  fi
done
fontdirs="#FONTDIRS#"
updatecmds="#UPDATECMDS#"

for currentdir in $fontdirs; do
  longdir=/usr/lib/X11/fonts/$currentdir
  if [ -d $longdir ]; then
    for file in fonts.dir fonts.alias; do
      if [ -e $file ]; then
        rm $file
      fi
    done
    if [ $(find | wc -l) -eq 1 ]; then
      echo "$currentdir font directory is empty.  Removing."
      rmdir $longdir
    else
      for currentcmd in $updatecmds; do
        if [ -e $currentcmd ]; then
          if [ -x $currentcmd ]; then
            shortcmd=$(basename $currentcmd)
            echo -n "Running $shortcmd in $currentdir font directory..."
            $currentcmd $longdir
            echo "done."
          else
            echo "Warning: $currentcmd not executable."
          fi
        else
          echo "Warning: $currentcmd not found."
        fi
      done
    fi
  fi
done

Reply to: