-
Notifications
You must be signed in to change notification settings - Fork 5
/
setver.sh
executable file
·141 lines (123 loc) · 3.31 KB
/
setver.sh
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
#!/bin/sh
OPTS=$(getopt -o biUFvo --long \
build,install,update,freshen,verbose,oldpackage \
-n 'setver.sh' -- "$@")
eval set -- "$OPTS"
while true; do
case $1 in
-b|--build)
build=yes
;;
-i|--install)
build=yes
install=i
;;
-U|--update)
build=yes
install=U
;;
-F|--freshen)
build=yes
install=F
;;
-v|--verbose)
verbose=yes
;;
-o|--oldpackage)
rpm_install_flags="${rpm_install_flags} --oldpackage"
;;
--)
break
;;
*)
echo "Invalid argument: $1" 1>&2
exit 1
esac
shift
done
test "$build" = "yes" && clean="yes"
NAME=ploop
RPM_SPEC=${NAME}.spec
MAKEFILE=Makefile.inc
# Try to figure out version from git
GIT_DESC=$(git describe --tags | sed s'/^[^0-9]*-\([0-9].*\)$/\1/')
# 3.0.28-1-gf784152
GIT_V=$(echo $GIT_DESC | awk -F - '{print $1}')
GIT_R=$(echo $GIT_DESC | awk -F - '{print $2}')
GIT_T=$(echo $GIT_DESC | awk -F - '{print $3}')
test "x$GIT_R" = "x" && GIT_R="1"
GIT_VR="${GIT_V}-${GIT_R}"
BUILDID=$(cat .build-id 2>/dev/null || echo 0)
if test "${GIT_VR}" = "$(cat .version-id 2>/dev/null)"; then
BUILDID=$((BUILDID+1))
GIT_R="${GIT_R}.${BUILDID}"
else
echo "${GIT_VR}" > .version-id
BUILDID=0
fi
echo "${BUILDID}" > .build-id
GIT_RT="${GIT_R}.${GIT_T}"
test "x$GIT_T" = "x" && GIT_RT="${GIT_R}"
GIT_VRT="${GIT_V}-${GIT_RT}"
read_spec() {
SPEC_V=$(awk '($1 == "Version:") {print $2}' $RPM_SPEC)
SPEC_R=$(awk '($1 " " $2 == "%define rel") {print $3}' $RPM_SPEC)
SPEC_VR="${SPEC_V}-${SPEC_R}"
}
read_spec
# Store original spec
if test "$clean" = "yes"; then
cp -a $RPM_SPEC .$RPM_SPEC.$$
ATEXIT="mv -f .$RPM_SPEC.$$ $RPM_SPEC"
trap "$ATEXIT" EXIT
fi
# Set version/release in spec from git
if test "$GIT_VR" != "$SPEC_VR"; then
test -z "$verbose" || echo "Changing $RPM_SPEC:"
# Version: 3.0.28
# Release: 1%{?dist}
sed -i -e "s/^\(Version:[[:space:]]*\).*\$/\1$GIT_V/" \
-e "s/^\(%define rel[[:space:]]*\).*\$/\1$GIT_RT/" \
$RPM_SPEC
if test -n "$GIT_T"; then
NVR='%{name}-%{version}-%{rel}'
sed -i -e "s/^\(Source:[[:space:]]*\).*\$/\1${NVR}.tar.bz2/" \
-e "s/^%setup[[:space:]]*.*\$/%setup -n ${NVR}/" \
$RPM_SPEC
fi
fi
test -z "$verbose" || \
grep -E -H '^Version:|^%define rel|^Source:|^%setup' $RPM_SPEC
# Store original Makefile
if test "$clean" = "yes"; then
cp -a $MAKEFILE .$MAKEFILE.$$
ATEXIT="$ATEXIT; mv -f .$MAKEFILE.$$ $MAKEFILE"
trap "$ATEXIT" EXIT
fi
# Set version in Makefile from git
MF_V=$(awk -F = '($1 == "VERSION") { print $2; }' $MAKEFILE)
MF_R=$(awk -F = '($1 == "RELEASE") { print $2; }' $MAKEFILE)
GIT_R_MF="-$GIT_RT"
test "$GIT_RT" = "1" && GIT_R_MF=""
if test "$GIT_V" != "$MF_V" -o "$GIT_R_MF" != "MF_R"; then
test -z "$verbose" || echo "Changing $MAKEFILE:"
# VERSION=1.12
# RELEASE=
sed -i -e "s/^\(VERSION=\).*\$/\1$GIT_V/" \
-e "s/^\(RELEASE=\).*\$/\1$GIT_R_MF/" \
$MAKEFILE
fi
test -z "$verbose" || \
grep -E -H "^VERSION=|^RELEASE=" $MAKEFILE
test "$build" = "yes" || exit 0
make rpms || exit 1
# Remove dist tarball
test "$clean" = "yes" && rm -f ${NAME}-${GIT_VRT}.tar.bz2
test -z "$install" && exit 0
sudo rpm -${install}hv ${rpm_install_flags} \
$(rpm --eval %{_rpmdir}/%{_arch})/${NAME}-*${GIT_VRT}*.rpm || exit 1
# Remove rpms
if test "$clean" = "yes"; then
rm -f $(rpm --eval %{_rpmdir}/%{_arch})/${NAME}-*${GIT_VRT}*.rpm
rm -f $(rpm --eval %{_srcrpmdir})/${NAME}-*${GIT_VRT}*.src.rpm
fi