File: mailman3.postinst

package info (click to toggle)
mailman3 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,808 kB
  • sloc: python: 39,280; sh: 279; makefile: 24
file content (126 lines) | stat: -rw-r--r-- 3,880 bytes parent folder | download
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
#!/bin/sh

set -e

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

# Set permissions for sqlite3 file
dbc_dbfile_owner="list:list"
dbc_dbfile_perms="0660"

dbc_go mailman3 "$@"

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

upgrade_fixes () {
    version="$(dpkg -s $DPKG_MAINTSCRIPT_PACKAGE | sed -n 's/^Version: //p')"
    if dpkg --compare-versions "$version" le "3.1.1-7"; then
        ucfr --force mailman3 /etc/mailman3/mailman.cfg
    fi
}

init_service_failed () {
    db_input high mailman3/init_service_failed || true
    db_go
}

# 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
    mailmancfg_new=`tempfile -m 0640`
    cp -a /usr/share/mailman3/mailman.cfg.sample $mailmancfg_new

    # get database settings from dbconfig-common
    if [ -f /etc/dbconfig-common/mailman3.conf ]; then
        . /etc/dbconfig-common/mailman3.conf

        # Comment out default database settings if dbconfig is used
        sed -i -e 's|^\s*class: mailman\.database\..*$|#&|' \
            $mailmancfg_new
        sed -i -e 's|^\s*url: [a-z+]\+://.*$|#&|' \
            $mailmancfg_new
    fi

    case "$dbc_dbtype" in
        pgsql)
            sed -i -e 's|^#\?\s*\(class: mailman\.database\.postgresql\.PostgreSQLDatabase\)$|\1|' \
                $mailmancfg_new
            sed -i -e "s|^#\?\s*url: postgres://.*$|url: postgres://$dbc_dbuser:$dbc_dbpass@$dbc_dbserver/$dbc_dbname|" \
                $mailmancfg_new
            ;;
        mysql)
            sed -i -e 's|^#\?\s*\(class: mailman\.database\.mysql\.MySQLDatabase\)|\1|' \
                $mailmancfg_new
            sed -i -e "s|^#\?\s*url: mysql+pymysql://.*$|url: mysql+pymysql://$dbc_dbuser:$dbc_dbpass@$dbc_dbserver/$dbc_dbname?charset=utf8\&use_unicode=1|" \
                $mailmancfg_new
            ;;
        sqlite3)
            sed -i -e 's|^#\?\s*\(class: mailman\.database\.sqlite\.SQLiteDatabase\)$|\1|' \
                $mailmancfg_new
            sed -i -e 's|^#\?\s*url: sqlite:///.*$|url: sqlite:///$DATA_DIR/mailman.db|' \
                $mailmancfg_new
            ;;
        "")
            ;;
        *)
            echo "Unsupported database type $dbc_type."
            exit 1
            ;;
    esac

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

    # Set new admin_pass in mailman.cfg
    sed -i -e "s|^\(\s*admin_pass:\s*\)\S\+$|\1$admin_pass|" $mailmancfg_new

    db_get mailman3/config_hyperkitty
    res="$RET"
    if [ "$res" = "true" ]; then
        cat /usr/share/mailman3/mailman_cfg_hyperkitty_snippet.cfg \
            >>$mailmancfg_new
    fi

    # Register new config file
    ucf --three-way --debconf-ok "$mailmancfg_new" /etc/mailman3/mailman.cfg
    ucfr mailman3 /etc/mailman3/mailman.cfg
    chmod 0640 /etc/mailman3/mailman.cfg
    chown root:list /etc/mailman3/mailman.cfg
    rm -f $mailmancfg_new
}

case "$1" in
    configure)
        upgrade_fixes
        create_config
    ;;

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

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

#DEBHELPER#

db_stop
exit 0