better config file handling
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2012 02:14:08 +0000 (02:14 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2012 02:14:08 +0000 (02:14 +0000)
TODO
checkfiles
debian/lintian-overrides
debian/po/templates.pot
debian/xfonts-traditional.config
debian/xfonts-traditional.install [new file with mode: 0644]
debian/xfonts-traditional.postinst
debian/xfonts-traditional.postrm
debian/xfonts-traditional.prerm
debian/xfonts-traditional.templates
debian/xfonts-traditional.triggers

diff --git a/TODO b/TODO
index e411b3d..e69de29 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1 +0,0 @@
-Need to somehow fix up xterm to use the new font
index c3d325b..6336fda 100755 (executable)
@@ -1,56 +1,72 @@
 #!/bin/sh
 # run from the prerm and postinst
-set -e
+set -ex
 
-install=$1
+script=$1
+mode=$2
 
-check_file () {
-       dckey=$1; regexp=$2; file=$3
-
-       if ! test -f $file; then return; fi
-
-       if $install; then
-               if test -e $file.not-trad; then return; fi
-               before=misc
-               after=trad
-               newfile=$file.trad
-               oldfile=$file.not-trad
-       else
-               if ! test -e $file.not-trad; then return; fi
-               before=trad
-               after=misc
-               newfile=$file.undo-trad
-               oldfile=$file.trad
-       fi
+. /usr/share/debconf/confmodule
 
+gen_file_overwrite () {
+       before=$1; after=$2; infile=$3; outfile=$4; backupmode=$5; backup=$6
        perl -pe '
  s/^('"$regexp"'\s+)\-'$before'\-(fixed-medium-r-semicondensed)/$1-'$after'-$2/
-               ' <$file >$file
-       if cmp -s $file $newfile; then
-               rm $newfile
+               ' <$infile >$outfile.tmp
+       if cmp -s $outfile.tmp $outfile; then
+               rm $outfile.tmp
                return
        fi
-
-       db_get $dckey
-       if [ $RET != true ]; then return; fi
-
-       if $install; then
-               db_get $dckey-done || true
-               if [ $RET = true ]; then return; fi
-
-               echo "Updating $file to use traditional fixed..."
-       else
-               echo "Restoring $file with nontraditional fixed..."
-       fi
-       rm -f $oldfile
-       ln $file $oldfile
-       mv -f $newfile $file
+       echo " Updating $file ($before=>$after)..."
+       case $backupmode in
+       once)
+               if ! test -e $backup; then
+                       ln $outfile $backup
+               fi
+               ;;
+       never)
+               ;;
+       esac
+       mv -f $outfile.tmp $outfile
 
        case "$file" in
        *.alias) update-fonts-alias misc ;;
        esac
+}
+
+check_file () {
+       dckey=$1; regexp=$2; file=$3
 
-       db_set $dckey-done $install
+       if ! test -f $file; then return; fi
+
+       needundo=true
+
+       case "$script.$mode" in
+       postinst.*)
+               db_get xfonts-traditional/$dckey ||:
+               if [ $RET = true ]; then
+                       gen_file_overwrite misc trad \
+                               $file $file once $file.backup.not-trad
+                       needundo=false
+               else
+                       gen_file_overwrite misc trad \
+                               $file $file.trad never
+               fi
+               ;;
+       prerm.upgrade*)
+               needundo=false
+               ;;
+       prerm.remove*)
+               ;;
+       *)
+               echo >&2 "huh $script.mode ?"
+               exit 1
+               ;;
+       esac
+       if $needundo && test -f $file.backup.not-trad; then
+               gen_file_overwrite trad misc \
+                       $file $file $file.backup.trad
+               mv -f $file.backup.not-trad $file.old.not-trad
+       fi
        # only ever do this once, unless we've actually undone it since
 }
 
@@ -62,3 +78,4 @@ check_file reconfigure-xterm '\*VT100\.utf8Fonts\.font\:' \
 check_file remap-fixed 'fixed' \
        /etc/X11/fonts/misc/xfonts-base.alias
 
+true
index bed5102..b71f40b 100644 (file)
@@ -1 +1,3 @@
 using-first-person-in-templates xfonts-traditional/remap-fixed
