This file is indexed.

postinst is in maas-region-controller 2.4.0~beta2-6865-gec43e47e6-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
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
#!/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"
    # The given address is either "[IPv6_IP]" or "IPv4_IP" or "name", such as
    # [2001:db8::3:1]:5555 or 127.0.0.1 or maas.example.com.
    # The ugly sed splits the given thing as:
    #   (string of anything but ":", or [ipv6_ip]),
    #   optionally followed by :port.
    local address=$(echo "$ipaddr" |
        sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\1/p')
    local port=$(echo "$ipaddr" |
        sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\2/p')
    test -n "$port" || port=":5240"
    ipaddr="${ipaddr}${port}"
    maas-region local_config_set --maas-url "http://${ipaddr}/MAAS"
}

get_default_route_ip6() {
    while read Src SrcPref Dest DestPref Gateway Metric RefCnt Use Flags Iface
    do
        [ "$SrcPref" = 00 ] && [ "$Iface" != lo ] && break
    done < /proc/net/ipv6_route
    if [ -n "$Iface" ]; then
        LC_ALL=C /sbin/ip -6 addr list dev "$Iface" scope global permanent |
            sed -n '/ inet6 /s/.*inet6 \([0-9a-fA-F:]*\).*/[\1]/p' | head -1
    fi
}

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

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.  Prefer ipv4 addresses if
    # present, and use "localhost" only if there is no default route in either
    # address family.
    db_get maas/default-maas-url
    ipaddr="$RET"
    if [ -z "$ipaddr" ]; then
        ipaddr=$(get_default_route_ip4)
    fi
    if [ -z "$ipaddr" ]; then
        ipaddr=$(get_default_route_ip6)
    fi
    # Fallback default is "localhost"
    if [ -z "$ipaddr" ]; then
        ipaddr=localhost
    fi
    # Set the IP address of the interface with default route
    configure_maas_default_url "$ipaddr"
    db_subst maas/installation-note MAAS_URL "$ipaddr"
    db_set maas/default-maas-url "$ipaddr"

    #########################################################
    ################  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-port 5432 --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.
    # 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-port 5432 --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

deb-systemd-invoke enable maas-regiond >/dev/null || true
deb-systemd-invoke restart maas-regiond >/dev/null || true

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

db_stop