|
@@ -1,5 +1,8 @@
|
1
|
1
|
#!/bin/bash
|
2
|
2
|
|
|
3
|
+TRIGGER_COPR_CONFIG=${TRIGGER_COPR_CONFIG:-}
|
|
4
|
+TRIGGER_COPR_PKGNAME=${TRIGGER_COPR_PKGNAME:-}
|
|
5
|
+
|
3
|
6
|
warn() {
|
4
|
7
|
echo "$1" >&2
|
5
|
8
|
}
|
|
@@ -16,6 +19,7 @@ usage() {
|
16
|
19
|
warn ""
|
17
|
20
|
warn " -b BRN build from branch BRN (default: last tag)"
|
18
|
21
|
warn " -c COPR_PROJECT COPR project name"
|
|
22
|
+ warn " -C CONF config file"
|
19
|
23
|
warn " -n dry mode, don't do anything (just show"
|
20
|
24
|
warn " what would be done)"
|
21
|
25
|
warn " -r REL use REL as Release number in SPEC file"
|
|
@@ -49,7 +53,7 @@ last_version() {
|
49
|
53
|
mkspec() {
|
50
|
54
|
local self_version
|
51
|
55
|
local cl_date
|
52
|
|
- self_version="slop-build-copr $(git describe --tags)"
|
|
56
|
+ self_version="$(basename "$0") $(git describe --tags)"
|
53
|
57
|
cl_date=$(LC_ALL=C date +"%a %b %d %Y")
|
54
|
58
|
sed -e "
|
55
|
59
|
s|__APP_VERSION__|$Version|
|
|
@@ -57,7 +61,7 @@ mkspec() {
|
57
|
61
|
s|__APP_URLBASE__|$UrlBase|
|
58
|
62
|
s|__APP_BUILDSCRIPT_VERSION__|$self_version|
|
59
|
63
|
s|__APP_DATE__|$cl_date|
|
60
|
|
- " <slop.spec.in
|
|
64
|
+ " <"$PkgName.spec.in"
|
61
|
65
|
}
|
62
|
66
|
|
63
|
67
|
git_guess() {
|
|
@@ -87,39 +91,44 @@ git_guess() {
|
87
|
91
|
esac
|
88
|
92
|
}
|
89
|
93
|
|
90
|
|
-choose_copr() {
|
|
94
|
+choose_relpfx() {
|
91
|
95
|
#
|
92
|
96
|
# Choose COPR project based on $Mode
|
93
|
97
|
#
|
94
|
|
- case $Mode in
|
95
|
|
- scratch) echo amahdal/slop-scratch ;;
|
96
|
|
- main) echo amahdal/slop ;;
|
97
|
|
- esac
|
|
98
|
+ test "$Mode" == scratch && echo 0.scratch.
|
|
99
|
+ return 0
|
98
|
100
|
}
|
99
|
101
|
|
100
|
|
-choose_urlbase() {
|
|
102
|
+read_conffile() {
|
101
|
103
|
#
|
102
|
|
- # Choose COPR project based on $Mode
|
|
104
|
+ # Read item T
|
103
|
105
|
#
|
104
|
|
- case $Mode in
|
105
|
|
- scratch) echo https://github.com/AloisMahdal/slop ;;
|
106
|
|
- main) echo https://github.com/naelstrof/slop ;;
|
|
106
|
+ local what=$1
|
|
107
|
+ local fieldn
|
|
108
|
+ case $what in
|
|
109
|
+ urlbase) fieldn=2 ;;
|
|
110
|
+ copr) fieldn=3 ;;
|
107
|
111
|
esac
|
|
112
|
+ grep -v '^[[:blank:]]*#' "$ConfFile" \
|
|
113
|
+ | grep "^ *$Mode\>" \
|
|
114
|
+ | sed 's/ */ /g' \
|
|
115
|
+ | cut -d' ' -f$fieldn
|
108
|
116
|
}
|
109
|
117
|
|
110
|
|
-choose_relpfx() {
|
|
118
|
+choose_conffile() {
|
111
|
119
|
#
|
112
|
|
- # Choose COPR project based on $Mode
|
|
120
|
+ # Find config file and echo its name
|
113
|
121
|
#
|
114
|
|
- test "$Mode" == scratch && echo 0.scratch.
|
115
|
|
- return 0
|
|
122
|
+ find . -name '*.trigger' \
|
|
123
|
+ | cut -d/ -f2 \
|
|
124
|
+ | grep .
|
116
|
125
|
}
|
117
|
126
|
|
118
|
127
|
do_action() {
|
119
|
128
|
local url
|
120
|
129
|
case $Action in
|
121
|
130
|
build)
|
122
|
|
- copr build "$CoprProject" "$Tmp/slop.spec"
|
|
131
|
+ copr build "$CoprProject" "$Tmp/$PkgName.spec"
|
123
|
132
|
;;
|
124
|
133
|
demo)
|
125
|
134
|
warn "demo mode active, we would build:"
|
|
@@ -127,19 +136,19 @@ do_action() {
|
127
|
136
|
test -n "$Branch" && warn " using branch $Branch"
|
128
|
137
|
test -n "$Branch" || warn " using last tag"
|
129
|
138
|
warn " from $UrlBase"
|
130
|
|
- warn " yielding slop-$Version-$Release.*.rpm"
|
|
139
|
+ warn " yielding $PkgName-$Version-$Release.*.rpm"
|
131
|
140
|
warn ""
|
132
|
|
- warn "===== BEGIN slop.spec ====="
|
133
|
|
- cat "$Tmp/slop.spec"
|
134
|
|
- warn "===== END slop.spec ====="
|
|
141
|
+ warn "===== BEGIN $PkgName.spec ====="
|
|
142
|
+ cat "$Tmp/$PkgName.spec"
|
|
143
|
+ warn "===== END $PkgName.spec ====="
|
135
|
144
|
return 1
|
136
|
145
|
;;
|
137
|
146
|
mkspec)
|
138
|
|
- cat "$Tmp/slop.spec"
|
|
147
|
+ cat "$Tmp/$PkgName.spec"
|
139
|
148
|
;;
|
140
|
149
|
rpmstuff)
|
141
|
150
|
url=$(
|
142
|
|
- grep -o 'Source.*:.*http.*' "$Tmp/slop.spec" \
|
|
151
|
+ grep -o 'Source.*:.*http.*' "$Tmp/$PkgName.spec" \
|
143
|
152
|
| sed "
|
144
|
153
|
s/.*http/http/
|
145
|
154
|
s/ *$//
|
|
@@ -147,7 +156,7 @@ do_action() {
|
147
|
156
|
"
|
148
|
157
|
)
|
149
|
158
|
wget --quiet "$url"
|
150
|
|
- cat "$Tmp/slop.spec" > slop.spec
|
|
159
|
+ cat "$Tmp/$PkgName.spec" > "$PkgName.spec"
|
151
|
160
|
;;
|
152
|
161
|
esac
|
153
|
162
|
}
|
|
@@ -161,11 +170,14 @@ main() {
|
161
|
170
|
local Branch # branch to use, if empty, tags are considered
|
162
|
171
|
local Mode=scratch # implies COPR project and release prefix
|
163
|
172
|
local Action=build # what to do
|
|
173
|
+ local ConfFile # config file to use
|
|
174
|
+ local PkgName # package name
|
164
|
175
|
local es=0 # exit status
|
165
|
176
|
which copr >/dev/null \
|
166
|
177
|
|| die "copr not found, try 'sudo install copr-cli'"
|
167
|
178
|
Tmp=$(mktemp -d)
|
168
|
179
|
while true; do case $1 in
|
|
180
|
+ -C) ConfFile=$2; shift 2 || usage ;;
|
169
|
181
|
-a) Action=$2; shift 2 || usage ;;
|
170
|
182
|
-b) Branch=$2; shift 2 || usage ;;
|
171
|
183
|
-c) CoprProject=$2; shift 2 || usage ;;
|
|
@@ -181,12 +193,14 @@ main() {
|
181
|
193
|
build|demo|mkspec|rpmstuff) : ;;
|
182
|
194
|
*) usage ;;
|
183
|
195
|
esac
|
184
|
|
- case $Mode in
|
185
|
|
- main|scratch) : ;;
|
186
|
|
- *) usage ;;
|
187
|
|
- esac
|
188
|
|
- test -n "$CoprProject" || CoprProject=$(choose_copr)
|
189
|
|
- test -n "$UrlBase" || UrlBase=$(choose_urlbase)
|
|
196
|
+ test -n "$ConfFile" || ConfFile=$TRIGGER_COPR_CONFIG
|
|
197
|
+ test -n "$ConfFile" || ConfFile=$(choose_conffile)
|
|
198
|
+ test -n "$ConfFile" || die "could not find config file"
|
|
199
|
+ test -r "$ConfFile" || die "could not read config file"
|
|
200
|
+ test -n "$PkgName" || PkgName=$TRIGGER_COPR_PKGNAME
|
|
201
|
+ test -n "$PkgName" || PkgName=${ConfFile%.trigger}
|
|
202
|
+ test -n "$CoprProject" || CoprProject=$(read_conffile copr)
|
|
203
|
+ test -n "$UrlBase" || UrlBase=$(read_conffile urlbase)
|
190
|
204
|
if test -n "$Branch"; then
|
191
|
205
|
die "not implemented"
|
192
|
206
|
test -n "$Version" || Version=$(git_guess ver)
|
|
@@ -196,7 +210,7 @@ main() {
|
196
|
210
|
test -n "$Release" || Release=1
|
197
|
211
|
fi
|
198
|
212
|
Release=$(choose_relpfx)$Release
|
199
|
|
- mkspec >"$Tmp/slop.spec"
|
|
213
|
+ mkspec >"$Tmp/$PkgName.spec"
|
200
|
214
|
do_action
|
201
|
215
|
rm -rf "$Tmp"
|
202
|
216
|
return $es
|