This file is indexed.

postinst is in rt4-extension-assettracker 3.0.0-1.

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

set -e

atdir=/usr/share/request-tracker4/plugins/RTx-AssetTracker
etcdir=$atdir/etc

upgrade_database ()
{
    echo "upgrading the RT database for Asset Tracker" 1>&2
    for dir in $etcdir/upgrade/*
    do
        for action in schema acl
        do
            run_setup_database $action $dir
        done
    done
    echo "Database upgrade done, see the RT (sys)log for details" 1>&2
}

setup_database ()
{
    echo "setting up the RT database for Asset Tracker" 1>&2
    for action in schema acl insert
    do
        run_setup_database $action $etcdir
    done
    echo "Database setup done, see the RT (sys)log for details" 1>&2
}

run_setup_database ()
{
    action=$1
    datadir=$2
    command="$atdir/sbin/rt-setup-database-debian -v 4 -- --action $action --datadir $datadir"

    if [ "$action" = "insert" ]
    then
	export PERLLIB=$atdir/lib
	command="$command --datafile $etcdir/initialdata"
    fi

    # cosmetics for the output
    base=$(basename $datadir)
    if [ "$base" = "etc" ]
    then
        base="Asset Tracker"
    fi
    echo -n "updating database $action for $base..." 1>&2

    run_command "$command"
}

run_command ()
{
    command="$1"
    local exitcode
    set +e
    output=$($command 2>&1 >/dev/null)
    exitcode=$?
    set -e
    if [ $exitcode != 0 ] #|| [ -n "$output" ]
    then
        echo "command failed with code $exitcode" 1>&2
        db_capb escape
        error=$(debconf-escape -e << EOF
database modification command "$command" exited with code $exitcode
Error messages follow:
$output
EOF
)
        db_subst rt4-extension-assettracker/modify-database-error error "$error"
        db_fset rt4-extension-assettracker/modify-database-error seen false
        db_input critical rt4-extension-assettracker/modify-database-error || true
        db_go || true
        db_get rt4-extension-assettracker/modify-database-error
        ERROR_CHOICE="$RET"
        if [ "$ERROR_CHOICE" = "abort" ]
        then
            echo "postinst script aborted" 1>&2
            exit 1
        fi
        if [ "$ERROR_CHOICE" = "retry" ]
        then
            echo "postinst script: retry to set up the database $action" 1>&2
            run_command $@
        fi
     else
        echo "OK" 1>&2
     fi
}

test_database ()
{
    local testresult
    testresult=0
    permission="$1"
    $atdir/sbin/test-database -v 4 2>/dev/null 1>&2 || testresult=$?
    set -e
    if [ "$permission" = "prompt" ] && \
       ( [ $testresult = 1 ] || [ $testresult = 2 ] )
    then
        case $testresult in
            1)
                db_fset rt4-extension-assettracker/setup-database-prompt seen false
                db_input high rt4-extension-assettracker/setup-database-prompt || true
                db_go
                db_get rt4-extension-assettracker/setup-database-prompt
                break
                ;;
            2)
                db_fset rt4-extension-assettracker/upgrade-database-prompt seen false
                db_input high rt4-extension-assettracker/upgrade-database-prompt || true
                db_go
                db_get rt4-extension-assettracker/upgrade-database-prompt
                break
                ;;
        esac
        if [ "$RET" = "false" ]
        then
            echo "database modification denied by the administrator" 1>&2
            return 0
        fi
    fi
    if [ $testresult = 255 ]
    then
        echo "Database state check failed, skipping modifications. Check your RT_SiteConfig.pm." 1>&2
    fi
    return $testresult
}

. /usr/share/debconf/confmodule

db_version 2.0

case "$1" in
    configure|reconfigure)
        db_get rt4-extension-assettracker/modify-database-permission
        CONFFILE=/etc/rt4-extension-assettracker/debian.conf
        MODIFY_DATABASE="unknown"
        if [ -r $CONFFILE ]
        then
            . $CONFFILE
        fi
        if [ "$RET" != "$MODIFY_DATABASE" ]
        then
            # rewrite the configuration file
            tmpfile=$(mktemp -t rt4-extension-assettracker.XXXXXXXX) || exit 1
            chmod 644 $tmpfile
            cat >$tmpfile << EOF
# automatically modify the database when needed?
# valid options are "allow", "deny" and "prompt"
MODIFY_DATABASE="${RET}"
EOF
            ucf --debconf-ok $tmpfile $CONFFILE
            rm $tmpfile
        fi

        if [ "$RET" != "deny" ]
        then
            retcode=0
            test_database $RET || retcode=$?
            case $retcode in
            1)
                setup_database
                ;;
            2)
                upgrade_database
                ;;
            esac
        fi
        db_stop

        # add the configuration file into the ucf registry
        if which ucfr >/dev/null 2>&1
        then
            ucfr rt4-extension-assettracker $CONFFILE
        fi

        break
        ;;
esac