|
@@ -0,0 +1,118 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+
|
|
3
|
+warn() {
|
|
4
|
+ echo "$1" >&2
|
|
5
|
+}
|
|
6
|
+
|
|
7
|
+die() {
|
|
8
|
+ warn "fatal: $1"
|
|
9
|
+ exit 3
|
|
10
|
+}
|
|
11
|
+
|
|
12
|
+usage() {
|
|
13
|
+ warn "usage: $0 [options] COPR_PROJECT"
|
|
14
|
+ warn ""
|
|
15
|
+ warn "Options:"
|
|
16
|
+ warn ""
|
|
17
|
+ warn " -n dry mode, don't do anything (just show"
|
|
18
|
+ warn " what would be done)"
|
|
19
|
+ warn " -r REL use REL as Release number in SPEC file"
|
|
20
|
+ warn " -v VER use VER as Version number in SPEC file"
|
|
21
|
+ warn " -u URL use URL as base (to get last tag and"
|
|
22
|
+ warn " compose Source0 in SPEC file)"
|
|
23
|
+ warn ""
|
|
24
|
+ warn "If -r or -v are not specified, git-describe master"
|
|
25
|
+ warn "is consulted."
|
|
26
|
+ exit 2
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+last_version() {
|
|
30
|
+ git ls-remote --tag "$UrlBase" \
|
|
31
|
+ | grep '/tags/' \
|
|
32
|
+ | cut -d/ -f3 \
|
|
33
|
+ | sort -V \
|
|
34
|
+ | tail -1 \
|
|
35
|
+ | sed "s/^v//"
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+trigger() {
|
|
39
|
+ sed -e "
|
|
40
|
+ /^Version/ s|__SLOP_VERSION__|$Version|
|
|
41
|
+ /^Release/ s|__SLOP_RELEASE__|$Release|
|
|
42
|
+ /^Source0/ s|__SLOP_URLBASE__|$UrlBase|
|
|
43
|
+ " <slop.spec.in >"$Tmp/slop.spec"
|
|
44
|
+ copr build "$CoprProject" "$Tmp/slop.spec"
|
|
45
|
+}
|
|
46
|
+
|
|
47
|
+git_guess() {
|
|
48
|
+ #
|
|
49
|
+ # Print git-guessed $1
|
|
50
|
+ #
|
|
51
|
+ local what=$1 # what we want (ver|rel)
|
|
52
|
+ local describe # full git-describe output
|
|
53
|
+ local xtra= # extra part (-N-gHASH)
|
|
54
|
+ local num=0 # num. of commits since tag (N)
|
|
55
|
+ local sha= # '.g'+sha1 of this commit (gHASH)
|
|
56
|
+ describe=$(git describe --tags --always HEAD)
|
|
57
|
+ case $describe in
|
|
58
|
+ *-*) # v1.2.3-21-g654cba
|
|
59
|
+ tag=${describe%%-*} # tag=v1.2.3
|
|
60
|
+ xtra=${describe#$tag-} # xtra=-21-g654cba
|
|
61
|
+ num=${xtra%%-*} # num=21
|
|
62
|
+ sha=.${xtra#$num-} # sha=.g654cba
|
|
63
|
+ ;;
|
|
64
|
+ *)
|
|
65
|
+ tag=$describe
|
|
66
|
+ ;;
|
|
67
|
+ esac
|
|
68
|
+ case $what in
|
|
69
|
+ ver) echo "${tag#v}" ;;
|
|
70
|
+ rel) echo "$((num + 1))$sha" ;;
|
|
71
|
+ esac
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+main() {
|
|
75
|
+ local Version # Version in SPEC file
|
|
76
|
+ local Release # Release in SPEC file
|
|
77
|
+ local CoprProject # COPR project
|
|
78
|
+ local UrlBase # GitHub URL base
|
|
79
|
+ local Tmp # our temp
|
|
80
|
+ local Branch # branch to use, if empty, tags are considered
|
|
81
|
+ local DryRun=false # do not do anything
|
|
82
|
+ UrlBase=https://github.com/AloisMahdal/slop
|
|
83
|
+ Tmp=$(mktemp -d)
|
|
84
|
+ while true; do case $1 in
|
|
85
|
+ -b) Branch=$2; shift 2 || usage ;;
|
|
86
|
+ -u) UrlBase=$2; shift 2 || usage ;;
|
|
87
|
+ -r) Release=$2; shift 2 || usage ;;
|
|
88
|
+ -v) Version=${2#v}; shift 2 || usage ;;
|
|
89
|
+ -n) DryRun=true; shift ;;
|
|
90
|
+ -*) usage ;;
|
|
91
|
+ *) break ;;
|
|
92
|
+ esac done
|
|
93
|
+ CoprProject=$1
|
|
94
|
+ test -n "$CoprProject" || usage
|
|
95
|
+ which copr >/dev/null \
|
|
96
|
+ || die "copr not found, try 'sudo install python-copr'"
|
|
97
|
+ if test -n "$Branch"; then
|
|
98
|
+ die "not implemented"
|
|
99
|
+ test -n "$Version" || Version=$(git_guess ver)
|
|
100
|
+ test -n "$Release" || Release=$(git_guess rel)
|
|
101
|
+ else
|
|
102
|
+ test -n "$Version" || Version=$(last_version)
|
|
103
|
+ test -n "$Release" || Release=1
|
|
104
|
+ fi
|
|
105
|
+ $DryRun && {
|
|
106
|
+ warn "dry mode active, we would build:"
|
|
107
|
+ warn " at $CoprProject"
|
|
108
|
+ test -n "$Branch" && warn " using branch $Branch"
|
|
109
|
+ test -n "$Branch" || warn " using last tag"
|
|
110
|
+ warn " from $UrlBase"
|
|
111
|
+ warn " yielding slop-$Version-$Release.*.rpm"
|
|
112
|
+ exit 1
|
|
113
|
+ }
|
|
114
|
+ trigger
|
|
115
|
+ rm -rf "$Tmp"
|
|
116
|
+}
|
|
117
|
+
|
|
118
|
+main "$@"
|