~ahasenack/landscape-client/landscape-client-1.5.5-0ubuntu0.9.04.0

« back to all changes in this revision

Viewing changes to debian/landscape-client.postinst

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-09-08 16:35:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080908163557-l3ixzj5dxz37wnw2
Tags: 1.0.18-0ubuntu1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
set -e
 
3
 
 
4
# summary of how this script can be called:
 
5
#        * <postinst> `configure' <most-recently-configured-version>
 
6
#        * <old-postinst> `abort-upgrade' <new version>
 
7
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
 
8
#          <new-version>
 
9
#        * <postinst> `abort-remove'
 
10
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
 
11
#          <failed-install-package> <version> `removing'
 
12
#          <conflicting-package> <version>
 
13
# for details, see http://www.debian.org/doc/debian-policy/ or
 
14
# the debian-policy package
 
15
 
 
16
. /usr/share/debconf/confmodule
 
17
trap "db_stop || true" EXIT HUP INT QUIT TERM
 
18
 
 
19
PACKAGE=landscape-client
 
20
 
 
21
# Use the default installed Python.  Running just "python" might run
 
22
# something from /usr/local/bin, which doesn't necessarily support
 
23
# running the landscape client.
 
24
PYTHON=/usr/bin/python
 
25
 
 
26
case "$1" in
 
27
    configure)
 
28
 
 
29
        db_input medium $PACKAGE/sysinfo_in_motd || true
 
30
        db_get $PACKAGE/sysinfo
 
31
        # Choices:
 
32
        #  * Do not display sysinfo on login
 
33
        #  * Cache sysinfo in /etc/motd
 
34
        #  * Run sysinfo on every login
 
35
        SYSINFO="${RET:-Cache sysinfo in /etc/motd}"
 
36
        if [ "$RET" = "Cache sysinfo in /etc/motd" ]; then
 
37
            rm -f /etc/profile.d/landscape-sysinfo.sh 2>/dev/null || true
 
38
            ln -s /usr/bin/landscape-sysinfo /etc/update-motd.d/50-landscape-sysinfo
 
39
            /etc/init.d/update-motd refresh || true
 
40
        elif [ "$RET" = "Run sysinfo on every login" ]; then
 
41
            if rm -f /etc/update-motd.d/50-landscape-sysinfo 2>/dev/null; then
 
42
                /etc/init.d/update-motd refresh || true
 
43
            fi
 
44
            echo /usr/bin/landscape-sysinfo > /etc/profile.d/landscape-sysinfo.sh
 
45
        else
 
46
            if rm -f /etc/update-motd.d/50-landscape-sysinfo 2>/dev/null; then
 
47
                /etc/init.d/update-motd refresh || true
 
48
            fi
 
49
            rm -f /etc/profile.d/landscape-sysinfo.sh || true
 
50
        fi
 
51
 
 
52
        # 0.9.1 introduces non-backwards compatible changes.  This detects
 
53
        # whether or not the data is in the current format.  If not, all
 
54
        # existing data is removed.
 
55
        DATA_DIR=/var/lib/landscape
 
56
 
 
57
        if [ -d $DATA_DIR/data ]; then
 
58
            rm -rf $DATA_DIR/*
 
59
        elif [ -f $DATA_DIR/client/data.bpickle ]; then
 
60
            LAST_BYTE=`sed -n '$,$s/.*\(.\)/\1/p' $DATA_DIR/client/data.bpickle`
 
61
            if [ "$LAST_BYTE" = e ]; then
 
62
                rm -rf $DATA_DIR/*
 
63
            fi
 
64
        fi
 
65
 
 
66
        # Create landscape system user
 
67
        if ! getent passwd landscape >/dev/null; then
 
68
            adduser --quiet --system --disabled-password \
 
69
                --gecos "Landscape Client Daemon" \
 
70
                --home /var/lib/landscape --no-create-home landscape
 
71
        fi
 
72
 
 
73
        # Fix prior ownerships
 
74
        chown -R landscape /var/log/landscape /var/lib/landscape
 
75
 
 
76
        # Tell dbus to reload its configuration since we've installed a conf
 
77
        # to its system.d. We must do this before invoking landscape-config.
 
78
        invoke-rc.d dbus reload || true
 
79
 
 
80
        CONFIG_FILE=/etc/landscape/client.conf
 
81
        if [ ! -f $CONFIG_FILE ]; then
 
82
            # Create new configuration, with private mode
 
83
            TEMPFILE=$(mktemp -p /etc/landscape)
 
84
            cat > $TEMPFILE <<END
 
85
[client]
 
86
log_level = info
 
87
url = https://landscape.canonical.com/message-system
 
88
ping_url = http://landscape.canonical.com/ping
 
89
data_path = /var/lib/landscape/client
 
90
END
 
91
            chown landscape $TEMPFILE
 
92
            mv $TEMPFILE $CONFIG_FILE
 
93
 
 
94
            # Do debconf configuration
 
95
            db_get $PACKAGE/register_system
 
96
            if [ "$RET" = true ]; then
 
97
                priority=high
 
98
            else
 
99
                priority=medium
 
100
            fi
 
101
            db_input "$priority" $PACKAGE/computer_title || true
 
102
            db_input "$priority" $PACKAGE/account_name || true
 
103
            db_input "$priority" $PACKAGE/registration_password || true
 
104
            db_go || true
 
105
 
 
106
            db_get $PACKAGE/computer_title
 
107
            COMPUTER_TITLE="${RET}"
 
108
            db_get $PACKAGE/account_name
 
109
            ACCOUNT_NAME="${RET}"
 
110
            db_get $PACKAGE/registration_password
 
111
            REGISTRATION_PASSWORD="${RET}"
 
112
 
 
113
            # If we got the needed information, actually do the registration.
 
114
            if [ -n "$ACCOUNT_NAME" -a -n "$COMPUTER_TITLE" ]; then
 
115
                landscape-config --silent -a "$ACCOUNT_NAME" \
 
116
                                          -p "$REGISTRATION_PASSWORD" \
 
117
                                          -t "$COMPUTER_TITLE"
 
118
            fi
 
119
        else
 
120
            # Fix non-private permissions
 
121
            chmod 0600 $CONFIG_FILE
 
122
        fi
 
123
 
 
124
        # old monolithic clients have a single persist data file and a single
 
125
        # package hash db.  This data should be migrated to the new format
 
126
        # where each service has a persist and the package data is kept in a
 
127
        # sqlite database.
 
128
 
 
129
        DATA_BPICKLE=$DATA_DIR/client/data.bpickle
 
130
        BROKER_BPICKLE=$DATA_DIR/client/broker.bpickle
 
131
 
 
132
        if [ -f $DATA_BPICKLE -a ! -f $BROKER_BPICKLE ]; then
 
133
            $PYTHON -c "from landscape.upgraders import legacy; legacy.migrate_data_file('$DATA_DIR/client')"
 
134
            mv $DATA_BPICKLE $DATA_BPICKLE.migrated
 
135
            echo "Old monolithic client data file migrated to new format."
 
136
        fi
 
137
 
 
138
    ;;
 
139
 
 
140
    abort-upgrade|abort-remove|abort-deconfigure)
 
141
    ;;
 
142
 
 
143
    *)
 
144
        echo "postinst called with unknown argument \`$1'" >&2
 
145
        exit 1
 
146
    ;;
 
147
esac
 
148
 
 
149
# dh_installdeb will replace this with shell code automatically
 
150
# generated by other debhelper scripts.
 
151
 
 
152
#DEBHELPER#
 
153
 
 
154
exit 0