chiark / gitweb /
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 e411b3d54f9b6b7563e944844fee2ed6a980e396..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1 +0,0 @@
-Need to somehow fix up xterm to use the new font
index c3d325b3ebd46aea72e5f66f74def51da9366816..6336fdae50029728f3616e10bd89df1b9c72dbf7 100755 (executable)
@@ -1,56 +1,72 @@
 #!/bin/sh
 # run from the prerm and postinst
 #!/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/
        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
                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
 
        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
 }
 
        # 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
 
 check_file remap-fixed 'fixed' \
        /etc/X11/fonts/misc/xfonts-base.alias
 
+true
index bed510280bc462809bd9edfc17eb166b74318403..b71f40b5fda4d8b83c8ec14115710a7955df72d2 100644 (file)
@@ -1 +1,3 @@
 using-first-person-in-templates xfonts-traditional/remap-fixed
 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 a92f6119a3ffe06365560860bff4516cede1b58a..8c1b962f279ed10b77fdfbc5a5ccc6022daf69f7 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: xfonts-traditional@packages.debian.org\n"
 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"
 "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
 #. 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 ""
 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 ""
 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 "
 "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
 
 #. 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."
 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
 
 #. 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."
 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 fe81215a443bd15a8b0be22040a05822053abf88..be18ceee9d8021b3c12c2190840db406db8c3364 100755 (executable)
@@ -2,5 +2,9 @@
 set -e
 . /usr/share/debconf/confmodule
 db_input low xfonts-traditional/generate || true
 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
 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 6ee2e43220634d65f5e75bce91571ca44fd21939..f5848e26e35c1d7b272585fe7a6b3abc204f85d8 100755 (executable)
@@ -5,37 +5,12 @@ set -e
 
 #DEBHELPER#
 
 
 #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
 
 db_get xfonts-traditional/generate
 if [ "$RET" = true ]; then
 
+       echo Generating fonts...
        update-xfonts-traditional --update
 
        update-xfonts-traditional --update
 
-       check_aliasfile
-
 fi
 fi
+
+/usr/share/xfonts-traditional/checkfiles postinst "$@"
index e9972f3e9d71430c12a40ff88b7eebb2ea348946..ac4c5c64c1f0c2f1628bb09f5b8c28ff85cb4cf3 100755 (executable)
@@ -7,6 +7,12 @@ aliasfile=/etc/X11/fonts/misc/xfonts-base.alias
 
 case "$1" in
 purge)
 
 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
        ;;
 esac
index 35f8edadcb22d4731f3bfee54e65dab0401322e0..53687d7984c0298e28e44382e5c25348d3abb65e 100755 (executable)
@@ -5,7 +5,7 @@ set -e
 
 #DEBHELPER#
 
 
 #DEBHELPER#
 
-aliasfile=/etc/X11/fonts/misc/xfonts-base.alias
+/usr/share/xfonts-traditional/checkfiles prerm "$@"
 
 case "$1" in
 
 
 case "$1" in
 
@@ -13,17 +13,18 @@ remove)
 
        echo 'Checking that "fixed" is not from xfonts-traditional...'
 
 
        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
                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] '
 
 END
                printf 'Continue anyway ? [n/y] '
index ab184790c23be495558a4acb4691d21de62b5c97..81046f3ca6daa9a609a5c25f2601cfe0b4c32760 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.
 
  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
 Template: xfonts-traditional/remap-fixed
 Type: boolean
 Default: false
index 19b49cc3f8ab2c36d1bc5e36df21ca4b17ffac6c..e51072477b578e98d58c4f9478669ceb90fbe80f 100644 (file)
@@ -1 +1,3 @@
 interest /usr/share/fonts/X11
 interest /usr/share/fonts/X11
+interest /etc/X11/app-defaults/XTerm
+interest /etc/X11/fonts/misc/xfonts-base.alias