chiark / gitweb /
Rewrite fd-commit in POSIX Shell
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 5 Jul 2014 11:01:17 +0000 (13:01 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Sat, 5 Jul 2014 11:01:17 +0000 (13:01 +0200)
fd-commit

index e4012de58838535d0bd1da8186ef026aaa003e57..9da979c5076434761b3eeb56535e5385ef3d5ad4 100755 (executable)
--- a/fd-commit
+++ b/fd-commit
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # fd-commit - part of the FDroid server tools
 # Commits updates to apps, allowing you to edit the commit messages
@@ -18,7 +18,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-commands=()
+commands=""
 
 if [ ! -d metadata ]; then
        if [ -d ../metadata ]; then
@@ -30,15 +30,17 @@ if [ ! -d metadata ]; then
 fi
 
 while read line; do
-       if [[ "$line" == *\?\?*metadata/*.txt ]]; then
-               new=true
-       elif [[ "$line" == *M*metadata/*.txt ]]; then
-               new=false
-       fi
-       file=${line##* }
+       [ -z "$line" ] && continue
+
+       case "$line" in
+               *\?\?*metadata/*.txt) new=true ;;
+               *M*metadata/*.txt) new=false ;;
+       esac
 
+       file=${line##* }
        id=${file##*/}
        id=${id%.txt*}
+
        if [ $# -gt 0 ]; then
                found=false
                for arg in "$@"; do
@@ -54,11 +56,10 @@ while read line; do
 
        name= autoname=
        while read l; do
-               if [[ "$l" == "Auto Name:"* ]]; then
-                       autoname=${l#*:}
-               elif [[ "$l" == "Name:"* ]]; then
-                       name=${l#*:}
-               fi
+               case "$l" in
+                       'Auto Name:'*) autoname=${l#*:} ;;
+                       'Name:'*) name=${l#*:} ;;
+               esac
        done < "$file"
 
        if [ -n "$name" ]; then
@@ -75,25 +76,26 @@ while read line; do
                onlybuild=true
                newbuild=false
                disable=false
+
                while read l; do
-                       if [[ "$l" == *"Maintainer Notes:"* ]]; then
-                               break
-                       fi
-                       if [[ "$l" == "-Build:"* ]]; then
-                               onlybuild=false
-                       elif [[ "$l" == "+Build:"* ]]; then
-                               if $newbuild; then
-                                       onlybuild=false
-                               fi
-                               newbuild=true
-                               build=${l#*:}
-                               version=${build%%,*}
-                               build=${build#*,}
-                               vercode=${build%%,*}
-                       elif $newbuild && $onlybuild && [[ "$l" == "+"*"disable="* ]]; then
-                               disable=true
-                       fi
-               done < <(git diff HEAD -- "$file")
+                       case "$l" in
+                               *"Maintainer Notes:"*) break ;;
+                               "-Build:"*) onlybuild=false ;;
+                               "+Build:"*)
+                                       $newbuild && onlybuild=false
+                                       newbuild=true
+                                       build=${l#*:}
+                                       version=${build%%,*}
+                                       build=${build#*,}
+                                       vercode=${build%%,*}
+                                       ;;
+                               '+'*"disable="*)
+                                       $newbuild && $onlybuild && disable=true
+                                       ;;
+                       esac
+               done << EOF
+               $(git diff HEAD -- "$file")
+EOF
 
                if $newbuild && $onlybuild; then
                        if $disable; then
@@ -107,13 +109,18 @@ while read line; do
        fi
 
        message=${message//\"/\\\"}
-       commands+=("git add -- $file $extra && git commit -m \"$message\" -e -v")
-done < <(git status --porcelain metadata)
+       commands="$commands%%git add -- $file $extra && git commit -m \"$message\" -e -v"
+
+done << EOF
+$(git status --porcelain metadata)
+EOF
 
-[[ -z $commands ]] && exit 0
+[ -z "$commands" ] && exit 0
 
 git reset >/dev/null
-for cmd in "${commands[@]}"; do
-       eval "$cmd"
+IFS='%%'
+for cmd in $commands; do
+       [ -z "$cmd" ] && continue
+       eval $cmd
        git reset >/dev/null
 done