chiark / gitweb /
Add copyright notices to bash scripts
[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 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         [ -d ../metadata ] && cd .. || { echo "No metadata files found!"; exit 2; }
25 fi
26
27 while read line; do
28         if [[ "$line" == *M*metadata/*.txt ]]; then
29                 file=${line##* }
30
31                 id=${file##*/}
32                 id=${id%.txt*}
33                 if [ $# -gt 0 ]; then
34                         found=false
35                         for arg in "$@"; do
36                                 if [ "$id" == "$arg" ]; then
37                                         found=true
38                                         break
39                                 fi
40                         done
41                         $found || continue
42                 fi
43
44                 if [ -d metadata/$id ]; then
45                         extra=metadata/$id
46                 else
47                         extra=
48                 fi
49
50                 name= autoname=
51                 while read l; do
52                         if [[ "$l" == "Auto Name:"* ]]; then
53                                 autoname=${l##*:}
54                         elif [[ "$l" == "Name:"* ]]; then
55                                 name=${l##*:}
56                         fi
57                 done < "$file"
58
59                 if [ -n "$name" ]; then
60                         fullname="$name ($id)"
61                 elif [ -n "$autoname" ]; then
62                         fullname="$autoname ($id)"
63                 else
64                         fullname="$id"
65                 fi
66
67                 newbuild=0
68                 while read l; do
69                         if [[ "$l" == "+Build:"* ]]; then
70                                 newbuild=1
71                                 build=${l#*:}
72                                 version=${build%%,*}
73                                 build=${build#*,}
74                                 vercode=${build%%,*}
75                         fi
76                 done < <(git diff HEAD -- "$file")
77
78                 if [ $newbuild -eq 0 ]; then
79                         message="$fullname:"
80                 else
81                         message="Update $fullname to $version ($vercode)"
82                 fi
83
84                 commands+=("git commit -m '$message' -e -v -- $file $extra")
85         fi
86 done < <(git status --porcelain)
87
88 for cmd in "${commands[@]}"; do
89         eval "$cmd"
90 done