+using-first-person-in-templates xfonts-traditional/reconfigure-xterm
+debconf-is-not-a-registry usr/share/xfonts-traditional/checkfiles
index a92f611..8c1b962 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: xfonts-traditional@packages.debian.org\n"
-"POT-Creation-Date: 2012-01-09 22:27+0000\n"
+"POT-Creation-Date: 2012-01-10 00:59+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -43,20 +43,59 @@ msgstr ""
 #. Type: boolean
 #. Description
 #: ../xfonts-traditional.templates:2001
-msgid "Configure system to use traditional \"fixed\"?"
+msgid "Configure xterm to use traditional font?"
 msgstr ""
 
 #. Type: boolean
 #. Description
 #: ../xfonts-traditional.templates:2001
 msgid ""
-"You can have the font alias \"fixed\" remapped to the traditional version."
+"You can have the xterm default UTF-8 font changed to the traditional  "
+"version."
 msgstr ""
 
 #. Type: boolean
 #. Description
 #: ../xfonts-traditional.templates:2001
 msgid ""
+"If you approve, I will edit /etc/X11/app-default/XTerm for you, and save "
+"your old file as XTerm.not-trad.  (Note that this is a conffile so you may "
+"get prompts from dpkg about it in the future.)"
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../xfonts-traditional.templates:2001
+msgid ""
+"Alternatively, if you do not want me to change the default, I will generate "
+"XTerm.trad for you to do what you like with."
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../xfonts-traditional.templates:2001
+msgid ""
+"To revert the change, simply change the key \"*VT100.utf8Fonts.font\" back "
+"from \"-trad-...\"  to \"-misc-...\", or rename the old file back into place."
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../xfonts-traditional.templates:3001
+msgid "Configure system to use traditional \"fixed\"?"
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../xfonts-traditional.templates:3001
+msgid ""
+"You can have the font alias \"fixed\" remapped to the traditional version."
+msgstr ""
+
+#. Type: boolean
+#. Description
+#: ../xfonts-traditional.templates:3001
+msgid ""
 "If you approve, I will edit /etc/X11/fonts/misc/xfonts-base.alias for you, "
 "and save your old file as xfonts-base.alias.not-trad.  (Note that this is a "
 "conffile so you may get prompts from dpkg about it in the future.)  This "
@@ -65,7 +104,7 @@ msgstr ""
 
 #. Type: boolean
 #. Description
-#: ../xfonts-traditional.templates:2001
+#: ../xfonts-traditional.templates:3001
 msgid ""
 "Alternatively, if you do not want me to change the default, I will generate "
 "xfonts-base-alias.trad for you to do what you like with."
@@ -73,7 +112,7 @@ msgstr ""
 
 #. Type: boolean
 #. Description
-#: ../xfonts-traditional.templates:2001
+#: ../xfonts-traditional.templates:3001
 msgid ""
 "To revert the change to the default, simply change the alias fixed back from "
 "\"-trad-...\"  to \"-misc-...\", or rename the old file back into place."
index fe81215..be18cee 100755 (executable)
@@ -2,5 +2,9 @@
 set -e
 . /usr/share/debconf/confmodule
 db_input low xfonts-traditional/generate || true
-db_input high xfonts-traditional/remap-fixed || true
+db_get xfonts-traditional/generate || true
+if [ $RET != false ]; then
+       db_input high xfonts-traditional/reconfigure-xterm || true
+       db_input high xfonts-traditional/remap-fixed || true
+fi
 db_go || true
diff --git a/debian/xfonts-traditional.install b/debian/xfonts-traditional.install
new file mode 100644 (file)
index 0000000..9d95963
--- /dev/null
@@ -0,0 +1 @@
+checkfiles usr/share/xfonts-traditional
index 6ee2e43..f5848e2 100755 (executable)
@@ -5,37 +5,12 @@ set -e
 
 #DEBHELPER#
 
