summaryrefslogtreecommitdiffstats
path: root/pki/scripts/compose_functions
blob: ac03bc32af3dd31a473f606bbed3bc16669c9710 (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
##
## Obtain various platform information
##

OS=`uname`
if [ "${OS}" != "Linux" ] ; then
	printf "'$0' is ONLY available on '${OS}'!\n"
	exit 255
fi

PLATFORM=`uname -p`
if [ "${PLATFORM}" = "i686" ] ; then
	ARCHITECTURE="32-bit"
elif [ "${PLATFORM}" = "x86_64" ] ; then
	ARCHITECTURE="64-bit"
else
	printf "'$0' is ONLY available on 'i686' or 'x86_64' platforms!\n"
	exit 255
fi

if [ -f "/etc/redhat-release" ] ; then
	DISTRIBUTION=`cat /etc/redhat-release | cut -c1-7`
	DIST_VERSION=`cat /etc/redhat-release | tr -d [:alpha:][:blank:][\(\)]`
	if [ "${DISTRIBUTION}" = "Fedora " ] ; then
		MESSAGE="[built for ${ARCHITECTURE} Fedora ${DIST_VERSION}]"
	elif [ "${DISTRIBUTION}" = "Red Hat" ] ; then
		MESSAGE="[built for ${ARCHITECTURE} Red Hat ${DIST_VERSION}]"
	else
		printf "'$0' is ONLY available on 'Fedora' or 'Red Hat' "
		printf "distributions!\n"
		exit 255
	fi
else
	printf "'$0' is ONLY available on 'Fedora' or 'Red Hat' distributions!\n"
	exit 255
fi


##
## Establish various shared variables
##

PKI_DIR="pki"
export PKI_DIR

PKI_BASE_DIR="${PKI_DIR}/base"
export PKI_BASE_DIR

PKI_DOGTAG_DIR="${PKI_DIR}/dogtag"
export PKI_DOGTAG_DIR

PKI_PATCHES_DIR="${PKI_DIR}/patches"
export PKI_PATCHES_DIR

PKI_FILE_LIST="CMakeLists.txt COPYING CPackConfig.cmake ConfigureChecks.cmake DefineOptions.cmake README cmake_uninstall.cmake.in config.h.cmake"
export PKI_FILE_LIST

PKI_CMAKE_DIR="cmake"
export PKI_CMAKE_DIR

PKI_BASE_MANIFEST="CMakeLists.txt"
export PKI_BASE_MANIFEST

PKI_DOGTAG_MANIFEST="CMakeLists.txt"
export PKI_DOGTAG_MANIFEST


##
## Usage statement
##

Usage()
{
	printf "\n"
	printf "Usage:  $0 <target>\n\n"
	printf "        where <target> is one of the following:\n\n"
	printf "            srpm         - produces tarball, spec, and SRPM\n"
	printf "                           [suitable for use by 'mock']\n\n"
	printf "            rpms         - produces tarball, spec, SRPM, and\n"
	printf "                           RPMS(S)\n"
	printf "                           ${MESSAGE}\n\n"
	printf "            patched_srpm - copies tarball, patches, and spec\n"
	printf "                           to produce an SRPM\n"
	printf "                           [suitable for use by 'mock']\n\n"
	printf "            patched_rpms - copies tarball, patches, and spec\n"
	printf "                           to produce an SRPM and RPM(s)\n"
	printf "                           ${MESSAGE}\n\n"
}


##
## Copy Specified Source Tarball and Patches to SOURCES
##
Retrieve_Source_Tarball_and_Patches()
{
	if [ $# -ne 3 ] ; then
		Usage
		exit 255
	fi

	SPECFILE=$1
	PATCHES_DIR=$2
	TARGET_DIR=$3

	if [ ! -f ${SPECFILE} ] ; then
		printf "ERROR:  '${SPECFILE}' is missing!\n\n"
		Usage
		exit 255
	elif [ ! -d ${PATCHES_DIR} ] ; then
		printf "ERROR:  '${PATCHES_DIR}' does NOT exist!\n\n"
		Usage
		exit 255
	elif [ ! -d ${TARGET_DIR} ] ; then
		printf "ERROR:  '${TARGET_DIR}' does NOT exist!\n\n"
		Usage
		exit 255
	fi

	component_name_marker="Name"
	component_version_marker="Version"
	component_tarball_marker="Source"
	component_patch_marker="Patch"

	component_name=""
	component_version=""
	component_tarball=""
	component_patch=""

	exec < ${SPECFILE}
	while read line; do
		entry=`echo $line | cut -d: -f 1`
		if [ "${entry:0:4}" = "${component_name_marker}" ] ; then
			component_name=`echo $line | cut -d' ' -f 2`
		elif [ "${entry:0:7}" = "${component_version_marker}" ] ; then
			component_version=`echo $line | cut -d' ' -f 2`
		elif [ "${entry:0:6}" = "${component_tarball_marker}" ] ; then
			value=`echo $line | cut -d' ' -f 2`
			component_tarball=`echo $value | sed -e "s/\%{name}/${component_name}/g" -e "s/\%{version}/${component_version}/g"`
			wget -q -O ${TARGET_DIR}/`basename ${component_tarball}` ${component_tarball}
			if [ $? -ne 0 ] ; then
				printf "ERROR:  Failed to download '${component_tarball}'!\n\n"
				Usage
				exit 255
			elif [ ! -f ${TARGET_DIR}/`basename ${component_tarball}` ] ; then
				printf "ERROR:  Failed to save '${TARGET_DIR}/`basename ${component_tarball}`'!\n\n"
				Usage
				exit 255
			fi
		elif [ "${entry:0:5}" = "${component_patch_marker}" ] ; then
			value=`echo $line | cut -d' ' -f 2`
			component_patch=`echo $value | sed -e "s/\%{name}/${component_name}/g" -e "s/\%{version}/${component_version}/g"`
			if [ -f ${PATCHES_DIR}/${component_patch} ] ; then
				cp -p ${PATCHES_DIR}/${component_patch} ${TARGET_DIR}
				if [ ! -f ${TARGET_DIR}/${component_patch} ] ; then
					printf "ERROR:  Failed to copy '${component_patch}'!\n\n"
					Usage
					exit 255
				fi
			else
				printf "ERROR:  Failed to find '${component_patch}'!\n\n"
				Usage
				exit 255
			fi
		fi
	done
}


##
## Check for command line argument validity
##

if [ $# -ne 1 ] ; then
	Usage
	exit 255
fi

if	[ $1 = "srpm" ] ; then
	RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" -bs"
	USE_PATCH_FILES=0
elif [ $1 = "patched_srpm" ] ; then
	RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" -bs"
	USE_PATCH_FILES=1
elif [ $1 = "rpms" ] ; then
	RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" -ba"
	USE_PATCH_FILES=0
elif [ $1 = "patched_rpms" ] ; then
	RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" -ba"
	USE_PATCH_FILES=1
else
	Usage
	exit 255
fi
export RPMBUILD_CMD