This file is indexed.

postinst is in mailman3-web 0+20170523-14.

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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/sh

set -e

. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst

# Set permissions for sqlite3 file
dbc_dbfile_owner="www-data:www-data"
dbc_dbfile_perms="0640"

dbc_go mailman3-web "$@"

pathfind() {
    OLDIFS="$IFS"
    IFS=:
    for p in $PATH; do
        if [ -x "$p/$*" ]; then
            IFS="$OLDIFS"
            return 0
        fi
    done
    IFS="$OLDIFS"
    return 1
}

if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
    . /usr/share/apache2/apache2-maintscript-helper

    apache_install() {
        if [ -d /etc/apache2/conf-available ] && [ ! -e /etc/apache2/conf-available/mailman3.conf ]; then
            ln -s /etc/mailman3/apache.conf /etc/apache2/conf-available/mailman3.conf
        fi
        # Enable proxy_uwsgi module
        if [ -f /etc/apache2/mods-available/proxy_uwsgi.load ]; then
            apache2_invoke enmod proxy_uwsgi
        fi
        # Enable the configuration
        apache2_invoke enconf mailman3.conf
    }
else
    apache_install() {
        return 1
    }
fi

if [ -e /usr/share/nginx ]; then
    nginx_install() {
        if [ -d /etc/nginx/sites-enabled ] && [ ! -e /etc/nginx/sites-enabled/mailman3 ]; then
            ln -s /etc/mailman3/nginx.conf /etc/nginx/sites-enabled/mailman3
            mkdir -p /var/log/nginx/mailman3 && chown www-data:adm /var/log/nginx/mailman3
        fi
    }
else
    nginx_install() {
        return 1
    }
fi

settings_local_new=

cleanup () {
    [ "$settings_local_new" ] && rm -f "$settings_local_new"
}

