summaryrefslogtreecommitdiffstats
path: root/pki/ipa/config-ext/build_ipa_pki
blob: 1ed090f1036c2fef89418767107e7909c8dc7eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
# BEGIN COPYRIGHT BLOCK
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# (C) 2007 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK

# Always switch into the base directory above this
# shared shell script prior to executing it so that
# all of its output is written to this directory
cd `dirname $0`/..

# Set pre-defined variables
#
# NOTE:  Variables prefixed with "IPA" are defined in the invoking script.
#        Variables prefixed with "PKI" are defined in this shared script.
#        Variables containing no prefix are reserved for the generated script.
#
PKI_ABORT_SCRIPT="false"
PKI_BASEDIR="../../.."
PKI_BUILD_XML=build.xml
PKI_DIR=pki
PKI_IPA_DIR=ipa
PKI_RELEASE_DIR=release
PKI_RELEASE_SCRIPT=release
PKI_SHARED_SCRIPT=`basename $0`
PKI_SRC_DIR=base

# Check the values of the passed-in environment variables
if [ "${IPA_BUILD_SCRIPT}" == "" ]; then
    printf "ERROR:  The 'IPA_BUILD_SCRIPT' environment variable is undefined!\n"
    PKI_ABORT_SCRIPT="true"
fi
if [ "${IPA_COMPONENT}" == "" ]; then
    printf "ERROR:  The 'IPA_COMPONENT' environment variable is undefined!\n"
    PKI_ABORT_SCRIPT="true"
fi
if [ "${IPA_SPECFILE}" == "" ]; then
    printf "ERROR:  The 'IPA_SPECFILE' environment variable is undefined!\n"
    PKI_ABORT_SCRIPT="true"
fi
if [ "${PKI_ABORT_SCRIPT}" == "true" ]; then
    printf "\n"
    printf "The '${PKI_SHARED_SCRIPT}' shared build script MUST be invoked by "
    printf "a\nPKI component-specific build script (e. g. - '${IPA_BUILD_SCRIPT}')\n"
    printf "which defines ALL environment variables prefixed by 'IPA'!\n"
    exit 255
fi

# Compute remaining variables by assigning their values from the specfile
PKI_SOURCE_CODE_URL="https://pki.fedoraproject.org/svn/pki/trunk/${PKI_DIR}/${PKI_SRC_DIR}/${IPA_COMPONENT}"
if [ "${PKI_PRODUCT_UI_FLAVOR_PREFIX}" != "" ]; then
    PKI_PRODUCT_BUILD_XML="${PKI_BUILD_XML}"
    PKI_PRODUCT_NAME="${PKI_PRODUCT_UI_FLAVOR_PREFIX}-${PKI_PRODUCT_PREFIX}-${PKI_PRODUCT}"
    PKI_PRODUCT_SOURCE_PATH="${PKI_DIR}/${PKI_IPA_DIR}/${IPA_COMPONENT}"
elif [ "${PKI_PRODUCT_PREFIX}" != "" ]; then
    PKI_PRODUCT_BUILD_XML="${PKI_BASEDIR}/${PKI_DIR}/${PKI_SRC_DIR}/${IPA_COMPONENT}/${PKI_BUILD_XML}"
    PKI_PRODUCT_NAME="${PKI_PRODUCT_PREFIX}-${PKI_PRODUCT}"
    PKI_PRODUCT_SOURCE_PATH="${PKI_DIR}/${PKI_SRC_DIR}/${IPA_COMPONENT}"
else
    PKI_PRODUCT_BUILD_XML="${PKI_BASEDIR}/${PKI_DIR}/${PKI_SRC_DIR}/${IPA_COMPONENT}/${PKI_BUILD_XML}"
    PKI_PRODUCT_NAME="${PKI_PRODUCT}"
    PKI_PRODUCT_SOURCE_PATH="${PKI_DIR}/${PKI_SRC_DIR}/${IPA_COMPONENT}"
fi
PKI_RELEASE_ROOT="${PKI_BASEDIR}/${PKI_RELEASE_DIR}/${PKI_PRODUCT_SOURCE_PATH}"
PKI_SOURCE_CODE_LOCAL_REPOSITORY="`pwd`/${PKI_BASEDIR}/${PKI_PRODUCT_SOURCE_PATH}"

