This file is indexed.

postinst is in maas-region-controller 2.0.0~beta3+bzr4941-0ubuntu1.

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
#!/bin/sh

set -e

. /usr/share/debconf/confmodule
db_version 2.0

if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
    . /usr/share/dbconfig-common/dpkg/postinst.pgsql
fi

RELEASE=`lsb_release -rs` || RELEASE=""

maas_sync_migrate_db(){
    maas-region dbupgrade
}

restart_postgresql(){
    invoke-rc.d --force postgresql restart || true
}

configure_maas_default_url() {
    local ipaddr="$1"
    maas-region local_config_set \
        --maas-url "http://${ipaddr}/MAAS"
}

get_default_route_ip() {
    while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
    do
        [ "$Mask" = "00000000" ] && break
    done < /proc/net/route
    interface="$Iface"
    ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global)
    ipaddr=${ipaddr#* inet }
    ipaddr=${ipaddr%%/*}
    echo $ipaddr
}

extract_default_maas_url() {
    # Extract DEFAULT_MAAS_URL IP/host setting from config file $1.
    grep "^DEFAULT_MAAS_URL" "$1" | cut -d"/" -f3
}

configure_migrate_maas_dns() {
    # This only runs on upgrade. We only run this if the
    # there are forwarders to migrate or no
    # named.conf.options.inside.maas are present.
    maas-region edit_named_options \
        --migrate-conflicting-options --config-path \
        /etc/bind/named.conf.options
    invoke-rc.d bind9 restart || true
}

if [ "$1" = "configure" ] && [ -z "$2" ]; then
    #########################################################
    ##########  Configure DEFAULT_MAAS_URL  #################
    #########################################################

    # Obtain IP address of default route and change DEFAULT_MAAS_URL
    # if default-maas-url has not been preseeded.
    db_get maas/default-maas-url
    ipaddr="$RET"
    if [ -z "$RET" ]; then
        ipaddr=$(get_default_route_ip)
    fi
    # Set the IP address of the interface with default route
    if [ -n "$ipaddr" ]; then
        configure_maas_default_url "$ipaddr"
        db_subst maas/installation-note MAAS_URL "$ipaddr"
        db_set maas/default-maas-url "$ipaddr"
    fi

    #########################################################
    ################  Configure Database  ###################
    #########################################################

    # Need to for postgresql start so it doesn't fail on the installer
    restart_postgresql

    # Create the database
    dbc_go maas-region-controller $@
    maas-region local_config_set \
        --database-host "localhost" --database-name "$dbc_dbname" \
        --database-user "$dbc_dbuser" --database-pass "$dbc_dbpass"

    # Only syncdb if we have selected to install it with dbconfig-common.
    db_get maas-region-controller/dbconfig-install
    if [ "$RET" = "true" ]; then
        maas_sync_migrate_db
        configure_migrate_maas_dns
    fi

    db_get maas/username
    username="$RET"
    if [ -n "$username" ]; then
        db_get maas/password
        password="$RET"
        if [ -n "$password" ]; then
            maas-region createadmin --username "$username" --password "$password" --email "$username@maas"
        fi
    fi

    # Display installation note
    db_input low maas/installation-note || true
    db_go

elif [ -n "$DEBCONF_RECONFIGURE" ]; then
    # Set the IP address of the interface with default route
    db_get maas/default-maas-url
    ipaddr="$RET"
    if [ -n "$ipaddr" ]; then
        configure_maas_default_url "$ipaddr"
    fi

elif [ "$1" = "configure" ] && dpkg --compare-versions "$2" gt 0.1+bzr266+dfsg-0ubuntu1; then
    # If upgrading to any later package version, then upgrade db.
    invoke-rc.d apache2 stop || true

    # make sure postgresql is running
    restart_postgresql

    # If the version we are upgrading from ("$2") is less than
    # 1.9.0~alpha1+bzr4038-0ubuntu1 then we need migrate to new
    # config file.
    if dpkg --compare-versions "$2" lt 1.9.0~alpha1+bzr4038-0ubuntu1 && [ -f /etc/maas/maas_local_settings.py ]; then
        ipaddr=$(extract_default_maas_url /etc/maas/maas_local_settings.py)
        if [ -n "$ipaddr" ]; then
            configure_maas_default_url "$ipaddr"
            db_set maas/default-maas-url "$ipaddr"
        fi
        # handle database upgrade
        if [ -f /etc/dbconfig-common/maas-region-controller.conf ]; then
            # source dbconfig-common db config for maas-region-controller
            # before upgrading database, otherwise a new config is written
            # but the password is no longer preserved.
            . /etc/dbconfig-common/maas-region-controller.conf
        else
            dbc_go maas-region-controller $@
        fi

        # Reconfigure the config file.
        maas-region local_config_set \
            --database-host "localhost" --database-name "$dbc_dbname" \
            --database-user "$dbc_dbuser" --database-pass "$dbc_dbpass"

        mv /etc/maas/maas_local_settings.py /etc/maas/maas_local_settings.py.maas-old
    fi

    maas_sync_migrate_db

    configure_migrate_maas_dns
fi

systemctl enable maas-regiond >/dev/null || true
systemctl restart maas-regiond >/dev/null || true
invoke-rc.d apache2 restart || true

if [ -f /lib/systemd/system/maas-rackd.service ]; then
    systemctl restart maas-rackd >/dev/null || true
fi

db_stop