-aliasfile=/etc/X11/fonts/misc/xfonts-base.alias
-
-check_aliasfile () {
-       if ! test -f $aliasfile; then return; fi
-       if test -e $aliasfile.not-trad; then return; fi
-
-       perl -pe '
- s/^(fixed\s+)\-misc\-(fixed-medium-r-semicondensed)/$1-trad-$2/
-               ' <$aliasfile >$aliasfile.trad
-       if cmp -s $aliasfile $aliasfile.trad; then
-               rm $aliasfile.trad
-               return
-       fi
-       db_get xfonts-traditional/remap-fixed
-       if [ $RET != true ]; then return; fi
-
-       echo 'Installing traditional variant of "fixed"...'
-       ln $aliasfile $aliasfile.not-trad
-       mv -f $aliasfile.trad $aliasfile
-
-       update-fonts-alias misc
-
-       db_set xfonts-traditional/remap-fixed false
-       # only ever do this once
-}
-
 db_get xfonts-traditional/generate
 if [ "$RET" = true ]; then
 
+       echo Generating fonts...
        update-xfonts-traditional --update
 
-       check_aliasfile
-
 fi
+
+/usr/share/xfonts-traditional/checkfiles postinst "$@"
index e9972f3..ac4c5c6 100755 (executable)
@@ -7,6 +7,12 @@ aliasfile=/etc/X11/fonts/misc/xfonts-base.alias
 
 case "$1" in
 purge)
-       rm -f $aliasfile.trad
+       for file in     /etc/X11/app-defaults/XTerm \
+                       /etc/X11/fonts/misc/xfonts-base.alias; do
+               rm -f $file.tmp
+               for f in $file.trad $file.old.not-trad $file.backup.trad;
+                       do rm -f $f $f.tmp
+               done
+       done
        ;;
 esac
index 35f8eda..53687d7 100755 (executable)
@@ -5,7 +5,7 @@ set -e
 
 #DEBHELPER#
 
-aliasfile=/etc/X11/fonts/misc/xfonts-base.alias
+/usr/share/xfonts-traditional/checkfiles prerm "$@"
 
 case "$1" in
 
@@ -13,17 +13,18 @@ remove)
 
        echo 'Checking that "fixed" is not from xfonts-traditional...'
 
-       if grep '^fixed[         ][      ]*-trad-' $aliasfile \
-           /usr/share/fonts/X11/misc/fonts.alias; then
+       if grep '^fixed[         ][      ]*-trad-' \
+                       /etc/X11/fonts/misc/xfonts-base.alias \
+                       /usr/share/fonts/X11/misc/fonts.alias; then
                cat >&2 <<'END'
 
 Removing xfonts-traditional would break your X server by removing "fixed".
 
 You should not remove xfonts-traditional while "fixed" refers to one
-of its fonts.  You probably want to check the differences between
-/etc/X11/fonts/misc/xfonts-base.alias and xfonts-base.alias.not-trad,
-reconcile any changes, and then run "update-fonts-alias misc".
-After that you can retry the removal.
+of its fonts.  You probably want to check the differences between the
+various /etc/X11/fonts/misc/xfonts-base.alias*, reconcile any changes,
+and then run "update-fonts-alias misc".  After that you can retry the
+removal.
 
 END
                printf 'Continue anyway ? [n/y] '
index ab18479..81046f3 100644 (file)
@@ -10,6 +10,24 @@ _Description: Generate traditional versions of fonts?
  But you may prefer not to do this automatically, and would rather
  just have the tool installed.
 
+Template: xfonts-traditional/reconfigure-xterm
+Type: boolean
+Default: false
+_Description: Configure xterm to use traditional font?
+ You can have the xterm default UTF-8 font changed to the traditional 
+ version.
+ .
+ If you approve, I will edit /etc/X11/app-default/XTerm for you, and
+ save your old file as XTerm.not-trad.  (Note that this is a conffile
+ so you may get prompts from dpkg about it in the future.)
+ .
+ Alternatively, if you do not want me to change the default, I will
+ generate XTerm.trad for you to do what you like with.
+ .
+ To revert the change, simply change the key "*VT100.utf8Fonts.font"
+ back from "-trad-..."  to "-misc-...", or rename the old file back
+ into place.
+
 Template: xfonts-traditional/remap-fixed
 Type: boolean
 Default: false
index 19b49cc..e510724 100644 (file)
@@ -1 +1,3 @@
 interest /usr/share/fonts/X11
+interest /etc/X11/app-defaults/XTerm
+interest /etc/X11/fonts/misc/xfonts-base.alias