# All seds are using a vertical pipe "|" as a delimiter because of
# the potential presence of a slash "/" into some variables, as those
# filled with a base64 -w0. We thought about using a number sign "#",
# but sometimes the delimiter follows a variable sign "$", and "$#"
# might be interpreted by the shell.
create_config () {
    trap cleanup EXIT
    settings_local_new=`tempfile -m 0644`
    cp -a /usr/share/mailman3-web/settings_local.py.sample $settings_local_new
    
    # get database settings from dbconfig-common
    if [ -f /etc/dbconfig-common/mailman3-web.conf ]; then
        . /etc/dbconfig-common/mailman3-web.conf

        # Comment out default database settings if dbconfig is used
        sed -i -e "s|^\(\s\+\)\('ENGINE':\)|\1#\2|" \
                $settings_local_new

        sed -i -e "s|^\(\s\+'NAME':\s*'\)\S\+\(',\s*\)|\1$dbc_dbname\2|" \
               -e "s|^\(\s\+'USER':\s*'\)\S\+\(',\s*\)|\1$dbc_dbuser\2|" \
               -e "s|^\(\s\+'PASSWORD':\s*'\)\S\+\(',\s*\)|\1$dbc_dbpass\2|" \
               -e "s|^\(\s\+'HOST':\s*'\)\S*\(',\s*\)|\1$dbc_dbserver\2|" \
                $settings_local_new
    fi

    case "$dbc_dbtype" in
        pgsql)
            sed -i -e "s|^\(\s\+\)#\?\s*\('ENGINE': 'django.db.backends.postgresql_psycopg2',\s*\)$|\1\2|" \
                    $settings_local_new
            ;;
        mysql)
            sed -i -e "s|^\(\s\+\)#\?\s*\('ENGINE': 'django.db.backends.mysql',\s*\)$|\1\2|" \
                   -e "s|^\(\s\+\)#\?\s*\('init_command': \"SET sql_mode=.*\",\s*\)$|\1\2|" \
                    $settings_local_new
            ;;
        sqlite3)
            sed -i -e "s|^\(\s\+\)#\?\s*\('ENGINE': 'django.db.backends.sqlite3',\s*\)$|\1\2|" \
                   -e "s|^\(\s\+'NAME':\s*'\)\S\+\(',\s*\)|\1$dbc_basepath/$dbc_dbname\2|" \
                    $settings_local_new
            ;;
        "")
            ;;
        *)
            echo "Unsupported database type $dbc_type."
            exit 1
            ;;
    esac

    # Get SECRET_KEY from mailman-web.py if existent
    [ -f /etc/mailman3/mailman-web.py ] && {
        secretkey="$(sed -ne "s/^SECRET_KEY = '\(\S\+\)'$/\1/p" \
            /etc/mailman3/mailman-web.py)"
    }
    # If this is the default key, forget it!
    [ "$secretkey" = "change-this-on-your-production-server" ] && unset secretkey
    # Generate a new one
    while [ -z "$secretkey" ]; do
        secretkey="$(dd if=/dev/urandom bs=1 count=200 2>/dev/null | \
            base64 -w0 | sed -ne 's|\(.\{48\}\).*|\1|p')"
    done

    # Get admin mail address from ADMINS from maimlan3-web.py if existent
    [ -f /etc/mailman3/mailman-web.py ] && {
        adminmail="$(sed -e '1,/^ADMINS = ($/d' -e '/^)$/,$d' -e \
            "s|^.*'Mailman Suite Admin'.*'\(\S\+\)').*$|\1|" \
            /etc/mailman3/mailman-web.py)"
    }

    # Get MAILMAN_REST_API_PASS from mailman-web.py if existent
    [ -f /etc/mailman3/mailman-web.py ] && {
        restapipass="$(sed -ne "s|^MAILMAN_REST_API_PASS = '\(\S\+\)'$|\1|p" \
            /etc/mailman3/mailman-web.py)"
    }
    # If this is the default key, forget it!
    [ "$restapipass" = "restpass" ] && unset restapipass
    # Set a new one
    if [ -z "$archiverkey" ]; then
        [ -f /etc/mailman3/mailman.cfg ] && {
            restapipass="$(sed -ne 's|^\s*admin_pass:\s*||p' \
                /etc/mailman3/mailman.cfg)"
        }
    fi

    # Get MAILMAN_ARCHIVER_KEY from mailman-web.py if existent
    [ -f /etc/mailman3/mailman-web.py ] && {
        archiverkey="$(sed -ne "s|^MAILMAN_ARCHIVER_KEY = '\(\S\+\)'$|\1|p" \
            /etc/mailman3/mailman-web.py)"
    }
    # If this is the default key, forget it!
    [ "$archiverkey" = "SecretArchiverAPIKey" ] && unset archiverkey
    # Generate a new one
    while [ -z "$archiverkey" ]; do
        archiverkey="$(dd if=/dev/urandom bs=1 count=200 2>/dev/null \
            | base64 -w0 | sed -ne 's|\(.\{32\}\).*|\1|p')"
    done

    db_get mailman3-web/emailname
    emailname="$RET"

    db_get mailman3-web/superuser-mail
    su_mail="$RET"

    # Set custom settings in settings_local.py
    sed -i -e "s|^\(\s*SECRET_KEY\s*=\s*'\)\S\+\('\s*\)$|\1$secretkey\2|" \
           -e "/^ADMINS = ($/,/^)$/{s|'$adminmail'|'$su_mail'|}" \
           -e "s|^\(\s*MAILMAN_REST_API_PASS\s*=\s*'\)\S\+\('\s*\)|\1$restapipass\2|" \
           -e "s|^\(\s*MAILMAN_ARCHIVER_KEY\s*=\s*'\)\S\+\('\s*\)|\1$archiverkey\2|" \
           -e "s|^\(\s*EMAILNAME\s*=\s*'\)\S\+\('\s*\)|\1$emailname\2|" \
           $settings_local_new

    # Register new config file
    ucf --three-way --debconf-ok "$settings_local_new" /etc/mailman3/mailman-web.py
    ucfr mailman3-web /etc/mailman3/mailman-web.py
    chmod 0640 /etc/mailman3/mailman-web.py
    chown root:www-data /etc/mailman3/mailman-web.py
    rm -f $settings_local_new
}

su_cmd="su --shell /bin/sh --command"
django_admin="python2.7 /usr/bin/django-admin"
django_admin_args="--verbosity 0 --no-color --pythonpath /usr/share/mailman3-web --settings settings"

