home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / var / lib / dpkg / info / popularity-contest.postinst < prev    next >
Encoding:
Text File  |  2006-05-11  |  3.1 KB  |  114 lines

  1. #!/bin/sh
  2.  
  3. # Load debconf variables
  4. . /usr/share/debconf/confmodule
  5.  
  6. conffile=/etc/popularity-contest.conf
  7.  
  8. set -e
  9.  
  10. if [ -e $conffile ] ; then
  11.     # Fetch current values.
  12.     . $conffile
  13. fi
  14.  
  15. # Get this setting from debconf.  It was set based on the content of
  16. # /etc/popularity-contest.conf in the 'config' script, so it should be
  17. # safe to ignore the value fetched by loading the file above.  This
  18. # should allow for using debconf to reconfigure the package.
  19. db_get popularity-contest/participate || true
  20. if [ "$RET" = "yes" ] || [ "$RET" = "YES" ] || [ "$RET" = "true" ]; then
  21.     PARTICIPATE="yes"
  22. else
  23.     PARTICIPATE="no"
  24. fi
  25. db_get popularity-contest/use-http || true
  26. if [ "$RET" = "yes" ] || [ "$RET" = "YES" ] || [ "$RET" = "true" ]; then
  27.     USEHTTP="yes"
  28. else
  29.     USEHTTP="no"
  30. fi
  31.  
  32. # The md5 sum of an empty file
  33. EMPTYID="d41d8cd98f00b204e9800998ecf8427e"
  34.  
  35. generate_id() {
  36.         if [ -x /usr/bin/uuidgen ] ; then
  37.                 MY_HOSTID=`uuidgen | tr -d -`
  38.         else
  39.             MY_HOSTID=`dd if=/dev/urandom bs=1k count=1 2>/dev/null | md5sum | sed 's/  -//'''`
  40.         fi
  41. }
  42.  
  43. generate_conffile() {
  44.         generate_id
  45.     cat <<-EOF >$conffile
  46.         # Config file for Debian's popularity-contest package.
  47.         #
  48.         # To change this file, use:
  49.         #        dpkg-reconfigure popularity-contest
  50.         #
  51.         # You can also edit it by hand, if you so choose.
  52.         #
  53.         # See /usr/share/popularity-contest/default.conf for more info
  54.         # on the options.
  55.         
  56.         MY_HOSTID="$MY_HOSTID"
  57.         PARTICIPATE="$PARTICIPATE"
  58.         USEHTTP="$USEHTTP"
  59.     EOF
  60.     # Make sure user nobody can read the file.
  61.     chmod a+r $conffile
  62. }
  63.  
  64. case "$1" in
  65.     configure)
  66.     if [ ! -e $conffile ]; then
  67.         generate_conffile
  68.     else
  69.             OLDHOSTID="$MY_HOSTID";
  70.             case $MY_HOSTID in
  71.             # Workaround for bug #237874 triggered on hurd.  The
  72.             # problem was fixed in version 1.15, 2004-03-20.
  73.  
  74.               $EMPTYID) generate_id;;
  75.             # Workaround for bug #240603 triggered by md5sums change
  76.             # of behaviour with stdin. version 1.17, 2004-04-12.
  77.               *-)  MY_HOSTID="${MY_HOSTID%  -}";;
  78.             esac;
  79.         # Replace only if the content changed, to avoid changing the
  80.         # config file date when no change was done.
  81.  
  82.         # Commenting out the obsolete addresses, to use the
  83.         # default config from /usr/share/ on hosts where
  84.         # the old default was unchanged.  Replace the "empty" id.
  85.  
  86.         sedopts=" \
  87.         s/^PARTICIPATE=.*$/PARTICIPATE=\"$PARTICIPATE\"/;   \
  88.         s/^USEHTTP=.*$/USEHTTP=\"$USEHTTP\"/;   \
  89.         s/^\(MAILTO=\"erich-survey@debian.org\"\)$/#\1/;    \
  90.         s/^\(MAILTO=\"apenwarr-survey@debian.org\"\)$/#\1/; \
  91.         s/^\(MAILTO=\"survey@popcon.debian.org\"\)$/#\1/;   \
  92.                 "
  93.             if [ "$OLDHOSTID" != "$MY_HOSTID" ]; then
  94.                 sedopts="$sedopts \
  95.                 s/^MY_HOSTID=\"\\?$OLDHOSTID\"\\?/MY_HOSTID=\"$MY_HOSTID\"/; \
  96.         "
  97.             fi
  98.  
  99.         if sed "$sedopts" < $conffile > $conffile.new &&
  100.         ! cmp $conffile $conffile.new > /dev/null; then
  101.         mv $conffile.new $conffile
  102.         # Make sure user nobody can read the file.
  103.         chmod a+r $conffile
  104.         else
  105.         rm $conffile.new
  106.         fi
  107.     fi
  108.     ;;
  109.     *)
  110.     ;;
  111. esac
  112.  
  113.  
  114.