Browse Source

Read project-specific data from config file

Alois Mahdal 6 years ago
parent
commit
15c5f65be8
2 changed files with 57 additions and 31 deletions
  1. 12
    0
      slop.trigger
  2. 45
    31
      trigger_copr

+ 12
- 0
slop.trigger View File

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://github.com/AloisMahdal/slop amahdal/slop
12
+main     https://github.com/naelstrof/slop   amahdal/slop-scratch

+ 45
- 31
trigger_copr View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
+TRIGGER_COPR_CONFIG=${TRIGGER_COPR_CONFIG:-}
4
+TRIGGER_COPR_PKGNAME=${TRIGGER_COPR_PKGNAME:-}
5
+
3
 warn() {
6
 warn() {
4
     echo "$1" >&2
7
     echo "$1" >&2
5
 }
8
 }
16
     warn ""
19
     warn ""
17
     warn "  -b BRN  build from branch BRN (default: last tag)"
20
     warn "  -b BRN  build from branch BRN (default: last tag)"
18
     warn "  -c COPR_PROJECT  COPR project name"
21
     warn "  -c COPR_PROJECT  COPR project name"
22
+    warn "  -C CONF   config file"
19
     warn "  -n      dry mode, don't do anything (just show"
23
     warn "  -n      dry mode, don't do anything (just show"
20
     warn "          what would be done)"
24
     warn "          what would be done)"
21
     warn "  -r REL  use REL as Release number in SPEC file"
25
     warn "  -r REL  use REL as Release number in SPEC file"
49
 mkspec() {
53
 mkspec() {
50
     local self_version
54
     local self_version
51
     local cl_date
55
     local cl_date
52
-    self_version="slop-build-copr $(git describe --tags)"
56
+    self_version="$(basename "$0") $(git describe --tags)"
53
     cl_date=$(LC_ALL=C date +"%a %b %d %Y")
57
     cl_date=$(LC_ALL=C date +"%a %b %d %Y")
54
     sed -e "
58
     sed -e "
55
         s|__APP_VERSION__|$Version|
59
         s|__APP_VERSION__|$Version|
57
         s|__APP_URLBASE__|$UrlBase|
61
         s|__APP_URLBASE__|$UrlBase|
58
         s|__APP_BUILDSCRIPT_VERSION__|$self_version|
62
         s|__APP_BUILDSCRIPT_VERSION__|$self_version|
59
         s|__APP_DATE__|$cl_date|
63
         s|__APP_DATE__|$cl_date|
60
-    " <slop.spec.in
64
+    " <"$PkgName.spec.in"
61
 }
65
 }
62
 
66
 
63
 git_guess() {
67
 git_guess() {
87
     esac
91
     esac
88
 }
92
 }
89
 
93
 
90
-choose_copr() {
94
+choose_relpfx() {
91
     #
95
     #
92
     # Choose COPR project based on $Mode
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
     esac
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
 do_action() {
127
 do_action() {
119
     local url
128
     local url
120
     case $Action in
129
     case $Action in
121
         build)
130
         build)
122
-            copr build "$CoprProject" "$Tmp/slop.spec"
131
+            copr build "$CoprProject" "$Tmp/$PkgName.spec"
123
             ;;
132
             ;;
124
         demo)
133
         demo)
125
             warn "demo mode active, we would build:"
134
             warn "demo mode active, we would build:"
127
             test -n "$Branch" && warn "    using branch $Branch"
136
             test -n "$Branch" && warn "    using branch $Branch"
128
             test -n "$Branch" || warn "    using last tag"
137
             test -n "$Branch" || warn "    using last tag"
129
             warn "    from $UrlBase"
138
             warn "    from $UrlBase"
130
-            warn "    yielding slop-$Version-$Release.*.rpm"
139
+            warn "    yielding $PkgName-$Version-$Release.*.rpm"
131
             warn ""
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
             return 1
144
             return 1
136
             ;;
145
             ;;
137
         mkspec)
146
         mkspec)
138
-            cat "$Tmp/slop.spec"
147
+            cat "$Tmp/$PkgName.spec"
139
             ;;
148
             ;;
140
         rpmstuff)
149
         rpmstuff)
141
             url=$(
150
             url=$(
142
-                grep -o 'Source.*:.*http.*' "$Tmp/slop.spec" \
151
+                grep -o 'Source.*:.*http.*' "$Tmp/$PkgName.spec" \
143
                   | sed "
152
                   | sed "
144
                         s/.*http/http/
153
                         s/.*http/http/
145
                         s/ *$//
154
                         s/ *$//
147
                     "
156
                     "
148
             )
157
             )
149
             wget --quiet "$url"
158
             wget --quiet "$url"
150
-            cat "$Tmp/slop.spec" > slop.spec
159
+            cat "$Tmp/$PkgName.spec" > "$PkgName.spec"
151
             ;;
160
             ;;
152
     esac
161
     esac
153
 }
162
 }
161
     local Branch        # branch to use, if empty, tags are considered
170
     local Branch        # branch to use, if empty, tags are considered
162
     local Mode=scratch  # implies COPR project and release prefix
171
     local Mode=scratch  # implies COPR project and release prefix
163
     local Action=build  # what to do
172
     local Action=build  # what to do
173
+    local ConfFile      # config file to use
174
+    local PkgName       # package name
164
     local es=0          # exit status
175
     local es=0          # exit status
165
     which copr >/dev/null \
176
     which copr >/dev/null \
166
      || die "copr not found, try 'sudo install copr-cli'"
177
      || die "copr not found, try 'sudo install copr-cli'"
167
     Tmp=$(mktemp -d)
178
     Tmp=$(mktemp -d)
168
     while true; do case $1 in
179
     while true; do case $1 in
180
+        -C) ConfFile=$2;    shift 2 || usage ;;
169
         -a) Action=$2;      shift 2 || usage ;;
181
         -a) Action=$2;      shift 2 || usage ;;
170
         -b) Branch=$2;      shift 2 || usage ;;
182
         -b) Branch=$2;      shift 2 || usage ;;
171
         -c) CoprProject=$2; shift 2 || usage ;;
183
         -c) CoprProject=$2; shift 2 || usage ;;
181
         build|demo|mkspec|rpmstuff) : ;;
193
         build|demo|mkspec|rpmstuff) : ;;
182
         *) usage ;;
194
         *) usage ;;
183
     esac
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
     if test -n "$Branch"; then
204
     if test -n "$Branch"; then
191
         die "not implemented"
205
         die "not implemented"
192
         test -n "$Version" || Version=$(git_guess ver)
206
         test -n "$Version" || Version=$(git_guess ver)
196
         test -n "$Release" || Release=1
210
         test -n "$Release" || Release=1
197
     fi
211
     fi
198
     Release=$(choose_relpfx)$Release
212
     Release=$(choose_relpfx)$Release
199
-    mkspec >"$Tmp/slop.spec"
213
+    mkspec >"$Tmp/$PkgName.spec"
200
         do_action
214
         do_action
201
     rm -rf "$Tmp"
215
     rm -rf "$Tmp"
202
     return $es
216
     return $es