Corrects logic to determine if audit logging is enabled.
[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     debian9)
78         FORMAT=deb
79         ;;
80     ubuntu1204)
81         FORMAT=deb
82         ;;
83     ubuntu1404)
84         FORMAT=deb
85         ;;
86     ubuntu1604)
87         FORMAT=deb
88         ;;
89     centos7)
90         FORMAT=rpm
91         ;;
92     *)
93         echo -e "$0: Unknown target '$TARGET'.\n" >&2
94         exit 1
95         ;;
96 esac
97
98 if ! [[ -n "$WORKSPACE" ]]; then
99   echo >&2 "$helpmessage"
100   echo >&2
101   echo >&2 "Error: WORKSPACE environment variable not set"
102   echo >&2
103   exit 1
104 fi
105
106 if ! [[ -d "$WORKSPACE" ]]; then
107   echo >&2 "$helpmessage"
108   echo >&2
109   echo >&2 "Error: $WORKSPACE is not a directory"
110   echo >&2
111   exit 1
112 fi
113
114 # Test for fpm
115 fpm --version >/dev/null 2>&1
116
117 if [[ "$?" != 0 ]]; then
118     echo >&2 "$helpmessage"
119     echo >&2
120     echo >&2 "Error: fpm not found"
121     echo >&2
122     exit 1
123 fi
124
125 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
126 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
127 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
128     # error; for some reason, the path is not accessible
129     # to the script (e.g. permissions re-evaled after suid)
130     exit 1  # fail
131 fi
132
133 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
134 debug_echo "Workspace is $WORKSPACE"
135
136 if [[ -f /etc/profile.d/rvm.sh ]]; then
137     source /etc/profile.d/rvm.sh
138     GEM="rvm-exec default gem"
139 else
140     GEM=gem
141 fi
142
143 # Make all files world-readable -- jenkins runs with umask 027, and has checked
144 # out our git tree here
145 chmod o+r "$WORKSPACE" -R
146
147 # More cleanup - make sure all executables that we'll package are 755
148 # No executables in the sso server package
149 #find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
150
151 # Now fix our umask to something better suited to building and publishing
152 # gems and packages
153 umask 0022
154
155 debug_echo "umask is" `umask`
156
157 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
158     mkdir -p "$WORKSPACE/packages/$TARGET"
159 fi
160
161 # Build the SSO server package
162 handle_rails_package arvados-sso-server "$WORKSPACE" \
163                      "$WORKSPACE/LICENCE" --url="https://arvados.org" \
164                      --description="Arvados SSO server - Arvados is a free and open source platform for big data science." \
165                      --license="Expat license"
166
167 exit $EXITCODE