This file is indexed.

postinst is in ejabberd 16.01-2.

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
#! /bin/sh
# postinst script for ejabberd
#
# see: dh_installdeb(1)

set -e

CONFIG_SOURCE=/usr/share/ejabberd/ejabberd.yml.example
CONFIG_TARGET=/etc/ejabberd/ejabberd.yml
TEMPFILE=$(mktemp)

. /usr/share/debconf/confmodule

setup_ejabberd()
{
    # Ejabberd config dir may contain sensitive data, so making it unreadable by
    # the world.
    if ! dpkg-statoverride --list /etc/ejabberd >/dev/null; then
	chown root:ejabberd /etc/ejabberd
	chmod 750 /etc/ejabberd
    fi

    # The users database dir /var/lib/ejabberd must be writable by user ejabberd.
    install -d /var/lib/ejabberd
    if ! dpkg-statoverride --list /var/lib/ejabberd >/dev/null; then
	chown -R ejabberd:ejabberd /var/lib/ejabberd
	chmod 700 /var/lib/ejabberd
    fi

    # Ejabberd logs should be readable by users in adm group (see also logrotate script).
    install -d /var/log/ejabberd
    if ! dpkg-statoverride --list /var/log/ejabberd >/dev/null; then
	chown ejabberd:adm /var/log/ejabberd
	chmod 2750 /var/log/ejabberd
	if dpkg --compare-versions "$2" lt '2.1.4'; then
	    find /var/log/ejabberd -type f -name '*.log*' \
		| while read f; do
		    chown ejabberd:adm "$f"
		    chmod 0640 "$f"
	    done
	fi
    fi

    # Making /etc/ejabberd/ejabberd.pem if it does not exist.
    ( cd /etc/ejabberd
    if [ ! -f ejabberd.pem ]
    then
	echo "Generating SSL certificate /etc/ejabberd/ejabberd.pem..."
	EHOSTNAME=$(hostname -s 2>/dev/null || echo localhost)
	EDOMAINNAME=$(hostname -d 2>/dev/null || echo localdomain)
	openssl req -new -x509 -days 365 -nodes -out ejabberd.pem \
		    -keyout ejabberd.pem > /dev/null 2>&1 <<+++
.
.
.
$EDOMAINNAME
$EHOSTNAME
ejabberd
root@$EHOSTNAME.$EDOMAINNAME
+++
    fi
    if ! dpkg-statoverride --list /etc/ejabberd/ejabberd.pem >/dev/null; then
	chown root:ejabberd /etc/ejabberd/ejabberd.pem
	chmod 640 /etc/ejabberd/ejabberd.pem
    fi
    )

    db_get ejabberd/hostname
    HOST="$RET"
    db_get ejabberd/user
    USER="$RET"
    db_get ejabberd/password
    PASSWD="$RET"
    sed -e     "s/  - \"localhost\"/  - \"$HOST\"/ ;
		s/  ## admin/  admin/ ;
		0,/  ##   user/s/  ##   user/     user/ ;
		s/  ##     - \"aleksey\": \"localhost\"/         - \"$USER\": \"$HOST\"/ ;
		s/.*ermine.*//" $CONFIG_SOURCE > $TEMPFILE
    ucf --three-way --debconf-ok $TEMPFILE $CONFIG_TARGET
    db_stop

    # Making ejabberd config readable only by ejabberd user.
    chown ejabberd:ejabberd $CONFIG_TARGET
    chmod 600 $CONFIG_TARGET
}

register_admin()
{
    if [ -n "$USER" -a -n "$PASSWD" ]; then
	echo -n "Waiting for ejabberd to register admin user"

	if ejabberdctl status >/dev/null || test $? = 1 ; then
	    # Ejabberd is starting ($? = 1) or running ($? = 0) already.
	    cnt=0
	    flag=1
	    while ! ejabberdctl status >/dev/null ; do
		echo -n "."
		cnt=`expr $cnt + 1`
		if [ $cnt -ge 60 ] ; then
		    echo
		    echo "Can't register admin user \"$USER@$HOST\"."
		    echo -n "Ejabberd is starting too long."
		    flag=0
		    break
		fi
		sleep 1
	    done

	    echo
	    if [ $flag -eq 1 ] ; then
		if ! status=$(ejabberdctl register "$USER" "$HOST" "$PASSWD") ; then
		    if echo $status | grep -q "already registered" ; then
			echo "Admin user \"$USER@$HOST\" is already registered. Password IS NOT changed."
		    else
			echo "Can't register admin user \"$USER@$HOST\"."
		    fi
		else
		    echo "Admin user \"$USER@$HOST\" is registered successfully."
		    invoke-rc.d ejabberd restart
		fi
	    fi
	else
	    echo
	    echo "Can't register admin user \"$USER@$HOST\"."
	    echo "Ejabberd server is not started."
	fi
    fi
}

case "$1" in
    configure|reconfigure)
	adduser --quiet --system --shell /bin/sh --group --home /var/lib/ejabberd ejabberd 2> /dev/null
	setup_ejabberd "$@"
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

# Automatically added by dh_apparmor
if [ "$1" = "configure" ]; then
    APP_PROFILE="/etc/apparmor.d/usr.sbin.ejabberdctl"
    if [ -f "$APP_PROFILE" ]; then
        # Add the local/ include
        LOCAL_APP_PROFILE="/etc/apparmor.d/local/usr.sbin.ejabberdctl"

        test -e "$LOCAL_APP_PROFILE" || {
            tmp=`mktemp`
        cat <<EOM > "$tmp"
# Site-specific additions and overrides for usr.sbin.ejabberdctl.
# For more details, please see /etc/apparmor.d/local/README.
EOM
            mkdir `dirname "$LOCAL_APP_PROFILE"` 2>/dev/null || true
            mv -f "$tmp" "$LOCAL_APP_PROFILE"
            chmod 644 "$LOCAL_APP_PROFILE"
        }

        # Reload the profile, including any abstraction updates
        if aa-status --enabled 2>/dev/null; then
            apparmor_parser -r -T -W "$APP_PROFILE" || true
        fi
    fi
fi
# End automatically added section
# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask ejabberd.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled ejabberd.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable ejabberd.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state ejabberd.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	# In case this system is running systemd, we need to ensure that all
	# necessary tmpfiles (if any) are created before starting.
	if [ -d /run/systemd/system ] ; then
		systemd-tmpfiles --create /usr/lib/tmpfiles.d/ejabberd.conf >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/ejabberd" ]; then
		update-rc.d ejabberd defaults >/dev/null
	fi
	if [ -x "/etc/init.d/ejabberd" ] || [ -e "/etc/init/ejabberd.conf" ]; then
		if [ -n "$2" ]; then
			_dh_action=restart
		else
			_dh_action=start
		fi
		invoke-rc.d ejabberd $_dh_action || exit $?
	fi
fi
# End automatically added section


case "$1" in
    configure|reconfigure)
    register_admin
    ;;
esac

exit 0