Add 'build/' from commit '555b039609a3c8700c27767c255fdfe00eb42063'
[arvados.git] / build / jenkins / run-build-packages-sso.sh
1 #!/bin/bash
2
3 JENKINS_DIR=$(dirname $(readlink -e "$0"))
4 . "$JENKINS_DIR/run-library.sh"
5
6 read -rd "\000" helpmessage <<EOF
7 $(basename $0): Build Arvados SSO server package
8
9 Syntax:
10         WORKSPACE=/path/to/arvados-sso $(basename $0) [options]
11
12 Options:
13
14 --debug
15     Output debug information (default: false)
16 --target
17     Distribution to build packages for (default: debian7)
18
19 WORKSPACE=path         Path to the Arvados SSO source tree to build packages from
20
21 EOF
22
23 EXITCODE=0
24 DEBUG=${ARVADOS_DEBUG:-0}
25 TARGET=debian7
26
27 PARSEDOPTS=$(getopt --name "$0" --longoptions \
28     help,build-bundle-packages,debug,target: \
29     -- "" "$@")
30 if [ $? -ne 0 ]; then
31     exit 1
32 fi
33
34 eval set -- "$PARSEDOPTS"
35 while [ $# -gt 0 ]; do
36     case "$1" in
37         --help)
38             echo >&2 "$helpmessage"
39             echo >&2
40             exit 1
41             ;;
42         --target)
43             TARGET="$2"; shift
44             ;;
45         --debug)
46             DEBUG=1
47             ;;
48         --test-packages)
49             test_packages=1
50             ;;
51         --)
52             if [ $# -gt 1 ]; then
53                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
54                 exit 1
55             fi
56             ;;
57     esac
58     shift
59 done
60
61 STDOUT_IF_DEBUG=/dev/null
62 STDERR_IF_DEBUG=/dev/null
63 DASHQ_UNLESS_DEBUG=-q
64 if [[ "$DEBUG" != 0 ]]; then
65     STDOUT_IF_DEBUG=/dev/stdout
66     STDERR_IF_DEBUG=/dev/stderr
67     DASHQ_UNLESS_DEBUG=
68 fi
69
70 case "$TARGET" in
71     debian7)
72         FORMAT=deb
73         ;;
74     debian8)
75         FORMAT=deb
76         ;;
77     ubuntu1204)
78         FORMAT=deb
79         ;;
80     ubuntu1404)
81         FORMAT=deb
82         ;;
83     centos6)
84         FORMAT=rpm
85         ;;
86     *)
87         echo -e "$0: Unknown target '$TARGET'.\n" >&2
88         exit 1
89         ;;
90 esac
91
92 if ! [[ -n "$WORKSPACE" ]]; then
93   echo >&2 "$helpmessage"
94   echo >&2
95   echo >&2 "Error: WORKSPACE environment variable not set"
96   echo >&2
97   exit 1
98 fi
99
100 if ! [[ -d "$WORKSPACE" ]]; then
101   echo >&2 "$helpmessage"
102   echo >&2
103   echo >&2 "Error: $WORKSPACE is not a directory"
104   echo >&2
105   exit 1
106 fi
107
108 # Test for fpm
109 fpm --version >/dev/null 2>&1
110
111 if [[ "$?" != 0 ]]; then
112     echo >&2 "$helpmessage"
113     echo >&2
114     echo >&2 "Error: fpm not found"
115     echo >&2
116     exit 1
117 fi
118
119 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
120 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
121 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
122     # error; for some reason, the path is not accessible
123     # to the script (e.g. permissions re-evaled after suid)
124     exit 1  # fail
125 fi
126
127 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
128 debug_echo "Workspace is $WORKSPACE"
129
130 if [[ -f /etc/profile.d/rvm.sh ]]; then
131     source /etc/profile.d/rvm.sh
132     GEM="rvm-exec default gem"
133 else
134     GEM=gem
135 fi
136
137 # Make all files world-readable -- jenkins runs with umask 027, and has checked
138 # out our git tree here
139 chmod o+r "$WORKSPACE" -R
140
141 # More cleanup - make sure all executables that we'll package are 755
142 # No executables in the sso server package
143 #find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
144
145 # Now fix our umask to something better suited to building and publishing
146 # gems and packages
147 umask 0022
148
149 debug_echo "umask is" `umask`
150
151 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
152     mkdir -p "$WORKSPACE/packages/$TARGET"
153 fi
154
155 # Build the SSO server package
156 handle_rails_package arvados-sso-server "$WORKSPACE" \
157                      "$WORKSPACE/LICENCE" --url="https://arvados.org" \
158                      --description="Arvados SSO server - Arvados is a free and open source platform for big data science." \
159                      --license="Expat license"
160
161 exit $EXITCODE