Sfoglia il codice sorgente

Add somewhat hacky but working version

Alois Mahdal 6 anni fa
parent
commit
a16fba83cf
4 ha cambiato i file con 281 aggiunte e 0 eliminazioni
  1. 4
    0
      README.md
  2. 37
    0
      light.spec.in
  3. 12
    0
      light.trigger
  4. 228
    0
      trigger_copr

+ 4
- 0
README.md Vedi File

@@ -0,0 +1,4 @@
1
+README
2
+======
3
+
4
+This repo contains script to build `light` at my Fedora COPR.

+ 37
- 0
light.spec.in Vedi File

@@ -0,0 +1,37 @@
1
+Name:       light
2
+Version:    __APP_VERSION__
3
+Release:    __APP_RELEASE__%{?dist}
4
+Summary:    Command line tool to control backlight controllers
5
+URL:        https://github.com/haikarainen/light
6
+
7
+License:    GPLv3
8
+Source0:   __APP_URLBASE__/archive/%{version}.tar.gz
9
+
10
+# BuildRequires: autoconf
11
+# BuildRequires: automake
12
+
13
+%description
14
+Light is a program to control backlight controllers under GNU/Linux.
15
+
16
+%prep
17
+%autosetup -n %{name}-%{version}
18
+sed -i -e 's/chown root//' Makefile
19
+sed -i -e 's/chmod 4755//' Makefile
20
+
21
+%build
22
+make %{?_smp_mflags}
23
+
24
+%install
25
+%make_install
26
+
27
+%files
28
+%doc README.md
29
+%license LICENSE
30
+%{_bindir}/light
31
+%{_mandir}/man1/light.1.gz
32
+
33
+%changelog
34
+* __APP_DATE__ Alois Mahdal <netvor+light@vornet.cz> - __APP_VERSION__-__APP_RELEASE__
35
+- Unofficial experimental RPM pseudo-release
36
+
37
+# spec file generated from __APP_BUILDSCRIPT_VERSION__

+ 12
- 0
light.trigger Vedi File

@@ -0,0 +1,12 @@
1
+# list of mode data
2
+#
3
+# Format:
4
+#
5
+#   *  MODE is mode name
6
+#   *  URLBASE is GitHub address to get latest source from
7
+#   *  COPR is COPR project name,
8
+#
9
+#
10
+# MODE   URLBASE                                COPR
11
+scratch  https://gitea.vornet.cz/netvor/light   netvor/light-scratch
12
+main     https://github.com/haikarainen/light   netvor/light

+ 228
- 0
trigger_copr Vedi File

