Browse Source

Add -a argument for multiple actions

Alois Mahdal 7 years ago
parent
commit
e291f3016a
1 changed files with 47 additions and 16 deletions
  1. 47
    16
      trigger_copr

+ 47
- 16
trigger_copr View File

114
     return 0
114
     return 0
115
 }
115
 }
116
 
116
 
117
+do_action() {
118
+    local url
119
+    case $Action in
120
+        build)
121
+            copr build "$CoprProject" "$Tmp/slop.spec"
122
+            ;;
123
+        demo)
124
+            warn "demo mode active, we would build:"
125
+            warn "    at $CoprProject"
126
+            test -n "$Branch" && warn "    using branch $Branch"
127
+            test -n "$Branch" || warn "    using last tag"
128
+            warn "    from $UrlBase"
129
+            warn "    yielding slop-$Version-$Release.*.rpm"
130
+            warn ""
131
+            warn "===== BEGIN slop.spec ====="
132
+            cat "$Tmp/slop.spec"
133
+            warn "===== END slop.spec ====="
134
+            return 1
135
+            ;;
136
+        mkspec)
137
+            cat "$Tmp/slop.spec"
138
+            ;;
139
+        rpmstuff)
140
+            url=$(
141
+                grep -o 'Source.*:.*http.*' "$Tmp/slop.spec" \
142
+                  | sed "
143
+                        s/.*http/http/
144
+                        s/ *$//
145
+                        s/%{version}/$Version/
146
+                    "
147
+            )
148
+            wget --quiet "$url"
149
+            cat "$Tmp/slop.spec" > slop.spec
150
+            ;;
151
+    esac
152
+}
153
+
117
 main() {
154
 main() {
118
     local Version       # Version in SPEC file
155
     local Version       # Version in SPEC file
119
     local Release       # Release in SPEC file
156
     local Release       # Release in SPEC file
121
     local UrlBase       # GitHub URL base
158
     local UrlBase       # GitHub URL base
122
     local Tmp           # our temp
159
     local Tmp           # our temp
123
     local Branch        # branch to use, if empty, tags are considered
160
     local Branch        # branch to use, if empty, tags are considered
124
-    local DryRun=false  # do not do anything
125
     local Mode=scratch  # implies COPR project and release prefix
161
     local Mode=scratch  # implies COPR project and release prefix
162
+    local Action=build  # what to do
163
+    local es=0          # exit status
126
     which copr >/dev/null \
164
     which copr >/dev/null \
127
      || die "copr not found, try 'sudo install copr-cli'"
165
      || die "copr not found, try 'sudo install copr-cli'"
128
     Tmp=$(mktemp -d)
166
     Tmp=$(mktemp -d)
129
     while true; do case $1 in
167
     while true; do case $1 in
168
+        -a) Action=$2;      shift 2 || usage ;;
130
         -b) Branch=$2;      shift 2 || usage ;;
169
         -b) Branch=$2;      shift 2 || usage ;;
131
         -c) CoprProject=$2; shift 2 || usage ;;
170
         -c) CoprProject=$2; shift 2 || usage ;;
132
         -u) UrlBase=$2;     shift 2 || usage ;;
171
         -u) UrlBase=$2;     shift 2 || usage ;;
133
         -r) Release=$2;     shift 2 || usage ;;
172
         -r) Release=$2;     shift 2 || usage ;;
134
         -v) Version=${2#v}; shift 2 || usage ;;
173
         -v) Version=${2#v}; shift 2 || usage ;;
135
-        -n) DryRun=true;    shift ;;
174
+        -n) Action=demo;    shift ;;
136
         -*) usage ;;
175
         -*) usage ;;
137
         *)  break ;;
176
         *)  break ;;
138
     esac done
177
     esac done
139
     Mode=${1:-$Mode}
178
     Mode=${1:-$Mode}
179
+    case $Action in
180
+        build|demo|mkspec|rpmstuff) : ;;
181
+        *) usage ;;
182
+    esac
140
     case $Mode in
183
     case $Mode in
141
         main|scratch) : ;;
184
         main|scratch) : ;;
142
         *)            usage ;;
185
         *)            usage ;;
153
     fi
196
     fi
154
     Release=$(choose_relpfx)$Release
197
     Release=$(choose_relpfx)$Release
155
     mkspec >"$Tmp/slop.spec"
198
     mkspec >"$Tmp/slop.spec"
156
-    $DryRun && {
157
-        warn "dry mode active, we would build:"
158
-        warn "    at $CoprProject"
159
-        test -n "$Branch" && warn "    using branch $Branch"
160
-        test -n "$Branch" || warn "    using last tag"
161
-        warn "    from $UrlBase"
162
-        warn "    yielding slop-$Version-$Release.*.rpm"
163
-        warn ""
164
-        warn "===== BEGIN slop.spec ====="
165
-        cat "$Tmp/slop.spec"
166
-        warn "===== END slop.spec ====="
167
-        exit 1
168
-    }
169
-    copr build "$CoprProject" "$Tmp/slop.spec"
199
+        do_action
170
     rm -rf "$Tmp"
200
     rm -rf "$Tmp"
201
+    return $es
171
 }
202
 }
172
 
203
 
173
 main "$@"
204
 main "$@"