[PATCH] Make symlink-mesa.sh Bourne compatible

Dan Nicholson dbn.lists at gmail.com
Sat Mar 8 08:56:55 PST 2008


Fixed a few problems for the Heirloom Bourne shell[1] which should make
symlink-mesa.sh more portable:
 - No -e operator for simply checking existence. Instead, the test uses
   the -r operator since we need the files and directories readable.
 - Quoting of potentially empty arguments to test. [ -z $foo ] when $foo
   is empty causes a lot of Bourne shells problems. Best to quote it.
 - Lack of `echo -n'. Copied the feature test from Autoconf to find if
   the shell respects -n or to otherwise add \c at the end of line.
 - `VAR=newval command' does not seem to work. Instead, the variable is
   just changed in the environment prior to the command.

1. http://heirloom.sourceforge.net/sh.html
---
 GL/symlink-mesa.sh |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/GL/symlink-mesa.sh b/GL/symlink-mesa.sh
index af9adbd..d9e02eb 100755
--- a/GL/symlink-mesa.sh
+++ b/GL/symlink-mesa.sh
@@ -28,7 +28,7 @@ check_destinations () {
 check_exist() {
     # Check whether $1 exists
 
-    if [ ! -e $1 ] ; then
+    if [ ! -r "$1" ] ; then
 	error "$1 not found"
     fi
 }
@@ -42,7 +42,7 @@ delete_existing() {
 link_files() {
     # Link $1 to $2
 
-    if [ ! -e $2 ] ; then
+    if [ ! -r "$2" ] ; then
 	ln -s $1 $2
     fi
 }
@@ -252,7 +252,7 @@ symlink_glx() {
 
 error() {
 	echo
-	echo \ \ \ error:\ \ \ $1
+	echo "   error:   $1"
 	exit 1
 }
 
@@ -260,7 +260,7 @@ error() {
 run_module() {
     # $1 module
     # $2 explanation
-    echo -n $EXPLANATION for $1 module ...\ 
+    echo $ECHO_N "$EXPLANATION for $1 module ... $ECHO_C"
     symlink_$1
     echo DONE
 }
@@ -269,8 +269,9 @@ run() {
     # $1 what to do
     # $2 explanation
 
-    ACTION=$1 EXPLANATION=$2 run_module mesa
-    ACTION=$1 EXPLANATION=$2 run_module glx
+    ACTION=$1 EXPLANATION=$2
+    run_module mesa
+    run_module glx
 }
 
 src_dir() {
@@ -288,7 +289,7 @@ dst_dir() {
 }
 
 action() {
-    if [ -z $2 ] ; then
+    if [ -z "$2" ] ; then
 	$ACTION	$REAL_SRC_DIR/$1	$REAL_DST_DIR/$1
     else
 	$ACTION	$REAL_SRC_DIR/$1	$REAL_DST_DIR/$2
@@ -303,13 +304,13 @@ usage() {
 
 # Check commandline args
 check_args() {
-    if [ -z $1 ] ; then
+    if [ -z "$1" ] ; then
 	echo Missing source dir
 	usage
 	exit 1
     fi
 
-    if [ -z $2 ] ; then
+    if [ -z "$2" ] ; then
 	echo Missing destination dir
 	usage
 	exit 1
@@ -337,8 +338,19 @@ check_args() {
     B=`basename "$relpath"`
     abspath="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
 
-    SRC_DIR=`( cd $1 ; pwd )`
-    DST_DIR=`(cd $2 ; pwd )`
+    SRC_DIR=`cd $1 ; pwd`
+    DST_DIR=`cd $2 ; pwd`
 }
 
+# echo -n feature test, this is borrowed from Autoconf
+ECHO_C= ECHO_N=
+case `echo -n x` in
+-n*)
+  case `echo 'x\c'` in
+  *)   ECHO_C='\c';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
 main $1 $2
-- 
1.5.3.2




More information about the xorg mailing list