summaryrefslogtreecommitdiffstats
path: root/redhat/genrpm.sh
blob: 1a57dd89826476efbcc50c31ee9a81f31d137a19 (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
#!/bin/bash

cd "$( dirname "$0" )"

clear
cat <<EOF
This script generates RPM of TDE from source tarball.
Please choose a TDE component to build.

EOF

# Checks RPMBUILD environment
if [ $( rpm -E "%{rhel}" ) = "%{rhel}" ] && [ $( rpm -E "%{fedora}" ) = "%{fedora}" ]; then
	cat <<EOF
Error: RPM macro %rhel or %fedora must be set to the distribution version to build !
E.g:
%rhel 6 
or
%fedora 15
EOF
	exit 1
fi

select COMP in $( cut -f1 "components.txt" ) ; do
	# Gets package version from 'components.txt' file
	VERSION=$( awk '{ if ($1 == "'${COMP}'") { print $2; } }' components.txt )
	
	# If no version is set in text file, get version number from source tarball name
	if [ -z "${VERSION}" ]; then
		set $( cd "${COMP}"; echo ${COMP##*/}*.tar.gz)
		if [ $# -gt 1 ]; then
			select VERSION in $*; do break; done
		elif [ -r "${COMP}/$1" ]; then
			VERSION="$1"
		else
			echo "No source tarball found for '${COMP}' !"
			continue
		fi
		VERSION="${VERSION##${COMP##*/}-}"
		VERSION="${VERSION%%.tar.gz}"
	# If version is defined in spec file: appends the date
	else
		VERSION="${VERSION}.$(date +%Y%m%d)"
	fi
	
	# Chooses a spec file (if many)
	set $( cd "${COMP}"; echo *.spec )
	if [ $# -gt 1 ]; then
		select SPEC in $*; do break; done
	elif [ -r "${COMP}/$1" ]; then
		SPEC="$1"
	else
		echo "Fatal: no spec file found !"
		exit 2
	fi
	
	cat <<EOF

About to build '${COMP}':
  Version: '${VERSION}'
  Spec file: '${SPEC}'

Press ENTER to build, or CTRL+C to abort.
EOF
	read rep
	
	# Specific prefix for installation of some components
	case "${COMP##*/}" in
		"qt3") PREFIX="/usr";;
	esac
	
	set -x
	(
	rpmbuild -ba \
		--define "_sourcedir ${PWD}/${COMP}" \
		--define "_prefix ${PREFIX:-/opt/trinity}" \
		--define "version ${VERSION:-3.5.13}" \
		${COMP}/${SPEC} || exit 1
	) 2>&1 | tee /tmp/log
	set +x
done