This file is indexed.

postinst is in ejabberd 18.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#! /bin/sh
# postinst script for ejabberd
#
# see: dh_installdeb(1)

set -e

CONFIG_SOURCE=/usr/share/ejabberd/ejabberd.yml.example
EJABBERDCTL_CONFIG_SOURCE=/usr/share/ejabberd/ejabberdctl.cfg.example
CONFIG_TARGET=/etc/ejabberd/ejabberd.yml
EJABBERDCTL_CONFIG_TARGET=/etc/default/ejabberd
TEMPFILE=$(mktemp)
EJABBERDCTL_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
	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 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*' -exec chown ejabberd:adm {} \+ -exec chmod 0640 {} \+
		fi
	fi

	# Chown the cert so ejabberd user can use it but not be accessible by the
	# world.
	if [ -f /etc/ejabberd/ejabberd.pem ]
	then
		if ! dpkg-statoverride --list /etc/ejabberd/ejabberd.pem >/dev/null; then
			chown root:ejabberd /etc/ejabberd/ejabberd.pem
		fi
	fi

	db_get ejabberd/erlangopts
	ERLOPTS="$RET"
	if [ -n "$ERLOPTS" ]; then
		sed -e "s/#\?ERL_OPTIONS=.*/ERL_OPTIONS=\"$ERLOPTS\"/" "$EJABBERDCTL_CONFIG_SOURCE" > "$EJABBERDCTL_TEMPFILE"
		ucf -three-way --debconf-ok "$EJABBERDCTL_TEMPFILE" "$EJABBERDCTL_CONFIG_TARGET"
		chmod 644 "$EJABBERDCTL_CONFIG_TARGET"
	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/.*ermine.*//" $CONFIG_SOURCE > "$TEMPFILE"
	# Since username is optional and we let the user set up the admin account
	# if there is no input to debconf's query, we use the given username or
	# leave it empty
	if [ -n "$USER" ]; then
		sed -i "s/  ##     - \"aleksey@localhost\"/       - \"$USER@$HOST\"/" "$TEMPFILE"
	else
		sed -i "s/  ##     - \"aleksey@localhost\"/       - \"\"/" "$TEMPFILE"
	fi
	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" ] && [ -n "$PASSWD" ]; then
		echo "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
				cnt=$((cnt + 1))
				if [ $cnt -ge 60 ] ; then
					echo
					echo "Can't register admin user \"$USER@$HOST\"."
					echo "Ejabberd is taking too long to start."
					flag=0
					break
				fi
				sleep 1
			done

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

# After updates to packaging (config validation and nodename changes), we need
# to keep track of the install process so we can aid and have users coming from
# before these changes transition smoothly.
# This flag will track whether the upgrade fails due to the nodename change
# (it will remain if failed) so that the user will not be forced to change
# configuration in debconf due to invalid configuration
touch /var/lib/ejabberd/.postinst.flag && chmod 644 /var/lib/ejabberd/.postinst.flag

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

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

		;;

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

# Automatically added by dh_apparmor/UNDECLARED
aa_is_enabled() {
   if command aa-enabled >/dev/null 2>&1; then
      # apparmor >= 2.10.95-2
      aa-enabled --quiet 2>/dev/null
   else
      # apparmor << 2.10.95-2
      # (This should be removed once Debian Stretch and Ubuntu 18.04 are out.)
      rc=0
      aa-status --enabled 2>/dev/null || rc=$?
      [ "$rc" = 0 ] || [ "$rc" = 2 ]
   fi
}

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_is_enabled; then
            apparmor_parser -r -T -W "$APP_PROFILE" || true
        fi
    fi
fi
# End automatically added section
# Automatically added by dh_systemd_enable/11.1.4ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	# 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
fi
# End automatically added section
# Automatically added by dh_installinit/11.1.4ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; 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/11.1.4ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if [ -x "/etc/init.d/ejabberd" ]; then
		update-rc.d ejabberd defaults >/dev/null
		if [ -n "$2" ]; then
			_dh_action=restart
		else
			_dh_action=start
		fi
		invoke-rc.d ejabberd $_dh_action || exit 1
	fi
fi
# End automatically added section


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

# Remove the flag if install is successful
rm -f /var/lib/ejabberd/.postinst.flag

exit 0