File: config

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (149 lines) | stat: -rw-r--r-- 4,404 bytes parent folder | download | duplicates (3)
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
#!/bin/bash -e
# Debconf script for phpwiki, written by Matt Brown <debian@mattb.net.nz>
# This script is released under the terms of the GPL version 2.
. /usr/share/debconf/confmodule
db_capb backup

# Write a script for loading the dbconfig from config.ini into a tempfile
loadscript=`tempfile`
cat > $loadscript << __EOF__
#!/bin/bash -e
# phpwiki database configuration load script
dbc_dbuser=''
dbc_dbpass=''
dbc_basepath=''
dbc_dbname=''
dbc_dbserver=''
dbc_dbport=''
dbc_dbtype=''

function print_results
{
    echo "dbc_dbuser='\$dbc_dbuser'"
    echo "dbc_dbpass='\$dbc_dbpass'"
    echo "dbc_basepath='\$dbc_basepath'"
    echo "dbc_dbname='\$dbc_dbname'"
    echo "dbc_dbserver='\$dbc_dbserver'"
    echo "dbc_dbport='\$dbc_dbport'"
    echo "dbc_dbtype='\$dbc_dbtype'"
}

n=\`egrep "^[[:space:]]*DATABASE_TYPE[[:space:]]*=[[:space:]]*dba" \
    /etc/phpwiki/config.ini | wc -l | sed 's/ //g'\`
if [ "\$n" -ne "0" ]; then
    # Still using DBA, dbconfig-common can't help us much...
    print_results
    exit 1
fi

dsn=\`grep "^[\w]*DATABASE_DSN" /etc/phpwiki/config.ini | cut -f2 -d'='\`
dsn=\`echo "\$dsn" | tr -d '" '\`

# Extract the database type
dbc_dbtype=\`echo "\$dsn" | cut -f1 -d':'\`
dsn=\`echo "\$dsn" | cut -f2- -d':' | sed 's#^//##g' | sed 's#^//#/#g'\`

if [ "\$dbc_dbtype" = "sqlite" ]; then
    # Break into basepath and database filename
    dbc_basepath=\`dirname \$dsn\`
    dbc_dbname=\`basename \$dsn\`
else
    # DSN in format <dbtype>://[user[:pass]@]<host>[:port]/<dbname>
    # May have username/password to extract
    if echo "\$dsn" | grep -q "@"; then
        # We have at least a username
        auth=\`echo "\$dsn" | cut -f1 -d'@'\`
        if echo "\$auth" | grep -q ":"; then
            # Username and password
            dbc_dbuser=\`echo "\$auth" | cut -f1 -d':'\`
            dbc_dbpass=\`echo "\$auth" | cut -f2 -d':'\`
        else
            dbc_dbuser="\$auth"
        fi
        dsn=\`echo "\$dsn" | cut -f2 -d'@'\`
    fi
    # Up to the next / is the host and port
    host=\`echo "\$dsn" | cut -f1 -d'/'\`
    if echo "\$host" | grep -q ":"; then
        # Host and port
        dbc_dbserver=\`echo "\$host" | cut -f1 -d':'\`
        dbc_dbport=\`echo "\$host" | cut -f2 -d':'\`
    else
        dbc_dbserver="\$host"
    fi
    # And finally the db name
    dbc_dbname=\`echo "\$dsn" | cut -f2 -d'/'\`
fi

print_results
exit 0
__EOF__
chmod +x $loadscript

# Prepare for using dbconfig-common
if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
    dbc_dbtypes='mysql, pgsql, sqlite'
    dbc_first_version='1.3.12p3-2'
    dbc_load_include="exec:$loadscript"
    . /usr/share/dbconfig-common/dpkg/config
fi

STATE=1
while true; do
    case "$STATE" in
    1)
        # Introduction
        db_input low phpwiki/notes/introduction || true
        ;;
    2)
        # Database setup
        if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
            dbc_go phpwiki $@
        fi
        ;;
    3)
        # Document root
        db_input high phpwiki/system/documentroot || true
        ;;
    4)
        # Accessibility
        db_title "Access Control" || true
        db_input medium phpwiki/system/accessible || true
        ;;
    5)
        # Prompt for the local network if necessary
        db_get phpwiki/system/accessible
        if [ "$RET" = "local network" ]; then
            db_title "Access Control" || true
            db_input critical phpwiki/system/localnet || true
        fi
        ;;
    *)
        # The default case catches when $STATE is greater than the
        # last implemented state, and breaks out of the loop. This
        # requires that states be numbered consecutively from 1
        # with no gaps, as the default case will also be entered
        # if there is a break in the numbering
        break # exits the enclosing "while" loop      ;;
    esac
    
    if db_go; then
        STATE=$(($STATE + 1))
    else
        STATE=$(($STATE - 1))
    fi
done

# Done with the loadscript now
rm -f $loadscript

if [ $STATE -eq 1 ]; then
    # The user has asked to back up from the first
    # question. This case is problematical. Regular
    # dpkg and apt package installation isn’t capable
    # of backing up questions between packages as this
    # is written, so this will exit leaving the package
    # unconfigured - probably the best way to handle
    # the situation.
    exit 10
fi