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