8491: move files from arvados-dev into their new places
[arvados.git] / build / package-testing / test-package-arvados-sso-server.sh
1 #!/bin/bash
2
3 set -e
4
5 EXITCODE=0
6 DEBUG=${ARVADOS_DEBUG:-0}
7
8 STDOUT_IF_DEBUG=/dev/null
9 STDERR_IF_DEBUG=/dev/null
10 DASHQ_UNLESS_DEBUG=-q
11 if [[ "$DEBUG" != 0 ]]; then
12     STDOUT_IF_DEBUG=/dev/stdout
13     STDERR_IF_DEBUG=/dev/stderr
14     DASHQ_UNLESS_DEBUG=
15 fi
16
17 case "$TARGET" in
18     debian*|ubuntu*)
19         FORMAT=deb
20         ;;
21     centos6)
22         FORMAT=rpm
23         ;;
24     *)
25         echo -e "$0: Unknown target '$TARGET'.\n" >&2
26         exit 1
27         ;;
28 esac
29
30 if ! [[ -n "$WORKSPACE" ]]; then
31   echo >&2 "$helpmessage"
32   echo >&2
33   echo >&2 "Error: WORKSPACE environment variable not set"
34   echo >&2
35   exit 1
36 fi
37
38 if ! [[ -d "$WORKSPACE" ]]; then
39   echo >&2 "$helpmessage"
40   echo >&2
41   echo >&2 "Error: $WORKSPACE is not a directory"
42   echo >&2
43   exit 1
44 fi
45
46 title () {
47     txt="********** $1 **********"
48     printf "\n%*s%s\n\n" $((($COLUMNS-${#txt})/2)) "" "$txt"
49 }
50
51 checkexit() {
52     if [[ "$1" != "0" ]]; then
53         title "!!!!!! $2 FAILED !!!!!!"
54     fi
55 }
56
57
58 # Find the SSO server package
59
60 cd "$WORKSPACE"
61
62 if [[ ! -d "/var/www/arvados-sso" ]]; then
63   echo "/var/www/arvados-sso should exist"
64   exit 1
65 fi
66
67 if [[ ! -e "/etc/arvados/sso/application.yml" ]]; then
68     mkdir -p /etc/arvados/sso/
69     RANDOM_PASSWORD=`date | md5sum |cut -f1 -d' '`
70     cp config/application.yml.example /etc/arvados/sso/application.yml
71     sed -i -e 's/uuid_prefix: ~/uuid_prefix: zzzzz/' /etc/arvados/sso/application.yml
72     sed -i -e "s/secret_token: ~/secret_token: $RANDOM_PASSWORD/" /etc/arvados/sso/application.yml
73 fi
74
75 if [[ ! -e "/etc/arvados/sso/database.yml" ]]; then
76   # We need to set up our database configuration now.
77   if [[ "$FORMAT" == "rpm" ]]; then
78     # postgres packaging on CentOS6 is kind of primitive, needs an initdb
79     service postgresql initdb
80     if [ "$TARGET" = "centos6" ]; then
81       sed -i -e "s/127.0.0.1\/32          ident/127.0.0.1\/32          md5/" /var/lib/pgsql/data/pg_hba.conf
82       sed -i -e "s/::1\/128               ident/::1\/128               md5/" /var/lib/pgsql/data/pg_hba.conf
83     fi
84   fi
85   service postgresql start
86
87   RANDOM_PASSWORD=`date | md5sum |cut -f1 -d' '`
88   cat >/etc/arvados/sso/database.yml <<EOF
89 production:
90   adapter: postgresql
91   encoding: utf8
92   database: sso_provider_production
93   username: sso_provider_user
94   password: $RANDOM_PASSWORD
95   host: localhost
96 EOF
97
98   su postgres -c "psql -c \"CREATE USER sso_provider_user WITH PASSWORD '$RANDOM_PASSWORD'\""
99   su postgres -c "createdb sso_provider_production -O sso_provider_user"
100 fi
101
102 if [[ "$FORMAT" == "deb" ]]; then
103   # Test 2: the package should reconfigure cleanly
104   dpkg-reconfigure arvados-sso-server || EXITCODE=3
105
106   cd /var/www/arvados-sso/current/
107   /usr/local/rvm/bin/rvm-exec default bundle list >"$ARV_PACKAGES_DIR/arvados-sso-server.gems"
108
109   # Test 3: the package should remove cleanly
110   apt-get remove arvados-sso-server --yes || EXITCODE=3
111
112   checkexit $EXITCODE "apt-get remove arvados-sso-server --yes"
113
114   # Test 4: the package configuration should remove cleanly
115   dpkg --purge arvados-sso-server || EXITCODE=4
116
117   checkexit $EXITCODE "dpkg --purge arvados-sso-server"
118
119   if [[ -e "/var/www/arvados-sso" ]]; then
120     EXITCODE=4
121   fi
122
123   checkexit $EXITCODE "leftover items under /var/www/arvados-sso"
124
125   # Test 5: the package should remove cleanly with --purge
126
127   apt-get remove arvados-sso-server --purge --yes || EXITCODE=5
128
129   checkexit $EXITCODE "apt-get remove arvados-sso-server --purge --yes"
130
131   if [[ -e "/var/www/arvados-sso" ]]; then
132     EXITCODE=5
133   fi
134
135   checkexit $EXITCODE "leftover items under /var/www/arvados-sso"
136
137 elif [[ "$FORMAT" == "rpm" ]]; then
138
139   # Set up Nginx first
140   # (courtesy of https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/el6/install_passenger.html)
141   yum install -q -y epel-release pygpgme curl
142   curl --fail -sSLo /etc/yum.repos.d/passenger.repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
143   yum install -q -y nginx passenger
144   sed -i -e 's/^# passenger/passenger/' /etc/nginx/conf.d/passenger.conf
145   # Done setting up Nginx
146
147   # Test 2: the package should reinstall cleanly
148   yum --assumeyes reinstall arvados-sso-server || EXITCODE=3
149
150   cd /var/www/arvados-sso/current/
151   /usr/local/rvm/bin/rvm-exec default bundle list >$ARV_PACKAGES_DIR/arvados-sso-server.gems
152
153   # Test 3: the package should remove cleanly
154   yum -q -y remove arvados-sso-server || EXITCODE=3
155
156   checkexit $EXITCODE "yum -q -y remove arvados-sso-server"
157
158   if [[ -e "/var/www/arvados-sso" ]]; then
159     EXITCODE=3
160   fi
161
162   checkexit $EXITCODE "leftover items under /var/www/arvados-sso"
163
164 fi
165
166 if [[ "$EXITCODE" == "0" ]]; then
167   echo "Testing complete, no errors!"
168 else
169   echo "Errors while testing!"
170 fi
171
172 exit $EXITCODE