[LEDE-DEV] [PATCH v3 05/13] scripts: Use cd ... || exit in case cd fails
Jan-Tarek Butt
tarek at ring0.de
Thu Oct 6 01:50:32 PDT 2016
Signed-off-by: Jan-Tarek Butt <tarek at ring0.de>
---
scripts/clean-package.sh | 1 +
scripts/deptest.sh | 4 ++--
scripts/ext-toolchain.sh | 12 ++++++------
scripts/get_source_date_epoch.sh | 4 +++-
scripts/getver.sh | 4 +++-
scripts/patch-specs.sh | 2 +-
scripts/sysupgrade-tar.sh | 2 +-
7 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
index 5cae341..2de3c51 100755
--- a/scripts/clean-package.sh
+++ b/scripts/clean-package.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
+set -e
[ -n "$1" -a -n "$2" ] || {
echo "Usage: $0 <file> <directory>"
exit 1
diff --git a/scripts/deptest.sh b/scripts/deptest.sh
index d7be99d..efa3c5a 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" || die "Failed to enter $STAMP_DIR_SUCCESS directory"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
else
- ( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
+ ( cd "$STAMP_DIR_FAILED" || die "Failed to enter $STAMP_DIR_FAILED directory"; 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 047bc24..b180874 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..8068568 100755
--- a/scripts/get_source_date_epoch.sh
+++ b/scripts/get_source_date_epoch.sh
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
export LANG=C
export LC_ALL=C
-[ -n "$TOPDIR" ] && cd "$TOPDIR"
+if [ -n "$TOPDIR" ]; then
+ cd "$TOPDIR" || exit
+fi
try_version() {
[ -f version.date ] || return 1
diff --git a/scripts/getver.sh b/scripts/getver.sh
index 7127eb2..67ddc20 100755
--- a/scripts/getver.sh
+++ b/scripts/getver.sh
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
export LANG=C
export LC_ALL=C
-[ -n "$TOPDIR" ] && cd "$TOPDIR"
+if [ -n "$TOPDIR" ]; then
+ cd "$TOPDIR" || exit
+fi
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