From 9cf2957242c572a332f732d359ea55c66f3964be Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Mon, 15 Sep 2014 19:46:14 +0100 Subject: buildsystem: maintdb slight modernisation+use bash explicitly. This is slightly subjective but most scripts do it this way these days without the extra letters on string comparisons and collapsing the if+then onto one line. --- modules/buildsystem/templates/maintdb/maintdb.bin | 43 ++++++++--------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'modules/buildsystem/templates') diff --git a/modules/buildsystem/templates/maintdb/maintdb.bin b/modules/buildsystem/templates/maintdb/maintdb.bin index 9fef3c64..6c40046c 100755 --- a/modules/buildsystem/templates/maintdb/maintdb.bin +++ b/modules/buildsystem/templates/maintdb/maintdb.bin @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash MAINTDBDIR="<%= scope.lookupvar('buildsystem::var::maintdb::dbdir') %>" @@ -15,15 +15,13 @@ function checkname() function maintnew() { - if [ a"$user" != "aroot" ] - then + if [ "$user" != "root" ]; then echo "Error: new is only allowed to root." >&2 exit 1 fi checkname "$1" maintfile="$MAINTDBDIR/$1" - if [ -f "$maintfile" ] - then + if [ -f "$maintfile" ]; then exit 0 fi echo "$2" > "$maintfile" @@ -34,26 +32,21 @@ function maintset() checkname "$1" maintfile="$MAINTDBDIR/$1" newmaint="$2" - if ! [ -f "$maintfile" ] - then + if [ ! -f "$maintfile" ]; then echo "Error: package $1 does not exist in maintdb." >&2 exit 1 fi curmaint=$(cat "$maintfile") - if [ a"$newmaint" = "anobody" ] - then - if [ a"$curmaint" = a"$user" ] - then + if [ "$newmaint" = "nobody" ]; then + if [ "$curmaint" = "$user" ]; then echo "$newmaint" > "$maintfile" exit 0 else echo "Error: cannot set maintainer for $1." >&2 exit 1 fi - elif [ a"$newmaint" = a"$user" ] - then - if [ a"$curmaint" = "anobody" ] - then + elif [ "$newmaint" = "$user" ]; then + if [ "$curmaint" = "nobody" ]; then echo "$newmaint" > "$maintfile" exit 0 else @@ -69,8 +62,7 @@ function maintset() function maintgetall() { cd "$MAINTDBDIR" - for file in * - do + for file in *; do echo "$file $(cat $file)" done exit 0 @@ -78,14 +70,12 @@ function maintgetall() function maintget() { - if [ -z "$1" ] - then + if [ -z "$1" ]; then maintgetall fi checkname "$1" maintfile="$MAINTDBDIR/$1" - if [ -f "$maintfile" ] - then + if [ -f "$maintfile" ]; then cat "$maintfile" else echo "Error: package $1 does not exist in maintdb." >&2 @@ -96,16 +86,13 @@ function maintget() user="$1" action="$2" -if [ a"$action" = "anew" ] -then +if [ "$action" = "new" ]; then maintnew "$3" "$4" -elif [ a"$action" = "aset" ] -then +elif [ "$action" = "set" ]; then maintset "$3" "$4" -elif [ a"$action" = "aget" ] -then +elif [ "$action" = "get" ]; then maintget "$3" else - echo "Error: unknow command." >&2 + echo "Error: unknown command." >&2 exit 2 fi -- cgit v1.2.1