# Always check that local source code for this PKI component is available
if [ ! -d "${PKI_SOURCE_CODE_LOCAL_REPOSITORY}" ]; then
    printf "Please checkout the '${IPA_COMPONENT}' source code from:\n\n"
    printf "    '${PKI_SOURCE_CODE_URL}'\n\n"
    printf "to:\n\n"
    printf "    '${PKI_SOURCE_CODE_LOCAL_REPOSITORY}'\n\n"
    exit 255
fi

# Define awk scripts
check_targets='
BEGIN {
    success = "false";
}

{
    while( getline < FILENAME > 0 ) {
        if( substr( $0, 0, 80 ) ~ "target name" ) {
            start = substr( $0,
                            match( $0, "\"" ) + 1 );
            target = substr( start,
                             start,
                             match( start, "\"" ) - 1 );
            if( build_target == target ) {
                success = "true";
            }
        }
    }
}

END {
    printf( "%s", success );
}'

display_targets='{
    while( getline < FILENAME > 0 ) {
        if( substr( $0, 0, 80 ) ~ "target name" ) {
            start = substr( $0,
                            match( $0, "\"" ) + 1 );
            target = substr( start,
                             start,
                             match( start, "\"" ) - 1 );
        }
        if( substr( $0, 0, 80 ) ~ "description" ) {
            start = substr( $0,
                            match( $0, "\"" ) + 1 );
            description[target] = substr( start,
                                          start,
                                          match( start, "\"" ) - 1 );
            printf( "'%20s' %s\n", target, description[target] );
        }
    }
}'

