[LEDE-DEV] [patch master 05/15] Use cd ... || exit in case cd fails

Jan-Tarek Butt tarek at ring0.de
Fri Sep 30 13:02:19 PDT 2016


---
 scripts/clean-package.sh         |  4 ++--
 scripts/deptest.sh               |  4 ++--
 scripts/ext-toolchain.sh         | 12 ++++++------
 scripts/get_source_date_epoch.sh |  2 +-
 scripts/getver.sh                |  2 +-
 scripts/patch-specs.sh           |  2 +-
 scripts/sysupgrade-tar.sh        |  2 +-
 7 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
index 5cae341..9efcac5 100755
--- a/scripts/clean-package.sh
+++ b/scripts/clean-package.sh
@@ -8,14 +8,14 @@
 	exit 1
 }
 cat "$1" | (
-	cd "$2"
+	cd "$2" || exit
 	while read entry; do
 		[ -n "$entry" ] || break
 		[ -f "$entry" ] && rm -f "$entry"
 	done
 )
 cat "$1" | (
-	cd "$2"
+	cd "$2" || exit
 	while read entry; do
 		[ -n "$entry" ] || break
 		[ -d "$entry" ] && rmdir "$entry" > /dev/null 2>&1
diff --git a/scripts/deptest.sh b/scripts/deptest.sh
index d7be99d..cce7caa 100755
--- a/scripts/deptest.sh
+++ b/scripts/deptest.sh
@@ -115,9 +115,9 @@ test_package() # $1=pkgname
 	local logfile="$(basename "$pkg").log"
 	deptest_make "package/$pkg/compile" "$logfile"
 	if [ $? -eq 0 ]; then
-		( cd "$STAMP_DIR_SUCCESS"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
+		( cd "$STAMP_DIR_SUCCESS" || exit; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
 	else
-		( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
+		( cd "$STAMP_DIR_FAILED" || exit; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
 		echo "Building package $pkg FAILED"
 	fi
 }
diff --git a/scripts/ext-toolchain.sh b/scripts/ext-toolchain.sh
index 8d8379e..9cd6e45 100755
--- a/scripts/ext-toolchain.sh
+++ b/scripts/ext-toolchain.sh
@@ -151,7 +151,7 @@ find_libs() {
 				sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'
 		); do
 			if [ -d "$libdir" ]; then
-				libdirs="$libdirs $(cd "$libdir"; pwd)/"
+				libdirs="$libdirs $(cd "$libdir" || exit; pwd)/"
 			fi
 		done
 
@@ -181,7 +181,7 @@ find_bins() {
 				sed -ne 's#:# #g; s#^COMPILER_PATH=##p'
 		); do
 			if [ -d "$bindir" ]; then
-				bindirs="$bindirs $(cd "$bindir"; pwd)/"
+				bindirs="$bindirs $(cd "$bindir" || exit; pwd)/"
 			fi
 		done
 
@@ -405,7 +405,7 @@ probe_cc() {
 			local cmd
 			for cmd in "$TOOLCHAIN/$bin/"*-*cc*; do
 				if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
-					CC="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
+					CC="$(cd "${cmd%/*}" || exit; pwd)/${cmd##*/}"
 					return 0
 				fi
 			done
@@ -422,7 +422,7 @@ probe_cxx() {
 			local cmd
 			for cmd in "$TOOLCHAIN/$bin/"*-*++*; do
 				if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
-					CXX="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
+					CXX="$(cd "${cmd%/*}" || exit; pwd)/${cmd##*/}"
 					return 0
 				fi
 			done
@@ -439,7 +439,7 @@ probe_cpp() {
 			local cmd
 			for cmd in "$TOOLCHAIN/$bin/"*-cpp*; do
 				if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
-					CPP="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
+					CPP="$(cd "${cmd%/*}" || exit; pwd)/${cmd##*/}"
 					return 0
 				fi
 			done
@@ -469,7 +469,7 @@ while [ -n "$1" ]; do
 				echo "Toolchain directory '$1' does not exist." >&2
 				exit 1
 			}
-			TOOLCHAIN="$(cd "$1"; pwd)"; shift
+			TOOLCHAIN="$(cd "$1" || exit; pwd)"; shift
 		;;
 
 		--cflags)
diff --git a/scripts/get_source_date_epoch.sh b/scripts/get_source_date_epoch.sh
index 1bec45f..fd3e9fd 100755
--- a/scripts/get_source_date_epoch.sh
+++ b/scripts/get_source_date_epoch.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 export LANG=C
 export LC_ALL=C
-[ -n "$TOPDIR" ] && cd "$TOPDIR"
+[ -n "$TOPDIR" ] && cd "$TOPDIR" || exit
 
 try_version() {
 	[ -f version.date ] || return 1
diff --git a/scripts/getver.sh b/scripts/getver.sh
index 7127eb2..f8b4ed3 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 export LANG=C
 export LC_ALL=C
-[ -n "$TOPDIR" ] && cd "$TOPDIR"
+[ -n "$TOPDIR" ] && cd "$TOPDIR" || exit
 
 GET_REV=$1
 
diff --git a/scripts/patch-specs.sh b/scripts/patch-specs.sh
index 3307b6b..a692632 100755
--- a/scripts/patch-specs.sh
+++ b/scripts/patch-specs.sh
@@ -3,7 +3,7 @@
 DIR="$1"
 
 if [ -d "$DIR" ]; then
-	DIR="$(cd "$DIR"; pwd)"
+	DIR="$(cd "$DIR" || exit; pwd)"
 else
 	echo "Usage: $0 toolchain-dir"
 	exit 1
diff --git a/scripts/sysupgrade-tar.sh b/scripts/sysupgrade-tar.sh
index 9995b7c..17b2f7a 100755
--- a/scripts/sysupgrade-tar.sh
+++ b/scripts/sysupgrade-tar.sh
@@ -61,7 +61,7 @@ if [ -n "$SOURCE_DATE_EPOCH" ]; then
 	mtime="--mtime=@${SOURCE_DATE_EPOCH}"
 fi
 
-(cd "$tmpdir"; tar cvf sysupgrade.tar sysupgrade-"${board}" "${mtime}")
+(cd "$tmpdir" || exit; tar cvf sysupgrade.tar sysupgrade-"${board}" "${mtime}")
 err="$?"
 if [ -e "$tmpdir/sysupgrade.tar" ]; then
 	cp "$tmpdir/sysupgrade.tar" "$outfile"
-- 
2.10.0




More information about the Lede-dev mailing list