[systemd-devel] [PATCH] Clean up bootstrap.sh

Victor Lowther victor.lowther at gmail.com
Sun Jun 6 08:47:10 PDT 2010


While toying around with systemd on Arch Linux, I noticed that the
bootstrap.sh could use some cleanups.  Here you go:

Make comparisons idiomatic bash ( [[ ]] instead of [ ] ).
Replace the three-way if in run_versioned with a for loop.
---
 bootstrap.sh |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index f59a815..c2ae321 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -22,19 +22,14 @@ AC_VERSION=2.63
 
 run_versioned() {
     local P
-    local V
 
-    V=$(echo "$2" | sed -e 's,\.,,g')
-
-    if [ -e "`which $1$V 2> /dev/null`" ] ; then
-        P="$1$V"
-    else
-        if [ -e "`which $1-$2 2> /dev/null`" ] ; then
-            P="$1-$2"
-        else
-            P="$1"
-        fi
-    fi
+    for P in "$1${2//,}" "$1-$2" "$1"; do
+	type -p "$P" >/dev/null && break
+	if [[ $P = $1 ]]; then
+	    echo "Cannot find required program $1, failing." >&2
+	    exit 1
+	fi
+    done
 
     shift 2
     "$P" "$@"
@@ -42,7 +37,7 @@ run_versioned() {
 
 set -ex
 
-if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
+if [[ -f .git/hooks/pre-commit.sample && ! -f .git/hooks/pre-commit ]] ; then
     cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \
     chmod +x .git/hooks/pre-commit && \
     echo "Activated pre-commit hook."
@@ -52,7 +47,7 @@ if type -p colorgcc > /dev/null ; then
    export CC=colorgcc
 fi
 
-if [ "x$1" = "xam" ] ; then
+if [[ $1 = am ]] ; then
     run_versioned automake "$VERSION" -a -c --foreign
     ./config.status
 else
@@ -64,8 +59,8 @@ else
     run_versioned autoheader "$AC_VERSION"
     run_versioned automake "$AM_VERSION" --copy --foreign --add-missing
 
-    if [ "x$1" != "xac" ]; then
-        CFLAGS="$CFLAGS -g -O0" ./configure --sysconfdir=/etc --localstatedir=/var --with-rootdir= "$@"
-        make clean
+    if [[ $1 != ac ]]; then
+	CFLAGS="$CFLAGS -g -O0" ./configure --sysconfdir=/etc --localstatedir=/var --with-rootdir= "$@"
+	make clean
     fi
 fi
-- 
1.7.1


-- 
Victor Lowther
LPIC2 UCP RHCE 



More information about the systemd-devel mailing list