File: postinst

package info (click to toggle)
portmap 5-26
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 264 kB
  • ctags: 111
  • sloc: ansic: 1,061; sh: 178; makefile: 100
file content (120 lines) | stat: -rw-r--r-- 3,946 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

CONFFILE=/etc/default/portmap

if [ "$1" = "configure" ] && [ -n "$2" ] &&
  dpkg --compare-versions "$2" lt 5-3; then
       err=$(update-rc.d -f portmap remove 2>&1 > /dev/null) || {
               echo "$err" >&2
               exit 1
       }
fi

if [ "$1" = "configure" ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt "5-7ubuntu2"; then
    db_set portmap/loopback true
fi

# be consistent with Debian
if [ -e "$CONFFILE" ]; then
	sed -i -e 's/ARGS/OPTIONS/g' "$CONFFILE"
else
	echo -e "# By default, listen only on the loopback interface\nOPTIONS=\"-i 127.0.0.1\"" > "$CONFFILE"
fi

# Keep track of changes to the portmapper
portmap_changed=0

if [ -e "$CONFFILE" ] && [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then

  # Read in the options
  . $CONFFILE || true

  if [ "$OPTIONS" = "-i 127.0.0.1" ] || [ -z "$OPTIONS" ] ; then
  # The configuration matches the changes we introduce, go ahead
  # and make the changes

      db_get portmap/loopback

      if [ "$RET" = true ]; then
	  # first we need to understand if there is OPTIONS somewhere
	  # and if not, add it with a sane default.
          if [ "$1" = "configure" ] && [ -n "$2" ] && ! grep -qs OPTIONS "$CONFFILE"; then
              echo "OPTIONS=\"-i 127.0.0.1\"" >> "$CONFFILE"
              portmap_changed=1
          fi
	  # if OPTION is not at the beginning, make it so
	  # XXX: only the last OPTIONS will be used, but we don't know
	  # if the user is chaining the values, so it seems to be reasonably safe.
          if ! grep -q ^OPTIONS "$CONFFILE" >/dev/null 2>&1; then
              sed -i -e 's/.*OPTIONS/OPTIONS/g' "$CONFFILE"
              portmap_changed=1
          fi
	  # source again the result
          . "$CONFFILE"
	  # check if loopback is not in the string
          if [ -z "$(echo $OPTIONS | grep "127.0.0.1")" ]; then
              OPTIONS="$OPTIONS -i 127.0.0.1"
              sed -i -e 's/OPTIONS.*/OPTIONS=\"'"$OPTIONS"'\"/g' "$CONFFILE"
              portmap_changed=1
          fi
      else
          if [ "$1" = "configure" ] && [ -n "$2" ] && ! grep -qs OPTIONS "$CONFFILE"; then
              echo "OPTIONS=\"\"" >> "$CONFFILE"
          fi
# Just reverse the change above in case a user wants to go from 'true'
# to 'false' at some point.
          OPTIONS="$(echo $OPTIONS | sed -e 's/-i 127.0.0.1//g')"
          sed -i -e 's/^OPTIONS.*/OPTIONS=\"'"$OPTIONS"'\"/g' "$CONFFILE"
          portmap_changed=1
      fi

      
  else 
      echo "Portmap options have already been configured in $CONFFILE"
      echo "This script will not modify it, please edit this file manually."
  fi
fi 

if [ ! -e "$CONFFILE" ] && [ "$1" = "reconfigure" ] ; then
	echo "Cannot reconfigure portmap since $CONFFILE has been manually removed by the admin"
fi

db_stop

# End of configuration

#DEBHELPER#

# Warn if there are services linked with the portmapper
# but its configuration has changed. We will not automatically
# restart them, however.
if [ -n "$2" ] && [ "$portmap_changed" -eq 1 ] ; then
    pid=`pidof portmap` || true
    if [ -n "$pid" ] ; then
	# RPCinfo might fail if the portmapper is not running
	# (i.e. broken options...)
	set +e
	rpccount=`rpcinfo -p 2>/dev/null |grep "tcp\|udp" | grep -v portmapper | wc -l`
	set -e
	if [ "0$rpccount" -gt 0 ] ; then
	# TODO: Turn this into a debconf note?
	# TODO: associate common RPC services with init.d lines?
	# i.e. : 
	#  sgi_fam -> /etc/init.d/fam
	#  status  -> /etc/init.d/nfs-common
		echo "There are RPC services which registered with the portmapper"
		echo "before the configuration was changed."
		echo "You need to manually restart them in order for the changes to take effect."
		echo "Current registered services:"
		echo "------------------------------------------------"
		rpcinfo -p | grep "tcp\|udp" | grep -v portmapper 
		echo "------------------------------------------------"
	fi
    fi
fi


exit 0