From d2d73109094ce9066392495b5777a23b04d984ad Mon Sep 17 00:00:00 2001 From: "Mingye Wang (Arthur2e5)" Date: Tue, 15 Mar 2016 21:48:34 -0400 Subject: [PATCH 1/3] compile: some portability-related tweaks echo -n are not POSIX-sh-portable, so use printf. Neither are parentheses inside [ ]. Some of the usage are clearly better covered by `case`, so let's use it. --- compile.sh | 57 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/compile.sh b/compile.sh index 38aa5f69e..af9120278 100755 --- a/compile.sh +++ b/compile.sh @@ -6,9 +6,9 @@ set -e #TODO command line parameter handling for non-interactive mode. # Do we already have a repo? -if [ \( -d .git \) -a \( -f easyinstall.sh \) -a \( -f src/BlockArea.cpp \) ]; then # A good enough indicator that we're in the Cuberite git repo. -cd ../ -echo "Cuberite repository detected. This should make the process faster, especially if you compiled before." +if [ -d .git ] && [ -f easyinstall.sh ] && [ -f src/BlockArea.cpp ]; then # A good enough indicator that we're in the Cuberite git repo. + cd ../ + echo "Cuberite repository detected. This should make the process faster, especially if you compiled before." fi # Error functions. @@ -69,7 +69,7 @@ GCC_EXISTS=0 CLANG_EXISTS=0 $GCC_EXE_NAME --help > /dev/null 2> /dev/null && GCC_EXISTS=1 $CLANG_EXE_NAME --help > /dev/null 2> /dev/null && CLANG_EXISTS=1 -if [ $GCC_EXISTS -eq 0 -a $CLANG_EXISTS -eq 0 ]; then +if [ "$GCC_EXISTS" -eq 0 ] && [ "$CLANG_EXISTS" -eq 0 ]; then MISSING_PACKAGES=" $COMPILER_PACKAGE_NAME" fi @@ -79,7 +79,7 @@ checkPackages () echo "$PROGRAMS" | while read line; do EXE_NAME=`echo "$line" | cut -f 1` PACKAGE_NAME=`echo "$line" | cut -f 2` - command -v $EXE_NAME > /dev/null 2> /dev/null || echo -n " $PACKAGE_NAME" + command -v $EXE_NAME > /dev/null 2> /dev/null || printf %s " $PACKAGE_NAME" done } MISSING_PACKAGES="$MISSING_PACKAGES`checkPackages`" @@ -138,18 +138,22 @@ You can choose between 3 branches: # Input: Branch choice. -echo -n "Choose the branch (s/t/d): " +printf %s "Choose the branch (s/t/d): " read BRANCH -if [ \( "$BRANCH" = "s" \) -o \( "$BRANCH" = "S" \) ]; then - #BRANCH="stable" - error "We don't have a stable branch yet, please use testing, sorry." -elif [ \( $BRANCH = "t" \) -o \( $BRANCH = "T" \) ]; then - BRANCH="testing" -elif [ \( $BRANCH = "d" \) -o \( $BRANCH = "D" \) ]; then - BRANCH="master" -else - error "Unrecognized user input." -fi +case $BRANCH in + s|S) + error "We don't have a stable branch yet, please use testing, sorry." + ;; + t|T) + BRANCH="testing" + ;; + d|D) + BRANCH="master" + ;; + *) + error "Unrecognized user input." + ;; +esac } ### Inactive code end. ### @@ -171,16 +175,19 @@ code after this step. It will then compile your program. " # Input: Compile mode choice. -echo -n "Choose compile mode: (n/d): " +printf %s "Choose compile mode: (n/d): " read BUILDTYPE -if [ \( "$BUILDTYPE" = "d" \) -o \( "$BUILDTYPE" = "D" \) ]; then - BUILDTYPE="Debug" -elif [ \( "$BUILDTYPE" = "n" \) -o \( "$BUILDTYPE" = "N" \) ]; then - BUILDTYPE="Release" -else - error "Unrecognized user input." -fi - +case $BUILDTYPE in + d|D) + BUILDTYPE="Debug" + ;; + n|N) + BUILDTYPE="Release" + ;; + *) + error "Unrecognized user input." + ;; +esac # Echo: Downloading began. echo From d346ec2cf7e9189f16cf49eef3694f3f728ea37d Mon Sep 17 00:00:00 2001 From: "Mingye Wang (Arthur2e5)" Date: Tue, 15 Mar 2016 21:53:26 -0400 Subject: [PATCH 2/3] Sanity check (quoting, etc.) for compile.sh --- compile.sh | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/compile.sh b/compile.sh index af9120278..43b5fa337 100755 --- a/compile.sh +++ b/compile.sh @@ -17,7 +17,7 @@ error () echo echo "-----------------" echo "Script aborted, reason:" - echo $1 + echo "$@" exit 1 } @@ -76,9 +76,8 @@ fi # Depdendency check. checkPackages () { - echo "$PROGRAMS" | while read line; do - EXE_NAME=`echo "$line" | cut -f 1` - PACKAGE_NAME=`echo "$line" | cut -f 2` + # note that IFS is a TAB here! + echo "$PROGRAMS" | while IFS=' ' read EXE_NAME PACKAGE_NAME __trash__; do command -v $EXE_NAME > /dev/null 2> /dev/null || printf %s " $PACKAGE_NAME" done } @@ -93,23 +92,23 @@ if [ "$MISSING_PACKAGES" != "" ]; then # apt-get guide. apt-get --help > /dev/null 2> /dev/null && \ - missingDepsExit "sudo apt-get install$MISSING_PACKAGES" + missingDepsExit "sudo apt-get install $MISSING_PACKAGES" # yum guide. yum --help > /dev/null 2> /dev/null && \ - missingDepsExit "sudo yum install$MISSING_PACKAGES" + missingDepsExit "sudo yum install $MISSING_PACKAGES" # zypper guide. zypper --help > /dev/null 2> /dev/null && \ - missingDepsExit "sudo zypper install$MISSING_PACKAGES" + missingDepsExit "sudo zypper install $MISSING_PACKAGES" # pacman guide. pacman --help > /dev/null 2> /dev/null && \ - missingDepsExit "sudo pacman -S$MISSING_PACKAGES" + missingDepsExit "sudo pacman -S $MISSING_PACKAGES" # urpmi guide. urpmi --help > /dev/null 2> /dev/null && \ - missingDepsExit "sudo urpmi$MISSING_PACKAGES" + missingDepsExit "sudo urpmi $MISSING_PACKAGES" missingDepsExit "" fi @@ -203,9 +202,9 @@ else # Git: Fetch. cd cuberite echo " --- Updating the $BRANCH branch..." - git fetch origin $BRANCH || error "git fetch failed" - git checkout $BRANCH || error "git checkout failed" - git merge origin/$BRANCH || error "git merge failed" + git fetch origin "$BRANCH" || error "git fetch failed" + git checkout "$BRANCH" || error "git checkout failed" + git merge "origin/$BRANCH" || error "git merge failed" fi # Git: Submodules. @@ -217,7 +216,7 @@ git submodule update --init echo " --- Running cmake..." if [ ! -d build-cuberite ]; then mkdir build-cuberite; fi cd build-cuberite -cmake .. -DCMAKE_BUILD_TYPE=$BUILDTYPE || error "cmake failed" +cmake .. -DCMAKE_BUILD_TYPE="$BUILDTYPE" || error "cmake failed" # Make. @@ -234,9 +233,9 @@ echo "Compilation done!" echo echo "Cuberite awaits you at:" if [ "$BUILDTYPE" = "Debug" ]; then - echo "`pwd`/Cuberite_debug" + echo "$PWD/Cuberite_debug" else - echo "`pwd`/Cuberite" + echo "$PWD/Cuberite" fi cd .. echo " @@ -247,7 +246,11 @@ Enjoy :)" exit 0 :windows_detected -echo "This script is not available for Windows yet, sorry." -echo "You can still download the Windows binaries from: http://cuberite.org" -echo "You can also manually compile for Windows. See: https://github.com/cuberite/cuberite" +@echo off +rem Putting echo "Foo" in Windows CMD gives you "Foo" -- with quotes. +echo This script is not available for Windows yet, sorry. +echo You can still download the Windows binaries from: http://cuberite.org +echo You can also manually compile for Windows. See: https://github.com/cuberite/cuberite +rem windows_exit +exit } From 8161d6f7f7dbf8585ca3599ebb24d6973899c21f Mon Sep 17 00:00:00 2001 From: "Mingye Wang (Arthur2e5)" Date: Tue, 15 Mar 2016 21:53:41 -0400 Subject: [PATCH 3/3] Shallow clone to the correct branch Shallow clones are faster, and we always want the correct branch to be cloned.. --- compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compile.sh b/compile.sh index 43b5fa337..166edea54 100755 --- a/compile.sh +++ b/compile.sh @@ -196,7 +196,7 @@ echo " --- Downloading Cuberite's source code from the $BRANCH branch..." if [ ! -d cuberite ]; then # Git: Clone. echo " --- Looks like your first run, cloning the whole code..." - git clone https://github.com/cuberite/cuberite.git + git clone --depth 1 https://github.com/cuberite/cuberite.git -b "$BRANCH" cd cuberite else # Git: Fetch.