This file is indexed.

postinst is in zentyal-core 2.3.21+quantal1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash

set -e

. /usr/share/debconf/confmodule

# This will be replaced with debian/zentyal-core.scripts-commmon which includes
# helper functions to set the password
PORT=443

stop_ebox_processes() {
    stop ebox.redis 2>/dev/null || true
    OLD_APACHE_PID=`ps aux | grep 'apache2.* -f /var/lib/ebox' | grep -v grep | awk '/^root/{print $2;exit}'`;
    kill $OLD_APACHE_PID 2>/dev/null || true
    pkill -9 -u ebox || true
}

# This function uses the eBox API to fetch the configured apache port used
# by eBox
#
# Usage: port=$(fetch_ebox_port)
fetch_ebox_port()
{
    set +e

    ret=$(perl -e '
            use EBox;
            use EBox::Global;
            EBox::init();

            my $apache = EBox::Global->modInstance('apache');
            print $apache->port();
            exit 0;
            ' 2> /dev/null );

    if [ $? -eq 0 ]; then
        PORT=$ret;
    fi

    set -e
}

# This function is used to try guess if a given port is available. It tries
# to connect to the port. Note that it does not distinguish if the port
# is being already used by eBox.
#
# Usage: check_port_available port_number
check_port_available()
{
    check_port=$1

    set +e

    perl -e '
        use IO::Socket;
        my $port = $ARGV[0];
        IO::Socket::INET->new(
            PeerAddr => "127.0.0.1",
            PeerPort => $port,
            Proto    => "tcp",
            Timeout  => 5) or exit 0;
        exit 1;
        ' $check_port 2> /dev/null;
    ret=$?

    set -e
    return $ret;
}

# This function uses the eBox API to set the apache port to be used by eBox.
#
# In case the current port and the new port are the same it returns without
# modifying the current value.
#
# We have to do two things to set the port:
#
#   Tell apache module its new port
#   Save changes in apache and services
#
# Usage: set_ebox_port new_port
set_ebox_port()
{
    db_get zentyal-core/port
    new_port=$RET

    fetch_ebox_port;
    if [ $new_port -eq $PORT ]; then
        return 0;
    fi

    set +e

    ret=$(perl -e '
            use EBox;
            use EBox::Global;

            EBox::init();
            my $port = $ARGV[0];
            my $global = EBox::Global->getInstance();
            my $apache = $global->modInstance('apache');
            $apache->setPort($port);
            $apache->saveConfig();
            if ($global->modExists('services')) {
                $global->modInstance('services')->saveConfig();
            }
            ' $new_port);

    set -e
}


# Automatically added by dh_installinit
if [ -x "/etc/init.d/zentyal" ]; then
	if [ ! -e "/etc/init/zentyal.conf" ]; then
		update-rc.d zentyal defaults >/dev/null
	fi
fi
# End automatically added section


ZENTYAL_HOME=/var/lib/zentyal/
FIRST_FILE=$ZENTYAL_HOME/.first

case "$1" in
    configure)
        ZENTYAL_LOGS_DIR=/var/log/zentyal
        ZENTYAL_BACKUPS_DIR=$ZENTYAL_HOME/conf/backups

        # create log directory
        test -d $ZENTYAL_LOGS_DIR || mkdir $ZENTYAL_LOGS_DIR
        chmod 750 $ZENTYAL_LOGS_DIR

        # create Zentyal apache certificates
        /usr/share/zentyal/create-certificate $ZENTYAL_HOME/conf/ssl > /dev/null 2>&1

        # add the ebox group and user
        if ! getent group ebox > /dev/null 2>&1
        then
            addgroup --system ebox

            # create the .first file only if we are on the first install
            touch $FIRST_FILE
        fi

        ENT_EBOX=`getent passwd ebox` || true
        if [ -z "$ENT_EBOX" ];
        then
            adduser --system --home $ZENTYAL_HOME \
                --disabled-password --ingroup ebox ebox
            adduser ebox adm
        elif [[ "$ENT_EBOX" =~ ":/var/lib/zentyal/:" ]]
        then
            true # user exists and has correct directory, do nothing
        else
            # override old Zentyal <= 2.0 home if the user ebox already exists
            chown ebox:ebox $ZENTYAL_HOME
            stop_ebox_processes
            usermod --home $ZENTYAL_HOME ebox > /dev/null 2>&1
        fi
        # to allow PAM authentication
        adduser ebox shadow > /dev/null 2>&1

        chown ebox:adm $ZENTYAL_LOGS_DIR
        chown -R ebox:adm $ZENTYAL_HOME/tmp
        chown -R ebox:adm $ZENTYAL_HOME/conf
        chown -R ebox:adm $ZENTYAL_HOME/log
        chown ebox:adm $ZENTYAL_BACKUPS_DIR
        chmod 700 $ZENTYAL_BACKUPS_DIR

        # create and set permissions for ebox.sid
        EBOX_SID="$ZENTYAL_HOME/conf/ebox.sid"
        if [ ! -e $EBOX_SID ]; then
            touch $EBOX_SID
        fi
        chown ebox:ebox $EBOX_SID
        chmod 0600 $EBOX_SID

        # add the stderr file needed by sudo
        STDERR_FILE=`perl -MEBox::Config -e'print EBox::Config::tmp() . 'stderr'; 1'`;
        touch ${STDERR_FILE}
        chmod 0600 ${STDERR_FILE}
        chown ebox:ebox ${STDERR_FILE}

        # add the dynamic-www- and downloads directories
        DYNAMIC_WWW_DIRS=$(perl -MEBox::Config -e'print EBox::Config::dynamicwww() ; print " " ; print join(" ", @{EBox::Config::dynamicwwwSubdirs()}); print " "; print EBox::Config::downloads;  1;');
        for DIR in $DYNAMIC_WWW_DIRS; do
            mkdir -p $DIR
            chown -R ebox:ebox $DIR
        done

        # change owner of $ZENTYAL_HOME
        chown ebox:ebox $ZENTYAL_HOME

        # setup random redis password
        REDIS_PASS="$ZENTYAL_HOME/conf/redis.passwd"
        if [ ! -f $REDIS_PASS ]; then
            touch $REDIS_PASS
            chmod 0600 $REDIS_PASS
            chown ebox:ebox $REDIS_PASS
            tr -dc A-Za-z0-9 < /dev/urandom | head -c8 > $REDIS_PASS
        fi

        # sudo configuration
        /usr/share/zentyal/sudoers-friendly

        if [ -z "$2" ]; then
            # Set eBox port only if it's the first time we install
            set_ebox_port
            # Write redis configuration
            invoke-rc.d zentyal apache start || true
        fi

        # create logs & reports database
        /usr/share/zentyal/create-db

        # setup core modules
        /usr/share/zentyal/initial-setup sysinfo $2
        /usr/share/zentyal/initial-setup --no-restart logs $2
        /usr/share/zentyal/initial-setup --no-restart events $2

        dpkg-trigger --no-await zentyal-core
    ;;
    triggered)
        # remove the menu cache
        rm -f $ZENTYAL_HOME/tmp/menucache

        # Call restart script (apache, logs, events)
        /usr/share/zentyal/restart-trigger

        rm -f $ZENTYAL_HOME/dpkg_running
    ;;
esac

db_stop

exit 0