init_django () {
    if pathfind django-admin; then
        update_django
        $su_cmd "$django_admin loaddata $django_admin_args first_start" www-data
    fi
}

update_django () {
    if pathfind django-admin; then
        $su_cmd "$django_admin migrate       --no-input $django_admin_args" www-data
        $su_cmd "$django_admin collectstatic --no-input $django_admin_args" www-data
    fi
}

config_django_site () {
    db_get mailman3-web/django-site
    django_site_domain="$RET"

    if [ -n "$django_site_domain" ]; then
       django_site_domain_old="$($su_cmd "$django_admin shell $django_admin_args \
           --command \"from django.contrib.sites.models import Site; \
           print Site.objects.all()[0].domain\"" www-data)"
       django_site_name="$($su_cmd "$django_admin shell $django_admin_args \
           --command \"from django.contrib.sites.models import Site; \
           print Site.objects.all()[0].name\"" www-data)"

       if [ "$django_site_name" = "example.com" ] || \
          [ "$django_site_name" = "$django_site_domain_old" ]; then
           # change site name only if it's unchanged so far
           django_site_name="$django_site_domain"
       fi

       $su_cmd "$django_admin shell $django_admin_args --command \
            \"from django.contrib.sites.models import Site; \
              one = Site.objects.all()[0]; \
              one.domain = '$django_site_domain'; \
              one.name = '$django_site_name'; \
              one.save()\"" www-data
    fi
}

create_django_superuser () {
    db_get mailman3-web/superuser-name
    su_name="$RET"
    db_get mailman3-web/superuser-mail
    su_mail="$RET"
    db_get mailman3-web/superuser-password
    su_password="$RET"

    if [ -n "$su_name" ] && [ -n "$su_mail" ] && [ -n "$su_password" ]; then
        /usr/share/mailman3-web/manage.py shell -c \
            "from django.contrib.auth.models import User; \
             User.objects.filter(username='$su_name').delete(); \
             User.objects.create_superuser('$su_name', \
             '$su_mail', '$su_password')"
    fi
}

case "$1" in
    configure)

        create_config

        if [ -n "$2" ]; then
            init_django
        else
            update_django
        fi

        config_django_site
        create_django_superuser

        # Handle webserver configuration/restart
        db_get mailman3-web/configure-webserver
        webservers="$RET"
        restart=""

        for webserver in $webservers; do
            webserver=${webserver%,}
            case "$webserver" in
                apache2)
                    apache_install
                    ;;
                nginx)
                    nginx_install
                    db_input high mailman3-web/nginx-choice || true
                    ;;
            esac
            pathfind $webserver || continue
            restart="$restart $webserver"
        done

        db_get mailman3-web/restart-webserver
        res="$RET"
        if [ "$res" = "true" ]; then
            for webserver in $restart; do
                webserver=${webserver%,}
                # Redirection of 3 is needed because Debconf uses it and it might
                # be inherited by webserver. See bug #446324.
                if pathfind invoke-rc.d; then
                    invoke-rc.d $webserver reload 3>/dev/null || true
                else
                    /etc/init.d/$webserver reload 3>/dev/null || true
                fi
            done
        fi

        db_stop
    ;;

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

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

# Automatically added by dh_installsystemd/11.1.6ubuntu1
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/mailman3-web.conf >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_installinit/11.1.6ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if [ -x "/etc/init.d/mailman3-web" ]; then
		update-rc.d mailman3-web defaults >/dev/null
		if [ -n "$2" ]; then
			_dh_action=restart
		else
			_dh_action=start
		fi
		invoke-rc.d mailman3-web $_dh_action || exit 1
	fi
fi
# End automatically added section
# Automatically added by dh_installsystemd/11.1.6ubuntu1
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 'mailman3-web.service' >/dev/null || true

	# was-enabled defaults to true, so new installations run enable.
	if deb-systemd-helper --quiet was-enabled 'mailman3-web.service'; then
		# Enables the unit on first installation, creates new
		# symlinks on upgrades if the unit file has changed.
		deb-systemd-helper enable 'mailman3-web.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 'mailman3-web.service' >/dev/null || true
	fi
fi
# End automatically added section


exit 0