-
Notifications
You must be signed in to change notification settings - Fork 0
/
makerpms
executable file
·144 lines (130 loc) · 3.44 KB
/
makerpms
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
#!/bin/bash
#
# Copyright (c) 2016, Cray Inc.
# All rights reserved.
#
# This script can be used to create RPMs from the source directory, using
# the existing OS and architecture (rather than a customized chroot build
# environment).
#
# NOTE: Do NOT add this to the specfile, nor to the automake, there is no
# point. This is part of the GIT clone image, and should only be used from
# within the local clone -- it has no purpose anywhere else (e.g. in /sbin,
# or within the released RPMs.)
## Usage information
# $@ = error information to be displayed
function usage
{
if [[ $# -gt 0 ]]; then
echo "$@"
echo
fi
cat <<EOF
Usage: makerpms [-d build_dir] sources
makerpms [-d build_dir] rpms [options]
makerpms [-d build_dir] install
sources = creates only the source tarball needed by rpmbuild to create RPMs
rpms = creates RPMs using the specified rpmbuild options (default = -ba)
install = creates RPMs and installs them on this machine
-d build_dir = set the build directory (default == ~/craybuild)
EOF
exit 1
}
## Make selected commands visible in stdout before executing
# $@ = command to execute (using eval)
function logdo
{
echo "+ $@"
eval "$@"
}
## If logdo on a command fails, stop running
# $@ = command to execute (using eval)
function faildo
{
if ! logdo $@; then
echo "FAILED"
exit 1
fi
}
## Prepare the environment for building
# $1 = build directory
# NOTE: This overrides any %_topdir declaration in ~/.rpmmacros
function setup
{
faildo mkdir -p $1/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
if grep -q '%_topdir' ~/.rpmmacros 2>/dev/null; then
sed -i -e "s:%_topdir.*:%_topdir $1" ~/.rpmmacros
else
echo "%_topdir $1" >>~/.rpmmacros
fi
}
## Create the wource tarball needed by rpmbuild
# $1 = build directory
function mksources
{
setup $1
faildo rm -rf $1/SOURCES/cray-powerapi-1.0.tar.bz2
faildo tar --exclude=.git --transform='s/^\./cray-powerapi-1.0/' -jcvf $1/SOURCES/cray-powerapi-1.0.tar.bz2 .
}
## Create new RPMs from the current sources
# $1 = build directory
# $2 = options to use with rpmbuild (default == '-ba' if omitted)
function mkrpms
{
mksources $1
opts="${2:--ba}"
faildo rm -rf $1/BUILD/cray-powerapi-1.0
faildo rm -rf $1/RPMS/cray*powerapi*
faildo rpmbuild $opts cray-powerapi.spec
}
## Create new RPMs and install them
# $1 = build directory
function mkinstall
{
mkrpms $1 '-ba'
# Find the complete list of RPMs created
rpms=$(find $1/RPMS -name '*.rpm')
# Find out what is currently installed
pkgs=$(rpm -qa | grep 'cray.*powerapi' | sed 's/-1.0-.*$/-1.0/')
# Remove the old RPMs (may fail if nothing installed)
if [[ -n "$pkgs" ]]; then
logdo rpm -e $pkgs
fi
# Install the new
faildo rpm -ivh $rpms
# Make sure dynamic library cache is updated
ldconfig
}
################################
# Parse command line options
build=~/craybuild
while getopts "d:h" opt; do
case "$opt" in
d) build=$OPTARG ;;
h) usage ;;
*) usage "Unknown option -$opt" ;;
esac
done
shift $(($OPTIND - 1))
if [[ $# -lt 1 ]]; then
usage "Must specify sources, rpms, or install"
fi
action="$1"
shift 1
options="$@"
# Act on the specified command
echo "+ makerpms $action"
case "$action" in
sources)
mksources $build
;;
rpms)
mkrpms $build "$options"
;;
install)
mkinstall $build
;;
*)
usage "Action '$action' unknown"
;;
esac