From 229a9c30915c5d4c66f151f321d8b2f0f3e83512 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Sun, 25 Feb 2018 14:41:52 +0000
Subject: [PATCH] Tidying cmake utils

---
 src/freedombone-utils-cmake | 49 ++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/src/freedombone-utils-cmake b/src/freedombone-utils-cmake
index 46ef71379..28231d802 100755
--- a/src/freedombone-utils-cmake
+++ b/src/freedombone-utils-cmake
@@ -32,25 +32,26 @@ CMAKE_REPO="https://github.com/Kitware/CMake"
 CMAKE_COMMIT='d6734eeb875ceca5d810e829ca90541918dca2b4'
 
 function mesh_install_cmake {
-    if [ ! -d $rootdir$INSTALL_DIR ]; then
-        chroot "$rootdir" mkdir -p $INSTALL_DIR
+    # shellcheck disable=SC2154
+    if [ ! -d "$rootdir$INSTALL_DIR" ]; then
+        chroot "$rootdir" mkdir -p "$INSTALL_DIR"
     fi
 
     chroot "$rootdir" apt-get -yq install build-essential
 
     if [ -d /repos/cmake ]; then
-        mkdir $rootdir$INSTALL_DIR/cmake
-        cp -r -p /repos/cmake/. $rootdir$INSTALL_DIR/cmake
-        cd $rootdir$INSTALL_DIR/cmake
+        mkdir "$rootdir$INSTALL_DIR/cmake"
+        cp -r -p /repos/cmake/. "$rootdir$INSTALL_DIR/cmake"
+        cd "$rootdir$INSTALL_DIR/cmake" || exit 678346836
         git pull
     else
-        git clone $CMAKE_REPO $rootdir$INSTALL_DIR/cmake
+        git clone "$CMAKE_REPO" "$rootdir$INSTALL_DIR/cmake"
     fi
 
-    cd $rootdir$INSTALL_DIR/cmake
+    cd "$rootdir$INSTALL_DIR/cmake" || exit 734634684
     git checkout $CMAKE_COMMIT -b $CMAKE_COMMIT
 
-    cat <<EOF > $rootdir/root/install_cmake
+    cat <<EOF > "$rootdir/root/install_cmake"
 cd $INSTALL_DIR/cmake
 ./bootstrap
 make
@@ -65,18 +66,17 @@ EOF
 }
 
 function install_cmake {
-    if [ $INSTALLING_MESH ]; then
+    if [ "$INSTALLING_MESH" ]; then
         mesh_install_cmake
         return
     fi
 
-    if [ -d $INSTALL_DIR/cmake ]; then
-        if ! grep -q "CMake commit:$CMAKE_COMMIT" $COMPLETION_FILE; then
-            set_repo_commit $INSTALL_DIR/cmake "CMake commit" "$CMAKE_COMMIT" $CMAKE_REPO
-            cd $INSTALL_DIR/cmake
+    if [ -d "$INSTALL_DIR/cmake" ]; then
+        if ! grep -q "CMake commit:$CMAKE_COMMIT" "$COMPLETION_FILE"; then
+            set_repo_commit "$INSTALL_DIR/cmake" "CMake commit" "$CMAKE_COMMIT" "$CMAKE_REPO"
+            cd "$INSTALL_DIR/cmake" || exit 36873638
             ./bootstrap
-            make
-            if [ ! "$?" = "0" ]; then
+            if ! make; then
                 exit 72581
             fi
             make install
@@ -87,26 +87,25 @@ function install_cmake {
         return
     fi
 
-    if [ ! -d $INSTALL_DIR ]; then
-        mkdir -p $INSTALL_DIR
+    if [ ! -d "$INSTALL_DIR" ]; then
+        mkdir -p "$INSTALL_DIR"
     fi
 
     apt-get -yq install build-essential
 
     if [ -d /repos/cmake ]; then
-        mkdir $INSTALL_DIR/cmake
-        cp -r -p /repos/cmake/. $INSTALL_DIR/cmake
-        cd $INSTALL_DIR/cmake
+        mkdir "$INSTALL_DIR/cmake"
+        cp -r -p /repos/cmake/. "$INSTALL_DIR/cmake"
+        cd "$INSTALL_DIR/cmake" || exit 374893758
         git pull
     else
-        git_clone $CMAKE_REPO $INSTALL_DIR/cmake
+        git_clone "$CMAKE_REPO" "$INSTALL_DIR/cmake"
     fi
 
-    cd $INSTALL_DIR/cmake
-    git checkout $CMAKE_COMMIT -b $CMAKE_COMMIT
+    cd "$INSTALL_DIR/cmake" || exit 3467384
+    git checkout "$CMAKE_COMMIT" -b "$CMAKE_COMMIT"
     ./bootstrap
-    make
-    if [ ! "$?" = "0" ]; then
+    if ! make; then
         exit 72581
     fi
     make install
-- 
GitLab