@@ -0,0 +1,228 @@
1
+#!/bin/bash
2
+
3
+TRIGGER_COPR_CONFIG=${TRIGGER_COPR_CONFIG:-}
4
+TRIGGER_COPR_PKGNAME=${TRIGGER_COPR_PKGNAME:-}
5
+
6
+warn() {
7
+    echo "$1" >&2
8
+}
9
+
10
+die() {
11
+    warn "fatal: $1"
12
+    exit 3
13
+}
14
+
15
+usage() {
16
+    warn "usage: $0 [options] MODE"
17
+    warn ""
18
+    warn "Options:"
19
+    warn ""
20
+    warn "  -b BRN  build from branch BRN (default: last tag)"
21
+    warn "  -c COPR_PROJECT  COPR project name"
22
+    warn "  -C CONF   config file"
23
+    warn "  -n      dry mode, don't do anything (just show"
24
+    warn "          what would be done)"
25
+    warn "  -r REL  use REL as Release number in SPEC file"
26
+    warn "  -v VER  use VER as Version number in SPEC file"
27
+    warn "  -u URL  use URL as base (to get last tag and"
28
+    warn "          compose Source0 in SPEC file)"
29
+    warn ""
30
+    warn "If -b is not used, build is launched from last tag available"
31
+    warn "in the GitHub repo.  In that case, Release is '1' and Version"
32
+    warn "is deduced from the tag by removing the initial 'v'."
33
+    warn ""
34
+    warn "If -b is used, the project repo is temporarily cloned, and"
35
+    warn "both Version and Release are found by consulting git-describe"
36
+    warn "on the specified branch."
37
+    warn ""
38
+    warn "If MODE is 'scratch' (default), Release is pre-fixed by string"
39
+    warn "'0.scratch.' and build is triggered in scratch COPR project."
40
+    exit 2
41
+}
42
+
43
+last_version() {
44
+#   git ls-remote --tag "$UrlBase" \
45
+#     | grep '/tags/' \
46
+#     | cut -d/ -f3 \
47
+#     | grep -v '[^0-9a-z.]' \
48
+#     | sort -V \
49
+#     | tail -1 \
50
+#     | sed "s/^v//"
51
+    git ls-remote --tag "$UrlBase" \
52
+      | grep /tags \
53
+      | cut -d/ -f3 \
54
+      | grep -E '[0-9]+[.][0-9.]+$' \
55
+      | grep -v ^v \
56
+      | sort -V \
57
+      | tail -1
58
+}
59
+
60
+mkspec() {
61
+    local self_version
62
+    local cl_date
63
+    self_version="$(basename "$0") $(git describe --tags)"
64
+    cl_date=$(LC_ALL=C date +"%a %b %d %Y")
65
+    sed -e "
66
+        s|__APP_VERSION__|$Version|
67
+        s|__APP_RELEASE__|$Release|
68
+        s|__APP_URLBASE__|$UrlBase|
69
+        s|__APP_BUILDSCRIPT_VERSION__|$self_version|
70
+        s|__APP_DATE__|$cl_date|
71
+    " <"$PkgName.spec.in"
72
+}
73
+
74
+git_guess() {
75
+    #
76
+    # Print git-guessed $1
77
+    #
78
+    local what=$1   # what we want (ver|rel)
79
+    local describe  # full git-describe output
80
+    local xtra=     # extra part (-N-gHASH)
81
+    local num=0     # num. of commits since tag (N)
82
+    local sha=      # '.g'+sha1 of this commit (gHASH)
83
+    describe=$(git describe --tags --always HEAD)
84
+    case $describe in
85
+        *-*)                        #     v1.2.3-21-g654cba
86
+            tag=${describe%%-*}     # tag=v1.2.3
87
+            xtra=${describe#$tag-}  # xtra=-21-g654cba
88
+            num=${xtra%%-*}         # num=21
89
+            sha=.${xtra#$num-}      # sha=.g654cba
90
+            ;;
91
+        *)
92
+            tag=$describe
93
+            ;;
94
+    esac
95
+    case $what in
96
+        ver)    echo "${tag#v}"         ;;
97
+        rel)    echo "$((num + 1))$sha" ;;
98
+    esac
99
+}
100
+
101
+choose_relpfx() {
102
+    #
103
+    # Choose COPR project based on $Mode
104
+    #
105
+    test "$Mode" == scratch && echo 0.scratch.
106
+    return 0
107
+}
108
+
109
+read_conffile() {
110
+    #
111
+    # Read item T
112
+    #
113
+    local what=$1
114
+    local fieldn
115
+    case $what in
116
+        urlbase) fieldn=2 ;;
117
+        copr)    fieldn=3 ;;
118
+    esac
119
+    grep -v '^[[:blank:]]*#' "$ConfFile" \
120
+      | grep "^ *$Mode\>" \
121
+      | sed 's/  */ /g' \
122
+      | cut -d' ' -f$fieldn
123
+}
124
+
125
+choose_conffile() {
126
+    #
127
+    # Find config file and echo its name
128
+    #
129
+    find . -name '*.trigger' \
130
+      | cut -d/ -f2 \
131
+      | grep .
132
+}
133
+
134
+do_action() {
135
+    local url
136
+    case $Action in
137
+        build)
138
+            copr build "$CoprProject" "$Tmp/$PkgName.spec"
139
+            printf '\a'
140
+            ;;
141
+        demo)
142
+            warn "demo mode active, we would build:"
143
+            warn "    at $CoprProject"
144
+            test -n "$Branch" && warn "    using branch $Branch"
145
+            test -n "$Branch" || warn "    using last tag"
146
+            warn "    from $UrlBase"
147
+            warn "    yielding $PkgName-$Version-$Release.*.rpm"
148
+            warn ""
149
+            warn "===== BEGIN $PkgName.spec ====="
150
+            cat "$Tmp/$PkgName.spec"
151
+            warn "===== END $PkgName.spec ====="
152
+            return 1
153
+            ;;
154
+        mkspec)
155
+            cat "$Tmp/$PkgName.spec"
156
+            ;;
157
+        rpmstuff)
158
+            url=$(
159
+                grep -o 'Source.*:.*http.*' "$Tmp/$PkgName.spec" \
160
+                  | sed "
161
+                        s/.*http/http/
162
+                        s/ *$//
163
+                        s/%{version}/$Version/g
164
+                        s/%{name}/$PkgName/g
165
+                    "
166
+            )
167
+            wget --quiet "$url"
168
+            cat "$Tmp/$PkgName.spec" > "$PkgName.spec"
169
+            ;;
170
+    esac
171
+}
172
+
173
+main() {
174
+    local Version       # Version in SPEC file
175
+    local Release       # Release in SPEC file
176
+    local CoprProject   # COPR project
177
+    local UrlBase       # GitHub URL base
178
+    local Tmp           # our temp
179
+    local Branch        # branch to use, if empty, tags are considered
180
+    local Mode=scratch  # implies COPR project and release prefix
181
+    local Action=build  # what to do
182
+    local ConfFile      # config file to use
183
+    local PkgName       # package name
184
+    local es=0          # exit status
185
+    which copr >/dev/null \
186
+     || die "copr not found, try 'sudo install copr-cli'"
187
+    Tmp=$(mktemp -d)
188
+    while true; do case $1 in
189
+        -C) ConfFile=$2;    shift 2 || usage ;;
190
+        -a) Action=$2;      shift 2 || usage ;;
191
+        -b) Branch=$2;      shift 2 || usage ;;
192
+        -c) CoprProject=$2; shift 2 || usage ;;
193
+        -u) UrlBase=$2;     shift 2 || usage ;;
194
+        -r) Release=$2;     shift 2 || usage ;;
195
+        -v) Version=${2#v}; shift 2 || usage ;;
196
+        -n) Action=demo;    shift ;;
197
+        -*) usage ;;
198
+        *)  break ;;
199
+    esac done
200
+    Mode=${1:-$Mode}
201
+    case $Action in
202
+        build|demo|mkspec|rpmstuff) : ;;
203
+        *) usage ;;
204
+    esac
205
+    test -n "$ConfFile" || ConfFile=$TRIGGER_COPR_CONFIG
206
+    test -n "$ConfFile" || ConfFile=$(choose_conffile)
207
+    test -n "$ConfFile" || die "could not find config file"
208
+    test -r "$ConfFile" || die "could not read config file"
209
+    test -n "$PkgName"  || PkgName=$TRIGGER_COPR_PKGNAME
210
+    test -n "$PkgName"  || PkgName=${ConfFile%.trigger}
211
+    test -n "$CoprProject" || CoprProject=$(read_conffile copr)
212
+    test -n "$UrlBase"     || UrlBase=$(read_conffile urlbase)
213
+    if test -n "$Branch"; then
214
+        die "not implemented"
215
+        test -n "$Version" || Version=$(git_guess ver)
216
+        test -n "$Release" || Release=$(git_guess rel)
217
+    else
218
+        test -n "$Version" || Version=$(last_version)
219
+        test -n "$Release" || Release=1
220
+    fi
221
+    Release=$(choose_relpfx)$Release
222
+    mkspec >"$Tmp/$PkgName.spec"
223
+        do_action
224
+    rm -rf "$Tmp"
225
+    return $es
226
+}
227
+
228
+main "$@"