-
Notifications
You must be signed in to change notification settings - Fork 4
/
zanata-rpm-functions
executable file
·157 lines (135 loc) · 4.56 KB
/
zanata-rpm-functions
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
#!/bin/bash -eu
### NAME
### zanata-rpm-functions
###
### SYNOPSIS
### zanata-rpm-functions help
### zanata-rpm-functions run <function> [function parameters ...]
###
### DESCRIPTION
### The script contain function to build RPM.
###
### This script depends on zanata-funtions
###
##=== function definitions Start ===
### FUNCTIONS
### koji_get_rawhide_version
### Get the version that rawhide targeting to.
function koji_get_rawhide_version(){
koji list-targets | sed -n -e '/^rawhide\s/ s/^.*\sf\([0-9]*\).*$/\1/p'
}
### spec_update <specPath> <version> <specRelease> <maintainerEmail> [changeLogMsg]
function spec_update(){
local specPath="$1"
local version=$2
local specRelease="$3"
local maintainerEmail="$4"
local changeLogMsg="${5-}"
SpecModified=0
test -r $specPath
exit_if_failed $? $EXIT_FATAL_FAIL "SPEC file $specPath does not exists"
if [ -z "$changeLogMsg" ];then
changeLogMsg="- Upgrade to upstream version ${Version}"
fi
mkdir -p $TMP_ROOT
local tmpSpecPath=$TMP_ROOT/$(basename ${specPath})
## Update changelog
local changelogMatchStr=$(sed -n -e '/^%changelog/,$ p' ${specPath} | sed -n -e "/^\* .* ${version}-${specRelease}/ p")
if [ -z "$changelogMatchStr" ];then
print_status " updating changelog"
sed -e '/^%changelog/a *'" $(date '+%a %b %d %Y') $maintainerEmail $version-$specRelease\n$changeLogMsg\n" "${specPath}" > ${tmpSpecPath}.changelog
SpecModified=1
else
cp "${specPath}" ${tmpSpecPath}.changelog
fi
## Update version
local versionMatchStr=$(sed -n -e '/^Version:/ s/^Version:\s*\([0-9.]*\)/\1/ p' ${tmpSpecPath}.changelog)
if [ "${versionMatchStr}" != "$version" ];then
print_status " updating version to $version"
sed -e '/^Version:/ s/^\(Version:\s*\).*$/\1'$version'/' ${tmpSpecPath}.changelog > ${tmpSpecPath}.version
SpecModified=1
else
cp "${tmpSpecPath}.changelog" "${tmpSpecPath}.version"
fi
## Update SpecRelease
local releaseMatchStr=$(sed -n -e '/^Release:/ s/^Release:\s*\([0-9][0-9]*\).*$/\1/ p' ${tmpSpecPath}.version)
if [ "${releaseMatchStr}" != "${specRelease}" ];then
print_status " updating SPEC release to ${specRelease}"
sed -e '/^Release:/ s/[0-9][0-9]*/'$specRelease'/' ${tmpSpecPath}.version > ${tmpSpecPath}
SpecModified=1
else
cp "${tmpSpecPath}.version" "${tmpSpecPath}"
fi
print_status " checking generated SPEC"
rpmlint ${tmpSpecPath} 1>/dev/stderr
exit_if_failed "$?" $EXIT_FATAL_FAIL "rpmlint check failed"
cp $tmpSpecPath $specPath
}
###
### branch_to_bodhi_branch <branch>
### Valid branch: fedora-<ver>, fedora<ver>, f<ver>, fc<ver>
### epel-<ver>, epel<ver>, el<ver>
function branch_to_bodhi_branch(){
local branch=$1
if [ "$branch" = "master" ];then
branch=f${RawhideVersion}
fi
local num=$(sed -e 's/[^0-9]*//' <<< $branch)
case $branch in
f* )
echo "fc$num"
;;
e* )
echo "el$num"
;;
esac
}
###
### branches_to_koji_targets <branch1> ...
### Valid branch: master, fedora-<ver>, fedora<ver>, f<ver>, fc<ver>
### epel-<ver>, epel<ver>, el<ver>
function branches_to_koji_targets(){
local first=1
for branch in "$@"; do
if [ "$branch" = "master" ];then
branch=f${RawhideVersion}
fi
local num=$(sed -e 's/[^0-9]*//' <<< $branch)
if [ $first -eq 1 ];then
first=0
else
echo -n " "
fi
case $branch in
f* )
echo -n "f$num"
;;
e* )
if [ $num -ge 7 ];then
echo -n "epel$num"
else
echo -n "el$num"
fi
;;
esac
done
}
##=== function definitions End ===
ProgramName=$(basename ${BASH_SOURCE[0]})
RawhideVersion=$(koji_get_rawhide_version)
if [ "$ProgramName" = "zanata-rpm-functions" ];then
## Running as standalone
ScriptDir=$(dirname $(readlink -q -f $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "${FunctionScriptFile}"
trap exit_print_error EXIT
fi
## Check depending programs
ExitStatus=$EXIT_OK
for dep in awk koji fedpkg bodhi rpmbuild mock; do
if ! which $dep &>/dev/null ; then
ExitStatus=${EXIT_FATAL_MISSING_DEPENDENCY}
EXIT_MSG+=" $dep"
fi
done
exit_if_failed "${ExitStatus}" ${EXIT_FATAL_MISSING_DEPENDENCY} "$EXIT_MSG"