/
travis_before_script.sh
executable file
·163 lines (132 loc) · 4.11 KB
/
travis_before_script.sh
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/bash -e
# -----------------------------------------------------------------------------
# MantisBT Travis-CI before script
# -----------------------------------------------------------------------------
# Global variables initialization
HOSTNAME=localhost
# Port 80 requires use of 'sudo' to run the PHP built-in web server, which
# causes builds to fail due to a bug in Travis [1]so we use port 8080 instead.
# [1] https://github.com/travis-ci/travis-ci/issues/2235
PORT=8080
MANTIS_DB_NAME=bugtracker
MANTIS_BOOTSTRAP=tests/bootstrap.php
MANTIS_CONFIG=config/config_inc.php
SQL_CREATE_DB="CREATE DATABASE $MANTIS_DB_NAME;"
SQL_CREATE_PROJECT="INSERT INTO mantis_project_table
(name, inherit_global, description)
VALUES
('Test Project',true,'Travis-CI Test Project');"
# -----------------------------------------------------------------------------
function step () {
echo "-----------------------------------------------------------------------------"
echo $1
echo
}
# -----------------------------------------------------------------------------
step "Create database $MANTIS_DB_NAME"
case $DB in
mysql)
DB_TYPE='mysqli'
DB_USER='root'
DB_PASSWORD=''
DB_CMD='mysql -e'
DB_CMD_SCHEMA="$MANTIS_DB_NAME"
$DB_CMD "$SQL_CREATE_DB"
;;
pgsql)
DB_TYPE='pgsql'
DB_USER='postgres'
DB_PASSWORD=''
DB_CMD="psql -U $DB_USER -c"
DB_CMD_SCHEMA="-d $MANTIS_DB_NAME"
# Wait a bit to make sure Postgres has started
sleep 5
$DB_CMD "$SQL_CREATE_DB"
$DB_CMD "ALTER USER $DB_USER SET bytea_output = 'escape';"
;;
esac
# -----------------------------------------------------------------------------
step "Web server setup"
if [ $TRAVIS_PHP_VERSION = '5.3' ]; then
# install Apache as PHP 5.3 does not come with an embedded web server
sudo apt-get update -qq
sudo apt-get install -qq apache2 libapache2-mod-php5 php5-mysql php5-pgsql
cat <<-EOF | sudo tee /etc/apache2/sites-available/default >/dev/null
Listen $PORT
NameVirtualHost *:$PORT
<VirtualHost *:$PORT>
DocumentRoot $PWD
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory $PWD>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
EOF
sudo service apache2 restart
else
# use PHP's embedded server
if [[ $PORT = 80 ]]
then
# sudo required for port 80
# get path of PHP as the path is not in $PATH for sudo
myphp="sudo $(which php)"
else
myphp=php
fi
$myphp -S $HOSTNAME:$PORT &
fi
# needed to allow web server to create config_inc.php
chmod 777 config
# wait until server is up
sleep 10
# -----------------------------------------------------------------------------
step "MantisBT Installation"
# Define parameters for MantisBT installer
declare -A query=(
[install]=2
[db_type]=$DB_TYPE
[hostname]=$HOSTNAME
[database_name]=$MANTIS_DB_NAME
[db_username]=$DB_USER
[db_password]=$DB_PASSWORD
[admin_username]=$DB_USER
[admin_password]=$DB_PASSWORD
[timezone]=UTC
)
# Build http query string
unset query_string
for param in "${!query[@]}"
do
value=${query[$param]}
query_string="${query_string}&${param}=${value}"
done
# trigger installation
curl --data "${query_string:1}" http://$HOSTNAME:$PORT/admin/install.php
# -----------------------------------------------------------------------------
step "Post-installation steps"
echo "Creating project"
$DB_CMD "$SQL_CREATE_PROJECT" $DB_CMD_SCHEMA
# enable SOAP tests
echo "Creating PHPUnit Bootstrap file"
cat <<-EOF >> $MANTIS_BOOTSTRAP
<?php
\$GLOBALS['MANTIS_TESTSUITE_SOAP_ENABLED'] = true;
\$GLOBALS['MANTIS_TESTSUITE_SOAP_HOST'] = 'http://$HOSTNAME:$PORT/api/soap/mantisconnect.php?wsdl';
EOF
echo "Adding custom configuration options"
sudo chmod 777 $MANTIS_CONFIG
cat <<-EOF >> $MANTIS_CONFIG
# Configs required to ensure all PHPUnit tests are executed
\$g_allow_no_category = ON;
\$g_due_date_update_threshold = DEVELOPER;
\$g_due_date_view_threshold = DEVELOPER;
\$g_enable_project_documentation = ON;
\$g_time_tracking_enabled = ON;
EOF
step "Before-script execution completed successfully"