Bläddra i källkod

fixes for all build.sh bugs and coding conventions identified in ShellCheck (www.shellcheck.net) - as per report by @mavit in #227

Chris Simpkins 7 år sedan
förälder
incheckning
a3dbb96beb
1 ändrade filer med 30 tillägg och 37 borttagningar
  1. 30 37
      build.sh

+ 30 - 37
build.sh

@@ -14,13 +14,15 @@
 #
 #
 # /////////////////////////////////////////////////////////////////
 # /////////////////////////////////////////////////////////////////
 
 
-
+# test for number of arguments
 if [ $# -gt 1 ]
 if [ $# -gt 1 ]
 	then
 	then
 	    echo "Inappropriate arguments included in your command." 1>&2
 	    echo "Inappropriate arguments included in your command." 1>&2
 	    echo "Usage: ./build.sh (--install-dependencies)" 1>&2
 	    echo "Usage: ./build.sh (--install-dependencies)" 1>&2
 	    exit 1
 	    exit 1
-elif [ "$1" = "--install-dependencies" ]
+fi
+
+if [ "$1" = "--install-dependencies" ]
 	then
 	then
 		# fontmake
 		# fontmake
 		pip install --upgrade fontmake
 		pip install --upgrade fontmake
@@ -29,10 +31,9 @@ elif [ "$1" = "--install-dependencies" ]
 		# ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
 		# ttfautohint v1.6 (must be pinned to v1.6 and above for Hack instruction sets)
         # begin with OS X check for platform specific ttfautohint install using Homebrew, install from source on other platforms
         # begin with OS X check for platform specific ttfautohint install using Homebrew, install from source on other platforms
         platformstr=$(uname)
         platformstr=$(uname)
-        if [ $platformstr = "Darwin" ]; then
+        if [ "$platformstr" = "Darwin" ]; then
             # test for homebrew install
             # test for homebrew install
-            which homebrew
-            if [ $? -ne 0 ]
+            if ! which homebrew
                 then
                 then
                     echo "Please manually install Homebrew (https://brew.sh/) before the execution of this script with the --install-dependencies flag on the OS X platform." 1>&2
                     echo "Please manually install Homebrew (https://brew.sh/) before the execution of this script with the --install-dependencies flag on the OS X platform." 1>&2
                     exit 1
                     exit 1
@@ -40,22 +41,26 @@ elif [ "$1" = "--install-dependencies" ]
 
 
             # install Homebrew release of ttfautohint (this installs all dependencies necessary for build)
             # install Homebrew release of ttfautohint (this installs all dependencies necessary for build)
             #    use --upgrade flag to confirm latest version installed as need 1.6+
             #    use --upgrade flag to confirm latest version installed as need 1.6+
-            brew install --upgrade ttfautohint
-            if [ $? -ne 0 ]
+            if ! brew install --upgrade ttfautohint
                 then
                 then
                     echo "Unable to install ttfautohint with Homebrew.  Please attempt to install this dependency manually and repeat this script without the --install-dependencies flag." 1>&2
                     echo "Unable to install ttfautohint with Homebrew.  Please attempt to install this dependency manually and repeat this script without the --install-dependencies flag." 1>&2
                     exit 1
                     exit 1
             fi
             fi
-
         else
         else
             curl -L https://sourceforge.net/projects/freetype/files/ttfautohint/1.6/ttfautohint-1.6.tar.gz/download -o ttfautohint.tar.gz
             curl -L https://sourceforge.net/projects/freetype/files/ttfautohint/1.6/ttfautohint-1.6.tar.gz/download -o ttfautohint.tar.gz
             tar -xvzf ttfautohint.tar.gz
             tar -xvzf ttfautohint.tar.gz
             ttfautohint-1.6/configure --with-qt=no
             ttfautohint-1.6/configure --with-qt=no
-            ttfautohint-1.6/make && sudo ttfautohint-1.6/make install
+            ttfautohint-1.6/make
+            if ! sudo ttfautohint-1.6/make install; then
+            	echo "Unable to install ttfautohint from source.  Please attempt to manually install this dependency and repeat this script without the --install-dependencies flag" 1>&2
+            	exit 1
+            fi
+
             if [ -f "ttfautohint-1.6.tar.gz" ]
             if [ -f "ttfautohint-1.6.tar.gz" ]
                 then
                 then
                     rm ttfautohint-1.6.tar.gz
                     rm ttfautohint-1.6.tar.gz
             fi
             fi
+
             if [ -d "ttfautohint-1.6" ]
             if [ -d "ttfautohint-1.6" ]
                 then
                 then
                     rm -rf ttfautohint-1.6
                     rm -rf ttfautohint-1.6
@@ -65,29 +70,23 @@ elif [ "$1" = "--install-dependencies" ]
 		# confirm installs
 		# confirm installs
 		installflag=0
 		installflag=0
         # fontmake installed
         # fontmake installed
-		which fontmake
-		if [ $? -ne 0 ]
+		if ! which fontmake
 			then
 			then
 			    echo "Unable to install fontmake with 'pip install fontmake'.  Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
 			    echo "Unable to install fontmake with 'pip install fontmake'.  Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
-			    $installflag=1
+			    installflag=1
 		fi
 		fi
-
         # fontTools python library can be imported
         # fontTools python library can be imported
-		python -c "import fontTools"
-		if [ $? -ne 0 ]
+		if ! python -c "import fontTools"
 			then
 			then
 			    echo "Unable to install fontTools with 'pip install fonttools'.  Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
 			    echo "Unable to install fontTools with 'pip install fonttools'.  Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
-			    $installflag=1
+			    installflag=1
 		fi
 		fi
-
         # ttfautohint installed
         # ttfautohint installed
-		which ttfautohint
-		if [ $? -ne 0 ]
+		if ! which ttfautohint
 			then
 			then
 			    echo "Unable to install ttfautohint from source.  Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
 			    echo "Unable to install ttfautohint from source.  Please attempt manual install and repeat build without the --install-dependencies flag." 1>&2
-			    $installflag=1
+			    installflag=1
 		fi
 		fi
-
 		# if any of the dependency installs failed, exit and do not attempt build, notify user
 		# if any of the dependency installs failed, exit and do not attempt build, notify user
 		if [ $installflag -eq 1 ]
 		if [ $installflag -eq 1 ]
 			then
 			then
@@ -122,32 +121,30 @@ if [ -d "master_ttf" ]; then
 fi
 fi
 
 
 # build regular set
 # build regular set
-fontmake -u "source/Hack-Regular.ufo" -o ttf
-if [ $? -ne 0 ]
+
+if ! fontmake -u "source/Hack-Regular.ufo" -o ttf
 	then
 	then
 	    echo "Unable to build the Hack-Regular variant set.  Build canceled." 1>&2
 	    echo "Unable to build the Hack-Regular variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
 fi
 fi
 
 
 # build bold set
 # build bold set
-fontmake -u "source/Hack-Bold.ufo" -o ttf
-if [ $? -ne 0 ]
+if ! fontmake -u "source/Hack-Bold.ufo" -o ttf
 	then
 	then
 	    echo "Unable to build the Hack-Bold variant set.  Build canceled." 1>&2
 	    echo "Unable to build the Hack-Bold variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
 fi
 fi
 
 
 # build italic set
 # build italic set
-fontmake -u "source/Hack-Italic.ufo" -o ttf
-if [ $? -ne 0 ]
+if ! fontmake -u "source/Hack-Italic.ufo" -o ttf
 	then
 	then
 	    echo "Unable to build the Hack-Italic variant set.  Build canceled." 1>&2
 	    echo "Unable to build the Hack-Italic variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
 fi
 fi
 
 
 # build bold italic set
 # build bold italic set
-fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
-if [ $? -ne 0 ]
+
+if ! fontmake -u "source/Hack-BoldItalic.ufo" -o ttf
 	then
 	then
 	    echo "Unable to build the Hack-BoldItalic variant set.  Build canceled." 1>&2
 	    echo "Unable to build the Hack-BoldItalic variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
@@ -160,32 +157,28 @@ fi
 mkdir master_ttf/hinted
 mkdir master_ttf/hinted
 
 
 # Hack-Regular.ttf
 # Hack-Regular.ttf
-ttfautohint -l 6 -r 50 -x 10 -H 181 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Regular-TA.txt" "master_ttf/Hack-Regular.ttf" "master_ttf/hinted/Hack-Regular.ttf"
-if [ $? -ne 0 ]
+if ! ttfautohint -l 6 -r 50 -x 10 -H 181 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Regular-TA.txt" "master_ttf/Hack-Regular.ttf" "master_ttf/hinted/Hack-Regular.ttf"
 	then
 	then
 	    echo "Unable to execute ttfautohint on the Hack-Regular variant set.  Build canceled." 1>&2
 	    echo "Unable to execute ttfautohint on the Hack-Regular variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
 fi
 fi
 
 
 # Hack-Bold.ttf
 # Hack-Bold.ttf
-ttfautohint -l 6 -r 50 -x 10 -H 260 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Bold-TA.txt" "master_ttf/Hack-Bold.ttf" "master_ttf/hinted/Hack-Bold.ttf"
-if [ $? -ne 0 ]
+if ! ttfautohint -l 6 -r 50 -x 10 -H 260 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Bold-TA.txt" "master_ttf/Hack-Bold.ttf" "master_ttf/hinted/Hack-Bold.ttf"
 	then
 	then
 	    echo "Unable to execute ttfautohint on the Hack-Bold variant set.  Build canceled." 1>&2
 	    echo "Unable to execute ttfautohint on the Hack-Bold variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
 fi
 fi
 
 
 # Hack-Italic.ttf
 # Hack-Italic.ttf
-ttfautohint -l 6 -r 50 -x 10 -H 145 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Italic-TA.txt" "master_ttf/Hack-Italic.ttf" "master_ttf/hinted/Hack-Italic.ttf"
-if [ $? -ne 0 ]
+if ! ttfautohint -l 6 -r 50 -x 10 -H 145 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-Italic-TA.txt" "master_ttf/Hack-Italic.ttf" "master_ttf/hinted/Hack-Italic.ttf"
 	then
 	then
 	    echo "Unable to execute ttfautohint on the Hack-Italic variant set.  Build canceled." 1>&2
 	    echo "Unable to execute ttfautohint on the Hack-Italic variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1
 fi
 fi
 
 
 # Hack-BoldItalic.ttf
 # Hack-BoldItalic.ttf
-ttfautohint -l 6 -r 50 -x 10 -H 265 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-BoldItalic-TA.txt" "master_ttf/Hack-BoldItalic.ttf" "master_ttf/hinted/Hack-BoldItalic.ttf"
-if [ $? -ne 0 ]
+if ! ttfautohint -l 6 -r 50 -x 10 -H 265 -D latn -f latn -w G -W -t -X "" -I -R "master_ttf/Hack-Regular.ttf" -m "postbuild_processing/tt-hinting/Hack-BoldItalic-TA.txt" "master_ttf/Hack-BoldItalic.ttf" "master_ttf/hinted/Hack-BoldItalic.ttf"
 	then
 	then
 	    echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set.  Build canceled." 1>&2
 	    echo "Unable to execute ttfautohint on the Hack-BoldItalic variant set.  Build canceled." 1>&2
 	    exit 1
 	    exit 1