[PATCH 5/5] Switch to dash when possible
Artem Bityutskiy
dedekind1 at gmail.com
Wed Feb 5 02:50:52 PST 2014
From: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
Aiaiai is written in a portable manner, meaning that it does not use Bash
features and should work with different shells, like dash and ksh. Actually,
dash is a nice, small, and fast shell implementing only POSIX feature (or may
be mostly), and it is good to use it when it is available. This will ensure
that we do not accidentally break protability.
This patch adds a small code snippet to each script which will check if dash is
installed in the system, and if it is, "re-start" with dash.
People hacking on Aiaiai are encouradge to install the 'dash' package on their
systems.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
---
aiaiai-checker | 7 +++++++
aiaiai-diff-log | 7 +++++++
aiaiai-make-kernel | 7 +++++++
aiaiai-match-keywords | 8 ++++++++
aiaiai-sh-functions | 12 ++++++++++++
aiaiai-test-bisectability | 7 +++++++
aiaiai-test-patchset | 7 +++++++
email/aiaiai-email-dispatcher | 7 +++++++
email/aiaiai-email-dispatcher-helper | 8 ++++++++
email/aiaiai-email-lda | 7 +++++++
email/aiaiai-email-test-patchset | 7 +++++++
jenkins/aiaiai-jenkins-test-patchset | 8 ++++++++
12 files changed, 92 insertions(+)
diff --git a/aiaiai-checker b/aiaiai-checker
index 929423a..5ca71c3 100755
--- a/aiaiai-checker
+++ b/aiaiai-checker
@@ -15,6 +15,13 @@ PATH="$srcdir:$srcdir/external/libshell:$srcdir/external:$PATH"
PROG="${0##*/}"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/aiaiai-diff-log b/aiaiai-diff-log
index cc4a63c..55c2136 100755
--- a/aiaiai-diff-log
+++ b/aiaiai-diff-log
@@ -17,6 +17,13 @@ PATH="$srcdir:$srcdir/external/libshell:$srcdir/external:$PATH"
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/aiaiai-make-kernel b/aiaiai-make-kernel
index bba9957..5ce11aa 100755
--- a/aiaiai-make-kernel
+++ b/aiaiai-make-kernel
@@ -16,6 +16,13 @@ export PATH="$srcdir:$srcdir/external/libshell:$srcdir/external:$PATH"
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/aiaiai-match-keywords b/aiaiai-match-keywords
index 4488853..701f459 100755
--- a/aiaiai-match-keywords
+++ b/aiaiai-match-keywords
@@ -10,10 +10,18 @@ PATH="$srcdir:$srcdir/external/libshell:$PATH"
. shell-error
. shell-args
. shell-quote
+. aiaiai-sh-functions
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/aiaiai-sh-functions b/aiaiai-sh-functions
index 0eb6840..abbd0f4 100644
--- a/aiaiai-sh-functions
+++ b/aiaiai-sh-functions
@@ -28,6 +28,18 @@ print_separator()
echo
}
+# Check if dash is available and we are not running in dash
+can_switch_to_dash()
+{
+ if command -v "dash" >/dev/null 2>&1; then
+ if [ -n "${BASH_VERSION:-}" ]; then
+ return 0
+ fi
+ fi
+
+ return 1
+}
+
# Die if a program is not in PATH
# Usage: program_required <program_name>
program_required()
diff --git a/aiaiai-test-bisectability b/aiaiai-test-bisectability
index bc46f9b..121312a 100755
--- a/aiaiai-test-bisectability
+++ b/aiaiai-test-bisectability
@@ -15,6 +15,13 @@ PATH="$srcdir:$srcdir/external/libshell:$srcdir/external:$PATH"
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/aiaiai-test-patchset b/aiaiai-test-patchset
index 58287cc..b231d30 100755
--- a/aiaiai-test-patchset
+++ b/aiaiai-test-patchset
@@ -15,6 +15,13 @@ PATH="$srcdir:$srcdir/external/libshell:$srcdir/external:$PATH"
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/email/aiaiai-email-dispatcher b/email/aiaiai-email-dispatcher
index 4e303d9..9fa7847 100755
--- a/email/aiaiai-email-dispatcher
+++ b/email/aiaiai-email-dispatcher
@@ -15,6 +15,13 @@ PATH="$srcdir:$srcdir/email:$srcdir/external/libshell:$PATH"
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/email/aiaiai-email-dispatcher-helper b/email/aiaiai-email-dispatcher-helper
index ab65849..91722b0 100755
--- a/email/aiaiai-email-dispatcher-helper
+++ b/email/aiaiai-email-dispatcher-helper
@@ -9,10 +9,18 @@ PATH="$srcdir:$srcdir/email:$srcdir/external/libshell:$PATH"
. shell-error
. shell-signal
+. aiaiai-sh-functions
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/email/aiaiai-email-lda b/email/aiaiai-email-lda
index de2cfb0..02a4a6b 100755
--- a/email/aiaiai-email-lda
+++ b/email/aiaiai-email-lda
@@ -16,6 +16,13 @@ PATH="$srcdir:$srcdir/email:$srcdir/external/libshell:$PATH"
PROG="${0##*/}"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset
index 77ead41..97083b2 100755
--- a/email/aiaiai-email-test-patchset
+++ b/email/aiaiai-email-test-patchset
@@ -16,6 +16,13 @@ PATH="$srcdir:$srcdir/email:$srcdir/external/libshell:$PATH"
PROG="${0##*/}"
export message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
diff --git a/jenkins/aiaiai-jenkins-test-patchset b/jenkins/aiaiai-jenkins-test-patchset
index 721cff9..bc5c948 100755
--- a/jenkins/aiaiai-jenkins-test-patchset
+++ b/jenkins/aiaiai-jenkins-test-patchset
@@ -13,8 +13,16 @@ PATH="$srcdir/..:$srcdir/../external/libshell:$PATH"
. shell-quote
. aiaiai-sh-functions
+PROG="aiaiai-jenkins-test-patchset"
message_time="yes"
+# This is a small trick to make sure the script is portable - check if 'dash'
+# is present, and if yes - use it.
+if can_switch_to_dash; then
+ exec dash -euf -- "$srcdir/$PROG" "$@"
+ exit $?
+fi
+
show_usage()
{
cat <<-EOF
--
1.8.5.2
More information about the aiaiai
mailing list