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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/bin/sh
set -e
. /lib/lsb/init-functions
. /usr/share/debconf/confmodule
CONFFILE=/etc/default/portmap
create_config() {
cat <<EOF > $CONFFILE
# Portmap configuration file
#
# Note: if you manually edit this configuration file,
# portmap configuration scripts will avoid modifying it
# (for example, by running 'dpkg-reconfigure portmap').
# If you want portmap to listen only to the loopback
# interface, uncomment the following line (it will be
# uncommented automatically if you configure this
# through debconf).
EOF
# Allow the installation default to be preseeded
db_get portmap/loopback
if [ "true" = "$RET" ] ; then
echo 'OPTIONS="-i 127.0.0.1"' >> $CONFFILE
else
echo 'OPTIONS=""' >> $CONFFILE
fi
chmod 0644 $CONFFILE
}
# On install only, create the config file if it does not exist
#
if [ ! -e $CONFFILE ] ; then
if [ -z "$version" ] ; then
create_config
elif [ -n "$version" ] && [ "$action" = "upgrade" ] && \
dpkg --compare-versions "$version" lt 5-6; then
# or if upgrading from version older than 5-6 (which provided the file)
create_config
fi
fi
if [ "$1" = "configure" ] && [ -n "$2" ] &&
dpkg --compare-versions "$2" le "6.0.0-1"; 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
printf "# By default, listen only on the loopback interface\nOPTIONS=\"-i 127.0.0.1\"\n" > "$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
if [ -n "$OPTIONS" ]; then
OPTIONS="$OPTIONS -i 127.0.0.1"
else
OPTIONS="-i 127.0.0.1"
fi
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=$( pidofproc -p /var/run/portmap.pid /sbin/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 were 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
|