~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to debian/erlang-base.prerm

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# prerm script for erlang-base
 
3
#
 
4
# see: dh_installdeb(1)
 
5
 
 
6
set -e
 
7
 
 
8
# summary of how this script can be called:
 
9
#        * <prerm> remove
 
10
#        * <old-prerm> upgrade <new-version>
 
11
#        * <new-prerm> failed-upgrade <old-version>
 
12
#        * <conflictor's prerm> remove in-favour <package> <new version>
 
13
#        * <deconfigured's prerm> deconfigure in-favour <package being installed> <version> \
 
14
#                                 removing <conflicting package> <version>
 
15
# for details, see /usr/share/doc/debian-policy/
 
16
 
 
17
case "$1" in
 
18
    remove|upgrade)
 
19
        echo -n "Searching for services which depend on erlang and should be stopped..."
 
20
        # find all init scripts and packages they belong
 
21
        inits=$(dpkg -S '/etc/init.d/*' 2>/dev/null | sed -e's:/etc/init.d/::')
 
22
        # filter the list of the packages
 
23
        packs=$(echo $inits | sed -e's/:[[:space:]]\+[^[:space:]]*//g' | sed -e's/ /\n/g' | sort -u)
 
24
        # find packages, which depend on erlang
 
25
        packs=$(dpkg -s $packs 2>/dev/null | egrep '^Package:|^Status:|^Depends' | awk '{if ($1 ~ /^Package:/) {package=$2;inst=0} else if ($0 ~ /^Status: .* installed$/) {inst=1} else if ((inst==1) && ($0 ~ /^Depends: .* erlang/)) {print package}}')
 
26
        # construct services list from the packages
 
27
        services=""
 
28
        for p in $packs ; do
 
29
            service=$(echo $inits | sed -e's/\([^:]\) /\1\n/g' | awk "/^$p:/ {print \$2}")
 
30
            services="$services $service"
 
31
        done
 
32
        services=$(echo $services | tr '\n' ' ' | sed -e's/\(^[[:space:]]*\|[[:space:]]*$\)//g')
 
33
 
 
34
        if [ -z "$services" ] ; then
 
35
            echo "none found."
 
36
        else
 
37
            echo "found: $services."
 
38
            echo "Stopping services which depend on erlang"
 
39
            rl=$(runlevel | awk '{print $2}')
 
40
            for service in $services ; do
 
41
                if [ -f /usr/share/file-rc/rc -o -f /usr/lib/file-rc/rc ] && [ -f /etc/runlevel.conf ]; then
 
42
                    idl=$(filerc $rl $service)
 
43
                else
 
44
                    idl=$(ls /etc/rc${rl}.d/S??${service} 2> /dev/null | head -1)
 
45
                fi
 
46
                if [ -n "$idl" ] ; then
 
47
                    echo -n "  $service: stopping..."
 
48
                    $idl stop > /dev/null 2>&1 || true
 
49
                    echo "done."
 
50
                fi
 
51
            done
 
52
        fi
 
53
 
 
54
        echo -n "Killing epmd..."
 
55
        pid=$(ps ax | grep epmd | grep -v grep |  awk '//{print $1}' | head -1)
 
56
        if [ -z "$pid" ] ; then
 
57
            echo "it is not running."
 
58
        else
 
59
            if kill $pid 2>/dev/null  ; then
 
60
                echo "done."
 
61
            else
 
62
                echo "failed."
 
63
            fi
 
64
        fi
 
65
    ;;
 
66
 
 
67
    failed-upgrade|deconfigure)
 
68
    ;;
 
69
 
 
70
    *)
 
71
        echo "prerm called with unknown argument \`$1'" >&2
 
72
        exit 0
 
73
    ;;
 
74
esac
 
75
 
 
76
# dh_installdeb will replace this with shell code automatically
 
77
# generated by other debhelper scripts.
 
78
 
 
79
#DEBHELPER#
 
80
 
 
81
exit 0
 
82