aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mailman/files/pkg-deinstall.in
blob: f8a389e8d545874ddf8fb5c306a5f275d71a5e0a (plain) (blame)
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
#! /bin/sh
#
# $FreeBSD$

PATH=/bin:/usr/bin:/usr/sbin

case $2 in
DEINSTALL)
  echo "---> Starting deinstall script"

  if /usr/bin/crontab -u "%%USER%%" -l | \
      /usr/bin/diff -B -b - "%%MAILMANDIR%%/cron/crontab.in" >/dev/null 2>&1 ; then
      echo "---> Zeroing crontab for \"%%USER%%\""
      /usr/bin/crontab -u "%%USER%%" -r </dev/null
      if [ -e /var/cron/allow ]; then
         grep -v "^%%USER%%$" /var/cron/allow > /var/cron/allow.new$$
         mv /var/cron/allow.new$$ /var/cron/allow
      fi
  else
      echo "---> Crontab for \"%%USER%%\" modified, not removed: please deinstall"
      echo "---> it manually if you no longer wish to use Mailman. E.g.:"
      echo "--->     /usr/bin/crontab -u \"%%USER%%\" -r"
  fi

  echo "---> Preserving the \"last_mailman_version\" file"
  /bin/mv -f "%%MAILMANDIR%%/data/last_mailman_version" /var/tmp/

  # If the errorlog is the only existing logfile, delete it.  (If Mailman's
  # qrunner had not been running, then the process of trying to stop the
  # qrunner (above) will cause the errorlog to be written to.  Hence, even if
  # the Mailman port/package is installed and immediately deinstalled, the
  # errorlog will exist.)
  if [ "`echo %%MAILMANDIR%%/logs/*`" = "%%MAILMANDIR%%/logs/error" ]; then
    echo "---> Deleting errorlog (It is the only existing logfile.)"
    /bin/rm -f "%%MAILMANDIR%%/logs/error"
  fi
  ;;

POST-DEINSTALL)
  echo "---> Starting post-deinstall script"

  # try to kill all empty directories - necessary on pkg_add-based systems
  find "%%MAILMANDIR%%" -depth -type d -exec rmdir '{}' + >/dev/null 2>&1 || :
  if [ -d "%%MAILMANDIR%%" ]; then
    echo '---> %%MAILMANDIR%% is not empty - this installation may have active lists!'
    ls -lRB "%%MAILMANDIR%%" | head -n200 || :
    echo "---> Restoring \"last_mailman_version\" file"
    /bin/mkdir -p "%%MAILMANDIR%%/data"
    /bin/mv -f /var/tmp/last_mailman_version "%%MAILMANDIR%%/data/"
  fi

  ;;
esac