chiark / gitweb /
Rewrite fd-commit in POSIX Shell
[fdroidserver.git] / fd-commit
1 #!/bin/sh
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         [ -z "$line" ] && continue
34
35         case "$line" in
36                 *\?\?*metadata/*.txt) new=true ;;
37                 *M*metadata/*.txt) new=false ;;
38         esac
39
40         file=${line##* }
41         id=${file##*/}
42         id=${id%.txt*}
43
44         if [ $# -gt 0 ]; then
45                 found=false
46                 for arg in "$@"; do
47                         if [ "$id" == "$arg" ]; then
48                                 found=true
49                                 break
50                         fi
51                 done
52                 $found || continue
53         fi
54
55         [ -d metadata/$id ] && extra=metadata/$id || extra=
56
57         name= autoname=
58         while read l; do
59                 case "$l" in
60                         'Auto Name:'*) autoname=${l#*:} ;;
61                         'Name:'*) name=${l#*:} ;;
62                 esac
63         done < "$file"
64
65         if [ -n "$name" ]; then
66                 fullname="$name"
67         elif [ -n "$autoname" ]; then
68                 fullname="$autoname"
69         else
70                 fullname="$id"
71         fi
72
73         if $new; then
74                 message="New app: $fullname"
75         else
76                 onlybuild=true
77                 newbuild=false
78                 disable=false
79
80                 while read l; do
81                         case "$l" in
82                                 *"Maintainer Notes:"*) break ;;
83                                 "-Build:"*) onlybuild=false ;;
84                                 "+Build:"*)
85                                         $newbuild && onlybuild=false
86                                         newbuild=true
87                                         build=${l#*:}
88                                         version=${build%%,*}
89                                         build=${build#*,}
90                                         vercode=${build%%,*}
91                                         ;;
92                                 '+'*"disable="*)
93                                         $newbuild && $onlybuild && disable=true
94                                         ;;
95                         esac
96                 done << EOF
97                 $(git diff HEAD -- "$file")
98 EOF
99
100                 if $newbuild && $onlybuild; then
101                         if $disable; then
102                                 message="Don't update $fullname to $version ($vercode)"
103                         else
104                                 message="Update $fullname to $version ($vercode)"
105                         fi
106                 else
107                         message="$fullname:"
108                 fi
109         fi
110
111         message=${message//\"/\\\"}
112         commands="$commands%%git add -- $file $extra && git commit -m \"$message\" -e -v"
113
114 done << EOF
115 $(git status --porcelain metadata)
116 EOF
117
118 [ -z "$commands" ] && exit 0
119
120 git reset >/dev/null
121 IFS='%%'
122 for cmd in $commands; do
123         [ -z "$cmd" ] && continue
124         eval $cmd
125         git reset >/dev/null
126 done