:: [DNG] A suggestion for devuan-basec…
Top Pagina
Delete this message
Reply to this message
Auteur: Rainer Weikusat
Datum:  
Aan: dng
Onderwerp: [DNG] A suggestion for devuan-baseconf postinst building code
This presently doesn't work on Debian wheezy because the corresponding
dpkg-parsechangelog doesn't support -S. Using sed to extract this field,
as in

DSUITE=$(shell dpkg-parsechangelog | sed -n 's/^Distribution: \(.*\)/\1/p')

would be more portable. Further, the postinst building code is "oneshot
only" because after the first run, the source files (which is also the
destination file) doesn't contain the suite placeholder anymore. This
could be avoided by using a different name for the source file and
generate the postinst from that.

Patch which changes this
-------------------------
diff --git a/debian/postinst b/debian/postinst
deleted file mode 100644
index 5a64759..0000000
--- a/debian/postinst
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/bin/sh
-
-# This script will make a best-effort attempt at guessing the needed suite and
-# dist values, falling back to sane defaults should the attempt fail.
-# No changes will be made if the file already exists.
-
-set -e
-
-case "$1" in
-    configure)
-
-    # Assign default values.
-    suite="__DSUITE__"
-    dists="main"
-    devuan="no"
-
-    if [ -f /etc/apt/sources.list ] ; then
-       detected="no"
-       # detect if devuan repository is already there
-       if grep -q '^[^#]*'packages.devuan.org/merged /etc/apt/sources.list ; then
-          devuan="yes"
-       fi
-
-       # try to guess suite
-       for s in stable jessie ascii testing sid unstable ; do
-          if grep -q '^[^#]*'$s /etc/apt/sources.list ; then
-             detected=$s
-          fi
-       done
-       case "$detected" in
-          stable|jessie)
-             suite="jessie"
-             ;;
-          testing|ascii)
-             suite="ascii"
-             ;;
-          sid|unstable)
-             suite="ceres"
-             ;;
-          *)
-             suite="__DSUITE__"
-       esac
-
-       # guess components
-       for dist in contrib non-free; do
-         if grep -q '^[^#]* '$dist /etc/apt/sources.list; then
-            dists="$dists $dist"
-         fi
-      done
-    fi
-    
-    devrep="no"
-    if [ -f /etc/apt/sources.lists.d/devuan.list ] ; then
-       if grep -q "# autogenerated by devuan-baseconf" /etc/apt/sources.lists.d/devuan.list ; then
-          devrep="yes"
-       fi
-    fi
-    if [ x"$devrep" = x"no" ] ; then
-       echo "# autogenerated by devuan-baseconf" > /etc/apt/sources.list.d/devuan.list
-       echo "# decomment following lines to  enable the developers devuan repository" >> /etc/apt/sources.list.d/devuan.list
-       echo "#deb http://packages.devuan.org/devuan $suite $dists" >> /etc/apt/sources.list.d/devuan.list
-       echo "#deb-src http://packages.devuan.org/devuan $suite $dists" >> /etc/apt/sources.list.d/devuan.list
-    fi
-
-    if [ x"$devuan" = x"no" ] ; then
-    
-       # Source debconf library.
-       . /usr/share/debconf/confmodule
-       
-       # db_unregister devuan-baseconf/suite
-
-       tmpl="/tmp/devuan-baseconf.template.$$"
-       cat > $tmpl << EOF
-Template: devuan-baseconf/suite
-Type: string
-Description: Choose a suite for devuan
-
-Template: devuan-baseconf/components
-Type: string
-Description: Choose component(s) for devuan
-
-Template: devuan-baseconf/note
-Type: note
-Description: Enabling Devuan
- Please remove any debian repository from sources.list to avoid package conflicts
- After that, perform apt-get update && apt-get install devuan-keyring.
- Live long and prosper.
-
-EOF
-
-       db_x_loadtemplatefile $tmpl devuan-baseconf
-       db_title "Devuan suite"
-       #db_fset devuan-baseconf/suite seen false
-       db_set devuan-baseconf/suite "$suite" 
-       db_input high devuan-baseconf/suite || true
-       db_go || true
-       db_get devuan-baseconf/suite
-       suite=$RET
-
-       db_title "Devuan component(s)"
-       #db_fset devuan-baseconf/components seen false
-       db_set devuan-baseconf/components "$dists" 
-       db_input high devuan-baseconf/components || true
-       db_go || true
-       db_get devuan-baseconf/components
-       dists=$RET
-
-       echo >> /etc/apt/sources.list
-       echo "# Devuan repositories" >> /etc/apt/sources.list
-       echo "deb http://packages.devuan.org/merged $suite $dists" >> /etc/apt/sources.list
-       echo "deb-src http://packages.devuan.org/merged $suite $dists" >> /etc/apt/sources.list
-
-       db_title "Enabling Devuan" 
-       db_input high devuan-baseconf/note || true
-       db_go || true
-      
-       rm -f $tmpl
-
-    fi
-    ;;
-
-    abort-upgrade|abort-remove|abort-deconfigure)
-    ;;
-
-    *)
-        echo "postinst called with unknown argument \`$1'" >&2
-        exit 1
-    ;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/postinst.in b/debian/postinst.in
new file mode 100644
index 0000000..5a64759
--- /dev/null
+++ b/debian/postinst.in
@@ -0,0 +1,133 @@
+#!/bin/sh
+
+# This script will make a best-effort attempt at guessing the needed suite and
+# dist values, falling back to sane defaults should the attempt fail.
+# No changes will be made if the file already exists.
+
+set -e
+
+case "$1" in
+    configure)
+
+    # Assign default values.
+    suite="__DSUITE__"
+    dists="main"
+    devuan="no"
+
+    if [ -f /etc/apt/sources.list ] ; then
+       detected="no"
+       # detect if devuan repository is already there
+       if grep -q '^[^#]*'packages.devuan.org/merged /etc/apt/sources.list ; then
+          devuan="yes"
+       fi
+
+       # try to guess suite
+       for s in stable jessie ascii testing sid unstable ; do
+          if grep -q '^[^#]*'$s /etc/apt/sources.list ; then
+             detected=$s
+          fi
+       done
+       case "$detected" in
+          stable|jessie)
+             suite="jessie"
+             ;;
+          testing|ascii)
+             suite="ascii"
+             ;;
+          sid|unstable)
+             suite="ceres"
+             ;;
+          *)
+             suite="__DSUITE__"
+       esac
+
+       # guess components
+       for dist in contrib non-free; do
+         if grep -q '^[^#]* '$dist /etc/apt/sources.list; then
+            dists="$dists $dist"
+         fi
+      done
+    fi
+    
+    devrep="no"
+    if [ -f /etc/apt/sources.lists.d/devuan.list ] ; then
+       if grep -q "# autogenerated by devuan-baseconf" /etc/apt/sources.lists.d/devuan.list ; then
+          devrep="yes"
+       fi
+    fi
+    if [ x"$devrep" = x"no" ] ; then
+       echo "# autogenerated by devuan-baseconf" > /etc/apt/sources.list.d/devuan.list
+       echo "# decomment following lines to  enable the developers devuan repository" >> /etc/apt/sources.list.d/devuan.list
+       echo "#deb http://packages.devuan.org/devuan $suite $dists" >> /etc/apt/sources.list.d/devuan.list
+       echo "#deb-src http://packages.devuan.org/devuan $suite $dists" >> /etc/apt/sources.list.d/devuan.list
+    fi
+
+    if [ x"$devuan" = x"no" ] ; then
+    
+       # Source debconf library.
+       . /usr/share/debconf/confmodule
+       
+       # db_unregister devuan-baseconf/suite
+
+       tmpl="/tmp/devuan-baseconf.template.$$"
+       cat > $tmpl << EOF
+Template: devuan-baseconf/suite
+Type: string
+Description: Choose a suite for devuan
+
+Template: devuan-baseconf/components
+Type: string
+Description: Choose component(s) for devuan
+
+Template: devuan-baseconf/note
+Type: note
+Description: Enabling Devuan
+ Please remove any debian repository from sources.list to avoid package conflicts
+ After that, perform apt-get update && apt-get install devuan-keyring.
+ Live long and prosper.
+
+EOF
+
+       db_x_loadtemplatefile $tmpl devuan-baseconf
+       db_title "Devuan suite"
+       #db_fset devuan-baseconf/suite seen false
+       db_set devuan-baseconf/suite "$suite" 
+       db_input high devuan-baseconf/suite || true
+       db_go || true
+       db_get devuan-baseconf/suite
+       suite=$RET
+
+       db_title "Devuan component(s)"
+       #db_fset devuan-baseconf/components seen false
+       db_set devuan-baseconf/components "$dists" 
+       db_input high devuan-baseconf/components || true
+       db_go || true
+       db_get devuan-baseconf/components
+       dists=$RET
+
+       echo >> /etc/apt/sources.list
+       echo "# Devuan repositories" >> /etc/apt/sources.list
+       echo "deb http://packages.devuan.org/merged $suite $dists" >> /etc/apt/sources.list
+       echo "deb-src http://packages.devuan.org/merged $suite $dists" >> /etc/apt/sources.list
+
+       db_title "Enabling Devuan" 
+       db_input high devuan-baseconf/note || true
+       db_go || true
+      
+       rm -f $tmpl
+
+    fi
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+    ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/rules b/debian/rules
index 5fadb14..cc8a10e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -2,7 +2,7 @@
 # See debhelper(7) (uncomment to enable)
 # output every command that modifies files on the build system.
 #DH_VERBOSE = 1
-DSUITE=$(shell dpkg-parsechangelog -S Distribution)
+DSUITE=$(shell dpkg-parsechangelog | sed -n 's/^Distribution: \(.*\)/\1/p')



 # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
@@ -30,8 +30,5 @@ include /usr/share/dpkg/default.mk
 #    -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)


 override_dh_auto_build:
-    sed "s/__DSUITE__/${DSUITE}/" debian/postinst > debian/postinst.tmp
-    mv debian/postinst.tmp debian/postinst
+    sed "s/__DSUITE__/${DSUITE}/" debian/postinst.in > debian/postinst
     dh_auto_build
-
-