summaryrefslogtreecommitdiffstats
path: root/pki/base/native-tools/setup_package
blob: f8df290b4fb8fcb5087095da7ed3b45017587115 (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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/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.
# 
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# --- END COPYRIGHT BLOCK ---

###############################################################################
##  (1)  Check command line arguments to see how many were passed in.        ##
###############################################################################

if [ $# -eq 7 ]
then
	NATIVE_TOOLS_BUILD_PREFIX=$1
	NATIVE_TOOLS_PRODUCT_NAME=$2
	NATIVE_TOOLS_SUBSYSTEM_NAME=$3
	VERSION=$4
	RELEASE=$5
	ARCHITECTURE=$6
	NATIVE_TOOLS_STAGING_PATH=$7
else
	echo
	echo "Usage:  $0 NATIVE_TOOLS_build_prefix NATIVE_TOOLS_product_name"
	echo "        NATIVE_TOOLS_subsystem_name version release architecture"
	echo "        NATIVE_TOOLS_staging_path"
	echo

	exit 255
fi


###############################################################################
##  (2)  Specify variables used by this script.                              ##
###############################################################################

# specify generic helper functions
usage() {
	if [ $# -gt 0 ] ; then
		echo
		echo "$1"
	fi
	echo
	echo "Usage:  $0 NATIVE_TOOLS_build_prefix NATIVE_TOOLS_product_name"
	echo "        NATIVE_TOOLS_subsystem_name version release architecture"
	echo
	echo "        where architecture MUST be 'intel',"
	echo "                                   'sparc', or"
	echo "                                   'sparcv9'."
	echo
	echo "        NOTE:  For 'intel' architectures, only the 'i386' and"
	echo "               the 'x86_64' architectures are currently supported."
	echo
}

# specify generic helper variables
if  [ ${ARCHITECTURE} = "intel" ] ; then
	# Since "rpmbuild" fails to process "%ifarch" macros inside the
	# "%install" section of a spec file, the actual hardware
	# architecture will be determined at this point in time.
	ARCHITECTURE=`uname -i`
	if   [ ${ARCHITECTURE} = "i386" ] ; then
		LIB_DIR="lib"
		PERL_DIR="/usr/bin/perl"
		SCRIPTS_DIR="bin"
		WRAPPER_DIR="bin"
	elif [ ${ARCHITECTURE} = "x86_64" ] ; then
		LIB_DIR="lib64"
		PERL_DIR="/usr/bin/perl"
		SCRIPTS_DIR="bin"
		WRAPPER_DIR="bin"
	else
		usage "ERROR:  Unsupported intel architecture '${ARCHITECTURE}'!"
		exit 255
	fi
elif [ ${ARCHITECTURE} = "sparc" ] ; then
	# Note that "pkgbuild" successfully processes "%ifarch" macros
	# inside the "%install" section of a spec file.
	LIB_DIR="lib"
	PERL_DIR="/opt/perl5/bin/perl"
	SCRIPTS_DIR="bin"
	WRAPPER_DIR="bin"
elif [ ${ARCHITECTURE} = "sparcv9" ] ; then
	# Note that "pkgbuild" successfully processes "%ifarch" macros
	# inside the "%install" section of a spec file.
	LIB_DIR="lib/sparcv9"
	PERL_DIR="/opt/perl5x/bin/perl"
	SCRIPTS_DIR="bin"
	WRAPPER_DIR="bin"
else
	usage "ERROR:  Unsupported architecture '${ARCHITECTURE}'!"
	exit 255
fi

# specify the pre-packaged files
NATIVE_TOOLS_PACKAGE_NAME=native-tools.zip

# break the VERSION number into its various components
MAJOR_VERSION=`echo ${VERSION} | awk -F. '{ print $1 }'`
MINOR_VERSION=`echo ${VERSION} | awk -F. '{ print $2 }'`
PATCH_VERSION=`echo ${VERSION} | awk -F. '{ print $3 }'`


# comply with standard FHS 2.3 binary locations (executables)
NATIVE_TOOLS_EXECUTABLES=${NATIVE_TOOLS_BUILD_PREFIX}/usr/${LIB_DIR}/${NATIVE_TOOLS_PRODUCT_NAME}/${NATIVE_TOOLS_SUBSYSTEM_NAME}

# comply with standard FHS 2.3 library locations

# comply with standard JPackage 1.6.0 jar locations

# comply with standard FHS 2.3 binary locations (wrappers)
NATIVE_TOOLS_SCRIPTS=${NATIVE_TOOLS_BUILD_PREFIX}/usr/${SCRIPTS_DIR}
NATIVE_TOOLS_WRAPPERS=${NATIVE_TOOLS_BUILD_PREFIX}/usr/${WRAPPER_DIR}
NATIVE_TOOLS_PERL=${NATIVE_TOOLS_BUILD_PREFIX}/usr/${SCRIPTS_DIR}/pkiperl

# comply with standard FHS 2.3 shared data locations (templates)
NATIVE_TOOLS_SHARED_DATA=${NATIVE_TOOLS_BUILD_PREFIX}/usr/share/${NATIVE_TOOLS_PRODUCT_NAME}
NATIVE_TOOLS_TEMPLATES=${NATIVE_TOOLS_SHARED_DATA}/templates

# comply with standard FHS 2.3 start/stop script locations

# comply with standard FHS 2.3 configuration file locations

# comply with standard FHS 2.3 documentation locations
NATIVE_TOOLS_DOCUMENTATION=${NATIVE_TOOLS_BUILD_PREFIX}/usr/share/doc/${NATIVE_TOOLS_PRODUCT_NAME}-${NATIVE_TOOLS_SUBSYSTEM_NAME}-${VERSION}

# comply with standard FHS 2.3 log file locations

# comply with default FHS 2.3 instance locations


###############################################################################
##  (3)  Create the appropriate subdirectories.                              ##
###############################################################################

##
## System:
##


##
## Product
##

mkdir -p ${NATIVE_TOOLS_SCRIPTS}
mkdir -p ${NATIVE_TOOLS_WRAPPERS}


##
## Subsystem
##

mkdir -p ${NATIVE_TOOLS_DOCUMENTATION}
mkdir -p ${NATIVE_TOOLS_EXECUTABLES}
mkdir -p ${NATIVE_TOOLS_SHARED_DATA}
mkdir -p ${NATIVE_TOOLS_TEMPLATES}


##
## Initial Instance
##


###############################################################################
##  (4)  Unpack the package contents to the appropriate subdirectories.      ##
###############################################################################

##
## Executables
##

cp -p ${NATIVE_TOOLS_STAGING_PATH}/conf/*      ${NATIVE_TOOLS_EXECUTABLES}

cp -p ${NATIVE_TOOLS_STAGING_PATH}/libexec/*   ${NATIVE_TOOLS_EXECUTABLES}

cp -p ${NATIVE_TOOLS_STAGING_PATH}/samples/*   ${NATIVE_TOOLS_EXECUTABLES}


##
## Libraries
##


##
## Jars
##


##
## Wrappers
##


##
## Shared Data
##

cp -rp ${NATIVE_TOOLS_STAGING_PATH}/doc/*      ${NATIVE_TOOLS_DOCUMENTATION}

cp -p ${NATIVE_TOOLS_STAGING_PATH}/templates/* ${NATIVE_TOOLS_TEMPLATES}


###############################################################################
##  (5)  Unpack the package contents to the initial instance directories.    ##
###############################################################################

##
## Start/Stop Script
##


##
## Configuration
##


##
## Logs
##


##
## Default Instance
##


###############################################################################
##  (6)  Rename the extracted contents following appropriate naming rules.   ##
###############################################################################

# comply with standard Linux/UNIX shared library naming conventions

# comply with standard JPackage 1.6.0 jar naming conventions


###############################################################################
##  (7)  Create a command wrapper for each specified command.                ##
###############################################################################

COMMANDS="bulkissuance p7tool revoker setpin tkstool sslget"

create_wrapper()
{
	PRODUCT=$1
	SUBSYSTEM=$2
	COMMAND=$3

	TEMPLATE=pki_subsystem_command_wrapper

	WRAPPER=${NATIVE_TOOLS_WRAPPERS}/${COMMAND}

	sed	-e "s|\[PKI_PRODUCT\]|${PRODUCT}|g"     \
		-e "s|\[PKI_SUBSYSTEM\]|${SUBSYSTEM}|g" \
		-e "s|\[PKI_COMMAND\]|${COMMAND}|g"     \
		${NATIVE_TOOLS_SHARED_DATA}/templates/${TEMPLATE} > ${WRAPPER}
}


for cmd in ${COMMANDS}
do
	create_wrapper ${NATIVE_TOOLS_PRODUCT_NAME} ${NATIVE_TOOLS_SUBSYSTEM_NAME} ${cmd}
done


# replace "uname -s" within various PKI scripts with "pkiname"
echo "#!/bin/sh"    >  ${NATIVE_TOOLS_SCRIPTS}/pkiname
echo                >> ${NATIVE_TOOLS_SCRIPTS}/pkiname
echo "echo `uname`" >> ${NATIVE_TOOLS_SCRIPTS}/pkiname


# replace "uname -i" and "uname -p" within various PKI scripts with "pkiarch"
echo "#!/bin/sh"            >  ${NATIVE_TOOLS_SCRIPTS}/pkiarch
echo                        >> ${NATIVE_TOOLS_SCRIPTS}/pkiarch
echo "echo ${ARCHITECTURE}" >> ${NATIVE_TOOLS_SCRIPTS}/pkiarch


# use "pkiflavor" to obtain the "pki" prefix within various PKI scripts
echo "#!/bin/sh"                         >  ${NATIVE_TOOLS_SCRIPTS}/pkiflavor
echo                                     >> ${NATIVE_TOOLS_SCRIPTS}/pkiflavor
echo "echo ${NATIVE_TOOLS_PRODUCT_NAME}" >> ${NATIVE_TOOLS_SCRIPTS}/pkiflavor

# obtain the PKI operating system distribution using "pkidist"
echo "#!/bin/sh"                             >  ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo                                         >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "OS=\`uname\`"                          >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "if [ \${OS} = \"Linux\" ]; then"       >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    if [ -e /etc/fedora-release ]; then" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        DISTRIBUTION=\"fc\""           >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        DISTRIBUTION_VERSION=\`rpm -qf --qf='%{VERSION}' /etc/fedora-release\`" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        VERSION=\`echo \${DISTRIBUTION_VERSION} | tr -d [A-Za-z]\`" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        printf \"\${DISTRIBUTION}\${VERSION}\n\"" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    elif [ -e /etc/redhat-release ]; then" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        DISTRIBUTION=\"el\""           >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        DISTRIBUTION_VERSION=\`rpm -qf --qf='%{VERSION}' /etc/redhat-release\`" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        VERSION=\`echo \${DISTRIBUTION_VERSION} | tr -d [A-Za-z]\`" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        printf \"\${DISTRIBUTION}\${VERSION}\n\"" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    else"                              >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "        printf \"undefined\n\""        >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    fi"                                >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "elif [ \${OS} = \"SunOS\" ]; then"     >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    DISTRIBUTION=\"sol\""              >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    VERSION=\`uname -r | cut -f2 -d .\`" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    printf \"\${DISTRIBUTION}\${VERSION}\n\"" >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "else"                                  >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "    printf \"undefined\n\""            >> ${NATIVE_TOOLS_SCRIPTS}/pkidist
echo "fi"                                    >> ${NATIVE_TOOLS_SCRIPTS}/pkidist


###############################################################################
##  (8)  Create useful symbolic links as appropriate.                        ##
###############################################################################

# create shared library sans version "linker-name" to protect this namespace

# create jar sans version to be used by classpath

# create assorted symbolic links to various file dependencies (Tomcat)
cd ${NATIVE_TOOLS_SCRIPTS} ;
ln -s ${PERL_DIR} ${NATIVE_TOOLS_PERL}


###############################################################################
##  (9)  Successfully exit from this setup script.                           ##
###############################################################################

exit 0