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