# Provide a usage function
usage() {
    if [ $# -gt 0 ] ; then
        echo
        echo "$1"
    fi
    echo
    echo "Usage:  ${IPA_BUILD_SCRIPT} [target]"
    echo
    echo "        where [target] is one of the optional values:"
    echo
    echo "                help --> display '${PKI_PRODUCT_NAME}' usage statement"
    echo "             refresh --> fetch latest '${PKI_PRODUCT_NAME}.spec' file"
    awk "$display_targets" ${PKI_PRODUCT_BUILD_XML}
    echo
    exit 255
}

# Verify that the appropriate number of
# command-line parameters have been entered
# and that a valid target has been specified
if [ $# -eq 0 ] ; then
    RELEASE_TARGET=main
    BUILD_TARGET=""
elif [ $# -eq 1 ] ; then
    if [ "$1" == "help" ]; then
        usage
    else
        SUCCESS=`awk -v build_target=$1 "$check_targets" ${PKI_PRODUCT_BUILD_XML}`
        if [ "${SUCCESS}" == "false" ]; then
            usage "ERROR:  Invalid target '$1' specified for '${PKI_PRODUCT_NAME}'!"
        else
            RELEASE_TARGET=local
            BUILD_TARGET="$1"
        fi
    fi
elif [ $# -gt 1 ] ; then
    usage "ERROR:  Too many parameters specified for '${PKI_PRODUCT_NAME}'!"
fi

# This script may ONLY be run on Linux!
PKI_OS=`uname`
if [ "${PKI_OS}" != "Linux" ]; then
    printf "The '${IPA_BUILD_SCRIPT}' script is ONLY executable on a 'Linux' machine!\n"
    exit 255
fi

# Always start with a new release root directory
rm -rf ${PKI_RELEASE_ROOT}
mkdir -p ${PKI_RELEASE_ROOT}

# Copy the source code to the release root
cd ${PKI_BASEDIR}
find ${PKI_PRODUCT_SOURCE_PATH} -name .svn -prune -o -name *.swp -prune -o -print | cpio -pdum ${PKI_RELEASE_DIR} > /dev/null 2>&1
cd - > /dev/null 2>&1

# Remove unused files
rm -rf ${PKI_RELEASE_ROOT}/build_*
rm -rf ${PKI_RELEASE_ROOT}/*.spec
if [ -d ${PKI_RELEASE_ROOT}/config-ext ]; then
    rm -rf ${PKI_RELEASE_ROOT}/config-ext
fi

# Create the default spec file
cp ${IPA_SPECFILE} ${PKI_RELEASE_ROOT}/${PKI_PRODUCT_NAME}.spec

# Use bash-specific syntax to create the default build script
cat >> ${PKI_RELEASE_ROOT}/${PKI_RELEASE_SCRIPT} << END_OF_SCRIPT
#!/bin/bash

#####################################################################
###  DO NOT EDIT!  This script has been automatically generated!  ###
#####################################################################

# Always switch into the base directory of this
# shell script prior to executing it so that all
# of its output is written to this directory
cd \`dirname \$0\`

# Set pre-defined variables
BUILD_SCRIPT=\`basename \$0\`
BUILD_XML=${PKI_BUILD_XML}
SPECFILE=${PKI_PRODUCT_NAME}.spec

# Define awk scripts
check_targets='
BEGIN {
    success = "false";
}

{
    while( getline < FILENAME > 0 ) {
        if( substr( \$0, 0, 80 ) ~ "target name" ) {
            start = substr( \$0,
                            match( \$0, "\"" ) + 1 );
            target = substr( start,
                             start,
                             match( start, "\"" ) - 1 );
            if( build_target == target ) {
                success = "true";
            }
        }
    }
}

END {
    printf( "%s", success );
}'

display_targets='{
    while( getline < FILENAME > 0 ) {
        if( substr( \$0, 0, 80 ) ~ "target name" ) {
            start = substr( \$0,
                            match( \$0, "\"" ) + 1 );
            target = substr( start,
                             start,
                             match( start, "\"" ) - 1 );
        }
        if( substr( \$0, 0, 80 ) ~ "description" ) {
            start = substr( \$0,
                            match( \$0, "\"" ) + 1 );
            description[target] = substr( start,
                                          start,
                                          match( start, "\"" ) - 1 );
            printf( "'%20s' %s\n", target, description[target] );
        }
    }
}'

# Provide a usage function
usage() {
    if [ \$# -gt 0 ] ; then
        echo
        echo "\$1"
    fi
    echo
    echo "Usage:  \${BUILD_SCRIPT} [target]"
    echo
    echo "        where [target] is one of the optional values:"
    echo
    echo "                help --> display '${PKI_PRODUCT_NAME}' usage statement"
    awk "\$display_targets" \${BUILD_XML}
    echo
    exit 255
}

# Verify that the appropriate number of
# command-line parameters have been entered
# and that a valid target has been specified
if [ \$# -eq 0 ] ; then
    RELEASE_TARGET=main
    BUILD_TARGET=main
elif [ \$# -eq 1 ] ; then
    if [ "\$1" == "help" ]; then
        usage
    else
        SUCCESS=\`awk -v build_target=\$1 "\$check_targets" \${BUILD_XML}\`
        if [ "\${SUCCESS}" == "false" ]; then
            usage "ERROR:  Invalid target '\$1' specified for '${PKI_PRODUCT_NAME}'!"
        else
            RELEASE_TARGET=local
            BUILD_TARGET="\$1"
        fi
    fi
elif [ \$# -gt 1 ] ; then
    usage "ERROR:  Too many parameters specified for '${PKI_PRODUCT_NAME}'!"
fi

# This script may ONLY be run on Linux!
OS=\`uname\`
if [ "\${OS}" != "Linux" ]; then
    printf "The '\${BUILD_SCRIPT}' script is ONLY executable on a 'Linux' machine!\n"
    exit 255
fi

if [ -f /etc/fedora-release ]; then
	# Script is being executed on Fedora
	ant -f config/release.xml -Drhel=0 -Dproduct.ui.flavor.prefix=\${PKI_PRODUCT_UI_FLAVOR_PREFIX} -Dproduct.prefix=\${PKI_PRODUCT_PREFIX} -Dproduct=\${PKI_PRODUCT} -Dversion=\${PKI_VERSION} -Dbasedir=. -Dspecfile=\${SPECFILE} -Dtarget=\${BUILD_TARGET} \${RELEASE_TARGET}
elif [ -f /etc/redhat-release ]; then
	# Script is being executed on RHEL
	ant -f config/release.xml -Drhel=1 -Dproduct.ui.flavor.prefix=\${PKI_PRODUCT_UI_FLAVOR_PREFIX} -Dproduct.prefix=\${PKI_PRODUCT_PREFIX} -Dproduct=\${PKI_PRODUCT} -Dversion=\${PKI_VERSION} -Dbasedir=. -Dspecfile=\${SPECFILE} -Dtarget=\${BUILD_TARGET} \${RELEASE_TARGET}
fi

END_OF_SCRIPT
chmod 00755 ${PKI_RELEASE_ROOT}/${PKI_RELEASE_SCRIPT}

cd ${PKI_RELEASE_ROOT}
./${PKI_RELEASE_SCRIPT} ${BUILD_TARGET}