home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / dpkg / info / ufw.postinst < prev    next >
Encoding:
Text File  |  2009-04-03  |  3.4 KB  |  127 lines

  1. #!/bin/sh -e
  2.  
  3. . /usr/share/debconf/confmodule
  4.  
  5. RULES_PATH="/etc/ufw"
  6. USER_PATH="/var/lib/ufw"
  7. TEMPLATE_PATH="/usr/share/ufw"
  8.  
  9. enable_ufw() {
  10.     ans=""
  11.     if [ "$1" = "true" ]; then
  12.         ans="yes"
  13.     elif [ "$1" = "false" ]; then
  14.         ans="no"
  15.     else
  16.         return 1
  17.     fi
  18.  
  19.     sed -i "s/^ENABLED=.*/ENABLED=$ans/" /etc/ufw/ufw.conf
  20. }
  21.  
  22. allow_port() {
  23.     ufw allow "$@" >/dev/null || true
  24. }
  25.  
  26. allow_service() {
  27.     service=`echo "$@" | sed 's/#/ /g'`
  28.     if [ "$service" = "Cups" ]; then
  29.         allow_port 631
  30.     elif [ "$service" = "DNS" ]; then
  31.         allow_port 53
  32.     elif [ "$service" = "Imap (Secure)" ]; then
  33.         allow_port 993/tcp
  34.     elif [ "$service" = "Pop3 (Secure)" ]; then
  35.         allow_port 995/tcp
  36.     elif [ "$service" = "SSH" ]; then
  37.         allow_port 22/tcp
  38.     elif [ "$service" = "Samba" ]; then
  39.         allow_port 137/udp
  40.         allow_port 138/udp
  41.         allow_port 139/tcp
  42.         allow_port 445/tcp
  43.     elif [ "$service" = "Smtp" ]; then
  44.         allow_port 25/tcp
  45.     elif [ "$service" = "WWW" ]; then
  46.         allow_port 80/tcp
  47.     elif [ "$service" = "WWW (Secure)" ]; then
  48.         allow_port 443/tcp
  49.     fi
  50. }
  51.  
  52. case "$1" in
  53.     configure)
  54.         # these files are required, but don't want to change them if
  55.         # the user modified them
  56.         for f in before.rules before6.rules after.rules after6.rules
  57.         do
  58.             ucf --debconf-ok $TEMPLATE_PATH/$f $RULES_PATH/$f
  59.         done
  60.  
  61.         for f in user.rules user6.rules
  62.         do
  63.             if [ ! -e "$USER_PATH/$f" ]; then
  64.                 # if no config, copy the template
  65.                 cp $TEMPLATE_PATH/$f $USER_PATH/$f
  66.             fi
  67.         done
  68.  
  69.         if [ ! -e "/etc/ufw/ufw.conf" ]; then
  70.             cp $TEMPLATE_PATH/ufw.conf /etc/ufw
  71.         fi
  72.  
  73.         if [ ! -z "$2" ] && dpkg --compare-versions "$2" lt "0.24.1" ; then
  74.             # remove these symlinks for existing installations
  75.             rm -f /etc/rc0.d/K39ufw
  76.             rm -f /etc/rc6.d/K39ufw
  77.         fi
  78.  
  79.         update-rc.d ufw start 39 S . stop 39 1 . > /dev/null
  80.  
  81.         # configure ufw with debconf values
  82.         db_get ufw/enable
  83.         enabled="$RET"
  84.  
  85.         db_fget ufw/existing_configuration seen
  86.         seen_warning="$RET"
  87.         if [ "$enabled" = "true" ] && [ "$seen_warning" = "false" ] ; then
  88.             db_get ufw/allow_known_ports
  89.             CHOICES="$RET"
  90.             for service in `echo "$CHOICES" | sed 's/, /\n/g' | sed 's/ /#/g'`; do
  91.                 allow_service "$service"
  92.             done
  93.  
  94.             db_get ufw/allow_custom_ports
  95.             PORTS="$RET"
  96.             for port in $PORTS ; do
  97.                 allow_service "$port"
  98.             done
  99.         fi
  100.  
  101.         # need to do this after all 'allow_service' calls, otherwise ufw may
  102.         # try to use iptables, which breaks the installer
  103.         enable_ufw "$enabled"
  104.         ;;
  105.     triggered)
  106.         ufw app update all || echo "Processing ufw triggers failed. Ignoring."
  107.         exit 0
  108.         ;;
  109.     abort-upgrade|abort-remove|abort-deconfigure)
  110.         ;;
  111.     *)
  112.         echo "postinst called with unknown argument '$1'" >&2
  113.         exit 1
  114.         ;;
  115. esac
  116.  
  117. # Automatically added by dh_pycentral
  118. rm -f /var/lib/pycentral/ufw.pkgremove
  119. if which pycentral >/dev/null 2>&1; then
  120.     pycentral pkginstall ufw
  121.     if grep -qs '^ufw$' /var/lib/pycentral/delayed-pkgs; then
  122.         sed -i '/^ufw$/d' /var/lib/pycentral/delayed-pkgs
  123.     fi
  124. fi
  125. # End automatically added section
  126.  
  127.