Steal Travis-CI setup from DBIx::Class
[dbsrgits/DBIx-Class-Schema-Loader.git] / maint / travis-ci_scripts / 10_before_install.bash
1 #!/bin/bash
2
3 source maint/travis-ci_scripts/common.bash
4 if [[ -n "$SHORT_CIRCUIT_SMOKE" ]] ; then return ; fi
5
6 # Different boxes we run on may have different amount of hw threads
7 # Hence why we need to query
8 # Originally we used to read /sys/devices/system/cpu/online
9 # but it is not available these days (odd). Thus we fall to
10 # the alwas-present /proc/cpuinfo
11 # The oneliner is a tad convoluted - basicaly what we do is
12 # slurp the entire file and get the index off the last
13 # `processor    : XX` line
14 export NUMTHREADS="$(( $(perl -0777 -n -e 'print (/ (?: .+ ^ processor \s+ : \s+ (\d+) ) (?! ^ processor ) /smx)' < /proc/cpuinfo) + 1 ))"
15
16 export CACHE_DIR="/tmp/poormanscache"
17
18 # install some common tools from APT, more below unless CLEANTEST
19 apt_install libapp-nopaste-perl tree apt-transport-https
20
21 # FIXME - the debian package is oddly broken - uses a bin/env based shebang
22 # so nothing works under a brew. Fix here until #debian-perl patches it up
23 sudo /usr/bin/perl -p -i -e 's|#!/usr/bin/env perl|#!/usr/bin/perl|' $(which nopaste)
24
25 if [[ "$CLEANTEST" != "true" ]]; then
26 ### apt-get invocation - faster to grab everything at once
27   #
28   # FIXME these debconf lines should automate the firebird config but do not :(((
29   sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/enabled\tboolean\ttrue" | debconf-set-selections'
30   sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/sysdba_password/new_password\tpassword\t123" | debconf-set-selections'
31
32   # add extra APT repo for Oracle
33   # (https is critical - apt-get update can't seem to follow the 302)
34   sudo bash -c 'echo -e "\ndeb [arch=i386] https://oss.oracle.com/debian unstable main non-free" >> /etc/apt/sources.list'
35
36   run_or_err "Cloning poor man's cache from github" "git clone --depth=1 --branch=poor_mans_travis_cache https://github.com/ribasushi/travis_futzing.git $CACHE_DIR && $CACHE_DIR/reassemble"
37
38   run_or_err "Priming up the APT cache with $(echo $(ls -d $CACHE_DIR/apt_cache/*.deb))" "sudo cp $CACHE_DIR/apt_cache/*.deb /var/cache/apt/archives"
39
40   apt_install memcached firebird2.5-super firebird2.5-dev unixodbc-dev expect oracle-xe
41
42 ### config memcached
43   run_or_err "Starting memcached" "sudo /etc/init.d/memcached start"
44   export DBICTEST_MEMCACHED=127.0.0.1:11211
45
46 ### config mysql
47   run_or_err "Creating MySQL TestDB" "mysql -e 'create database dbic_test;'"
48   export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
49   export DBICTEST_MYSQL_USER=root
50
51 ### config pg
52   run_or_err "Creating PostgreSQL TestDB" "psql -c 'create database dbic_test;' -U postgres"
53   export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
54   export DBICTEST_PG_USER=postgres
55
56 ### conig firebird
57   # poor man's deb config
58   EXPECT_FB_SCRIPT='
59     spawn dpkg-reconfigure --frontend=text firebird2.5-super
60     expect "Enable Firebird server?"
61     send "\177\177\177\177yes\r"
62     expect "Password for SYSDBA"
63     send "123\r"
64     sleep 1
65     expect eof
66   '
67   # creating testdb
68   # FIXME - this step still fails from time to time >:(((
69   # has to do with the FB reconfiguration I suppose
70   # for now if it fails twice - simply skip FB testing
71   for i in 1 2 ; do
72
73     run_or_err "Re-configuring Firebird" "
74       sync
75       DEBIAN_FRONTEND=text sudo expect -c '$EXPECT_FB_SCRIPT'
76       sleep 1
77       sync
78       # restart the server for good measure
79       sudo /etc/init.d/firebird2.5-super stop || true
80       sleep 1
81       sync
82       sudo /etc/init.d/firebird2.5-super start
83       sleep 1
84       sync
85     "
86
87     if run_or_err "Creating Firebird TestDB" \
88       "echo \"CREATE DATABASE '/var/lib/firebird/2.5/data/dbic_test.fdb';\" | sudo isql-fb -u sysdba -p 123"
89     then
90
91       run_or_err "Fetching and building Firebird ODBC driver" '
92         cd "$(mktemp -d)"
93         wget -qO- http://sourceforge.net/projects/firebird/files/firebird-ODBC-driver/2.0.2-Release/OdbcFb-Source-2.0.2.153.gz/download | tar -zx
94         cd Builds/Gcc.lin
95         perl -p -i -e "s|/usr/lib64|/usr/lib/x86_64-linux-gnu|g" ../makefile.environ
96         make -f makefile.linux
97         sudo make -f makefile.linux install
98       '
99
100       sudo bash -c 'cat >> /etc/odbcinst.ini' <<< "
101 [Firebird]
102 Description     = InterBase/Firebird ODBC Driver
103 Driver          = /usr/lib/x86_64-linux-gnu/libOdbcFb.so
104 Setup           = /usr/lib/x86_64-linux-gnu/libOdbcFb.so
105 Threading       = 1
106 FileUsage       = 1
107 "
108
109       export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
110       export DBICTEST_FIREBIRD_USER=SYSDBA
111       export DBICTEST_FIREBIRD_PASS=123
112
113       export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
114       export DBICTEST_FIREBIRD_INTERBASE_USER=SYSDBA
115       export DBICTEST_FIREBIRD_INTERBASE_PASS=123
116
117       export DBICTEST_FIREBIRD_ODBC_DSN="dbi:ODBC:Driver=Firebird;Dbname=/var/lib/firebird/2.5/data/dbic_test.fdb"
118       export DBICTEST_FIREBIRD_ODBC_USER=SYSDBA
119       export DBICTEST_FIREBIRD_ODBC_PASS=123
120
121       break
122     fi
123
124   done
125
126 ### config oracle
127   SRV_ORA_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
128
129   # without this some of the more zealous tests can exhaust the amount
130   # of listeners and oracle is too slow to spin extras up :(
131   sudo bash -c "echo -e '\nprocesses=150' >> $SRV_ORA_HOME/config/scripts/init.ora"
132
133   EXPECT_ORA_SCRIPT='
134     spawn /etc/init.d/oracle-xe configure
135
136     sleep 1
137     set send_slow {1 .005}
138
139     expect "Specify the HTTP port that will be used for Oracle Application Express"
140     sleep 0.5
141     send -s "8021\r"
142
143     expect "Specify a port that will be used for the database listener"
144     sleep 0.5
145     send -s "1521\r"
146
147     expect "Specify a password to be used for database accounts"
148     sleep 0.5
149     send -s "adminpass\r"
150
151     expect "Confirm the password"
152     sleep 0.5
153     send -s "adminpass\r"
154
155     expect "Do you want Oracle Database 10g Express Edition to be started on boot"
156     sleep 0.5
157     send -s "n\r"
158
159     sleep 0.5
160     expect "Configuring Database"
161
162     sleep 1
163     expect eof
164     wait
165   '
166
167   # if we do not redirect to some random file, but instead try to capture
168   # into a var the way run_or_err does - everything hangs
169   # FIXME: I couldn't figure it out after 3 hours of headdesking,
170   # would be nice to know the reason eventually
171   run_or_err "Configuring OracleXE" "sudo $(which expect) -c '$EXPECT_ORA_SCRIPT' &>/tmp/ora_configure_10.2.log"
172
173   export DBICTEST_ORA_DSN=dbi:Oracle://localhost:1521/XE
174   export DBICTEST_ORA_USER=dbic_test
175   export DBICTEST_ORA_PASS=abc123456
176   export DBICTEST_ORA_EXTRAUSER_DSN="$DBICTEST_ORA_DSN"
177   export DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
178   export DBICTEST_ORA_EXTRAUSER_PASS=abc123456
179
180   run_or_err "Create Oracle users" "ORACLE_SID=XE ORACLE_HOME=$SRV_ORA_HOME $SRV_ORA_HOME/bin/sqlplus -L -S system/adminpass @/dev/stdin <<< '
181     CREATE USER $DBICTEST_ORA_USER IDENTIFIED BY $DBICTEST_ORA_PASS;
182     GRANT connect,resource TO $DBICTEST_ORA_USER;
183     CREATE USER $DBICTEST_ORA_EXTRAUSER_USER IDENTIFIED BY $DBICTEST_ORA_EXTRAUSER_PASS;
184     GRANT connect,resource TO $DBICTEST_ORA_EXTRAUSER_USER;
185   '"
186
187   export ORACLE_HOME="$CACHE_DIR/ora_instaclient/x86-64/oracle_instaclient_10.2.0.5.0"
188 fi