chiark / gitweb /
Use 'case' instead of if/elif in the line matching logic
[fdroidserver.git] / fd-commit
1 #!/bin/bash
2 #
3 # fd-commit - part of the FDroid server tools
4 # Commits updates to apps, allowing you to edit the commit messages
5 #
6 # Copyright (C) 2013-2014 Daniel Martí <mvdan@mvdan.cc>
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Affero General Public License for more details.
17 #
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 commands=()
22
23 if [ ! -d metadata ]; then
24         if [ -d ../metadata ]; then
25                 cd ..
26         else
27                 echo "No metadata files found!"
28                 exit 2
29         fi
30 fi
31
32 while read line; do
33
34         case "$line" in
35                 *'??'*'metadata/'*'.txt') new=true ;;
36                 *'M'*'metadata/'*'.txt') new=false ;;
37         esac
38
39         file=${line##* }
40         id=${file##*/}
41         id=${id%.txt*}
42
43         if [ $# -gt 0 ]; then
44                 case "$@" in
45                         *" $id "*) ;;  # Middle
46                         "$id "*) ;;    # Start
47                         *" $id") ;;    # End
48                         "$id") ;;      # Alone
49                         *) continue ;; # Missing
50                 esac
51         fi
52
53         [ -d metadata/$id ] && extra=metadata/$id || extra=
54
55         name= autoname=
56         while read l; do
57                 case "$l" in
58                         'Auto Name:'*) autoname=${l#*:} ;;
59                         'Name:'*) name=${l#*:} ;;
60                 esac
61         done < "$file"
62
63         if [ -n "$name" ]; then
64                 fullname="$name"
65         elif [ -n "$autoname" ]; then
66                 fullname="$autoname"
67         else
68                 fullname="$id"
69         fi
70
71         if $new; then
72                 message="New app: $fullname"
73         else
74                 onlybuild=true
75                 newbuild=false
76                 disable=false
77                 while read line; do
78                         case "$line" in
79                                 *'Maintainer Notes:'*) break ;;
80                                 '-Build:'*) onlybuild=false ;;
81                                 '+Build:'*)
82                                         $newbuild && onlybuild=false
83                                         newbuild=true
84                                         build=${l#*:}
85                                         version=${build%%,*}
86                                         build=${build#*,}
87                                         vercode=${build%%,*}
88                                         ;;
89                                 '+'*'disable='*)
90                                         $newbuild && $onlybuild && disable=true
91                                         ;;
92                         esac
93                 done < <(git diff HEAD -- "$file")
94
95                 if $newbuild && $onlybuild; then
96                         if $disable; then
97                                 message="Don't update $fullname to $version ($vercode)"
98                         else
99                                 message="Update $fullname to $version ($vercode)"
100                         fi
101                 else
102                         message="$fullname:"
103                 fi
104         fi
105
106         message=${message//\"/\\\"}
107         commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
108
109 done < <(git status --porcelain metadata)
110
111 [ -z "$commands" ] && exit 0
112
113 git reset >/dev/null
114 for cmd in "${commands[@]}"; do
115         eval "$cmd"
116         git reset >/dev/null
117 done