Skip to content

Commit

Permalink
Use POSIX sh instead of GNU Bash
Browse files Browse the repository at this point in the history
  • Loading branch information
yukiisbored committed Jan 6, 2019
1 parent 6c3dd41 commit d1bdc65
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 54 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Expand Up @@ -28,6 +28,13 @@ jobs:
- attach_workspace: { at: ~/ }
- run: ./clang-tidy.sh -j 2

shellcheck:
working_directory: ~/cuberite
docker: *cube_docker
steps:
- attach_workspace: { at: ~/ }
- run: ./shellcheck.sh

workflows:
version: 2
checks:
Expand Down
8 changes: 4 additions & 4 deletions CIbuild.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
#!/bin/sh

set -e

export CUBERITE_BUILD_SERIES_NAME="Travis $CC $TRAVIS_CUBERITE_BUILD_TYPE"
export CUBERITE_BUILD_ID=$TRAVIS_JOB_NUMBER
export CUBERITE_BUILD_DATETIME=`date`
CUBERITE_BUILD_SERIES_NAME="Travis $CC $TRAVIS_CUBERITE_BUILD_TYPE"; export CUBERITE_BUILD_SERIES_NAME
CUBERITE_BUILD_ID=$TRAVIS_JOB_NUMBER; export CUBERITE_BUILD_ID
CUBERITE_BUILD_DATETIME=$(date); export CUBERITE_BUILD_DATETIME

cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1;

Expand Down
4 changes: 2 additions & 2 deletions Server/hg
@@ -1,7 +1,7 @@
#! /bin/bash
#!/bin/sh

# This script runs Cuberite under helgrind
# It expects valgrind to be normally installed and available
# Note that this is for Linux only and debug-only, since it slows down MCS way too much

valgrind --log-file=helgrind.log --suppressions=hg.supp --gen-suppressions=all --tool=helgrind -v ./Cuberite
exec valgrind --log-file=helgrind.log --suppressions=hg.supp --gen-suppressions=all --tool=helgrind -v ./Cuberite
4 changes: 2 additions & 2 deletions Server/vg
@@ -1,7 +1,7 @@
#! /bin/bash
#!/bin/sh

# This script runs Cuberite under valgrind
# It expects valgrind to be normally installed and available
# Note that this is for Linux only and debug-only, since it slows down MCS way too much

valgrind --log-file=valgrind.log --suppressions=vg.supp --tool=memcheck --leak-check=full --leak-resolution=high --show-reachable=yes --track-origins=yes -v ./Cuberite
exec valgrind --log-file=valgrind.log --suppressions=vg.supp --tool=memcheck --leak-check=full --leak-resolution=high --show-reachable=yes --track-origins=yes -v ./Cuberite
2 changes: 1 addition & 1 deletion Server/webadmin/GenerateSelfSignedHTTPSCertUsingOpenssl.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

echo "This script generates the certificate and private key for the https webadmin"
echo "Note that the generated certificate is self-signed, and therefore not trusted by browsers"
Expand Down
35 changes: 18 additions & 17 deletions android/compile.sh
@@ -1,34 +1,35 @@
#!/bin/bash
#!/bin/sh

# This script cross-compiles cuberite for the android platform. It uses
# the following enviroment variables
# CMAKE: Should be the path to a cmake executable of version 3.7+
# NDK: Should be the path to the android ndk root
# (optional) TYPE: either Release or Debug, sets the build type
# (optional) THREADS: The number of threads to use, default 4
set -e

function usage() {
usage() {
echo "Usage: NDK=<path-to-ndk> CMAKE=<cmake-binary> $0 (clean|<ABI>)";
exit 1
}

BASEDIR="$(realpath $(dirname $0))"
SELF="./$(basename $0)"
BASEDIR="$(realpath "$(dirname "$0")")"
SELF="./$(basename "$0")"

# Clean doesn't need CMAKE and NDK, so it's handled here
if [ "$1" == "clean" ]; then
cd $BASEDIR
if [ "$1" = "clean" ]; then
cd "$BASEDIR"
rm -rf ../android-build/
exit 0
fi

if [ -z "$CMAKE" -o -z "$NDK" ];then
if [ -z "$CMAKE" ] || [ -z "$NDK" ];then
usage;
fi

# CMake wants absolute path
CMAKE="$(realpath $CMAKE)"
NDK="$(realpath $NDK)"
CMAKE="$(realpath "$CMAKE")"
NDK="$(realpath "$NDK")"

if [ -z "$TYPE" ]; then
TYPE="Release"
Expand All @@ -38,7 +39,7 @@ if [ -z "$THREADS" ]; then
THREADS="4"
fi

cd $BASEDIR
cd "$BASEDIR"

case "$1" in
armeabi)
Expand Down Expand Up @@ -72,20 +73,20 @@ case "$1" in
all)
echo "Packing server.zip ..."
mkdir -p Server
cd $BASEDIR/../Server
zip -r $BASEDIR/Server/server.zip *
cd "$BASEDIR"/../Server
zip -r "$BASEDIR/Server/server.zip" ./*

for arch in armeabi armeabi-v7a arm64-v8a mips mips64 x86 x86_64; do
echo "Doing ... $arch ..." && \
cd $BASEDIR && \
cd "$BASEDIR" && \
"$SELF" clean && \
"$SELF" "$arch" && \
cd Server && \
zip "$arch".zip Cuberite && \
rm Cuberite
done

cd $BASEDIR/Server
cd "$BASEDIR/Server"
for file in server.zip armeabi.zip armeabi-v7a.zip arm64-v8a.zip mips.zip mips64.zip x86.zip x86_64.zip; do
echo "Generating sha1 sum for ... $file ..." && \
sha1sum "$file" > "$file".sha1
Expand All @@ -100,7 +101,7 @@ case "$1" in
;;
esac

mkdir -p $BASEDIR/../android-build
cd $BASEDIR/../android-build
"$CMAKE" $BASEDIR/../android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION="$APILEVEL" -DCMAKE_BUILD_TYPE="$TYPE" -DCMAKE_ANDROID_ARCH_ABI="$1" -DCMAKE_ANDROID_NDK="$NDK"
mkdir -p "$BASEDIR"/../android-build
cd "$BASEDIR"/../android-build
"$CMAKE" "$BASEDIR"/../android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION="$APILEVEL" -DCMAKE_BUILD_TYPE="$TYPE" -DCMAKE_ANDROID_ARCH_ABI="$1" -DCMAKE_ANDROID_NDK="$NDK"
make -j "$THREADS"
10 changes: 7 additions & 3 deletions clang-tidy.sh
Expand Up @@ -3,14 +3,18 @@
set -e

FIXES_FILE="tidy-fixes.yaml"
REGEX="/cuberite/src/\.?[^\.]"
ARGS="-header-filter $REGEX -quiet -export-fixes $FIXES_FILE "$@" $REGEX"
REGEX="/cuberite/src/\\.?[^\\.]"

run_clang_tidy_args () {
run-clang-tidy.py \
-header-filter "$REGEX" -quiet -export-fixes "$FIXES_FILE" "$1" "$REGEX"
}

mkdir -p tidy-build
cd tidy-build
cmake --target Cuberite -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..

if run-clang-tidy.py $ARGS; then
if run_clang_tidy_args "$@"; then
echo "clang-tidy: No violations found"
else
echo "clang-tidy: Found violations"
Expand Down
38 changes: 19 additions & 19 deletions compile.sh
Expand Up @@ -83,7 +83,7 @@ errorInput ()
echo
echoInt "-----------------"
echo "Unrecognized user input"
echo "$@"
echo "$1"
exit 5
}

Expand All @@ -101,7 +101,7 @@ errorOther ()

echoInt () # echo only if interactive mode.
{
if [ $STATE_INTERACTIVE -eq 1 ]; then
if [ "$STATE_INTERACTIVE" -eq 1 ]; then
echo "$1"
fi
}
Expand Down Expand Up @@ -228,13 +228,13 @@ doDependencyCheck()
# Depdendency check.
checkPackages ()
{
echo "$PROGRAMS" | while read line; do
EXE_NAME=`echo "$line" | cut -f 1 -d " "`
PACKAGE_NAME=`echo "$line" | cut -f 2 -d " "`
command -v $EXE_NAME > /dev/null 2> /dev/null || printf %s " $PACKAGE_NAME"
echo "$PROGRAMS" | while read -r line; do
EXE_NAME=$(echo "$line" | cut -f 1 -d " ")
PACKAGE_NAME=$(echo "$line" | cut -f 2 -d " ")
command -v "$EXE_NAME" > /dev/null 2> /dev/null || printf %s " $PACKAGE_NAME"
done
}
MISSING_PACKAGES="$MISSING_PACKAGES`checkPackages`"
MISSING_PACKAGES="$MISSING_PACKAGES$(checkPackages)"
missingDepsExit ()
{
if [ "$1" != "" ]; then
Expand All @@ -251,7 +251,7 @@ doDependencyCheck()
echoInt
echoInt "-----------------"
echoErr "You have missing compilation dependencies:"
echoErr $MISSING_PACKAGES
echoErr "$MISSING_PACKAGES"
echoErr

# apt-get guide.
Expand Down Expand Up @@ -305,7 +305,7 @@ You can choose between 3 branches:


printf %s "Choose the branch (s/t/d): "
read CHOICE_BRANCH
read -r CHOICE_BRANCH
case $CHOICE_BRANCH in
s|S)
errorOther "We don't have a stable branch yet, please use testing, sorry."
Expand All @@ -317,7 +317,7 @@ case $CHOICE_BRANCH in
CHOICE_BRANCH="master"
;;
*)
errorInput
errorInput "$@"
;;
esac

Expand All @@ -342,7 +342,7 @@ if [ $STATE_INTERACTIVE -eq 1 ]; then
"

printf %s "Choose compile mode: (r/d) (Default: \"$DEFAULT_BUILDTYPE\"): "
read CHOICE_BUILDTYPE
read -r CHOICE_BUILDTYPE
case $CHOICE_BUILDTYPE in
d|D)
CHOICE_BUILDTYPE="Debug"
Expand All @@ -364,18 +364,18 @@ fi

numberOfThreads()
{
KERNEL=`uname -s`
KERNEL=$(uname -s)

if [ "$KERNEL" = "Linux" ] || [ "$KERNEL" = "Darwin" ]; then
echo `getconf _NPROCESSORS_ONLN`
getconf _NPROCESSORS_ONLN
elif [ "$KERNEL" = "FreeBSD" ]; then
echo `getconf NPROCESSORS_ONLN`
getconf NPROCESSORS_ONLN
else
echo "unknown"
fi
}

CPU_THREAD_COUNT=`numberOfThreads`
CPU_THREAD_COUNT=$(numberOfThreads)

if [ $STATE_INTERACTIVE -eq 1 ]; then
echo ""
Expand All @@ -392,13 +392,13 @@ if [ $STATE_INTERACTIVE -eq 1 ]; then
echo "If you have enough RAM, it is wise to choose your CPU's thread count. "
echo "Otherwise choose lower. Old Raspberry Pis should choose 1. If in doubt, choose 1."
printf %s "Please enter the number of compilation threads to use (Default: $DEFAULT_THREADS): "
read CHOICE_THREADS
read -r CHOICE_THREADS
fi

if [ -z "$CHOICE_THREADS" ] 2> /dev/null; then
CHOICE_THREADS="$DEFAULT_THREADS"
elif [ "$CHOICE_THREADS" = "AUTO" ] 2> /dev/null; then
if [ $CPU_THREAD_COUNT = "unknown" ]; then
if [ "$CPU_THREAD_COUNT" = "unknown" ]; then
CHOICE_THREADS="$DEFAULT_THREADS"
echo "WARNING: could not detect number of threads. Using the default ($DEFAULT_THREADS) ." >&2
else
Expand Down Expand Up @@ -443,8 +443,8 @@ if [ $STATE_INTERACTIVE -eq 1 ]; then
echo "After pressing ENTER, the script will connect to $UPSTREAM_LINK"
echo "to check for updates and/or fetch code. It will then compile your program."
echo "If you compiled before, make sure you're in the proper directory and that \"Previous compilation\" is detected."
printf $s "Press ENTER to continue... "
read dummy
printf "Press ENTER to continue... "
read -r dummy
fi


Expand Down
15 changes: 15 additions & 0 deletions shellcheck.sh
@@ -0,0 +1,15 @@
#!/bin/sh

echo "Collecting shell files, This may take a while ..."

# For some reason shellcheck reports SC2016 for the '-exec sh ..' part,
# even though that is not the case.
# shellcheck disable=SC2016
SHELL_FILES=$(find . \
-type f \
\! \( -path './.git/*' -o -path './lib/*' -o -path './Server/Plugins/*' \) \
-exec sh -c 'head -n 1 "$1" | grep bin/sh>/dev/null' _ {} \; -print)

# We actually need word splitting
# shellcheck disable=SC2086
exec shellcheck --shell=sh $SHELL_FILES
2 changes: 1 addition & 1 deletion src/Bindings/AllToLua.sh 100644 → 100755
@@ -1,2 +1,2 @@
#!/bin/bash
#!/bin/sh
/usr/bin/tolua++ -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
8 changes: 3 additions & 5 deletions uploadCoverage.sh
@@ -1,9 +1,7 @@
#!/usr/bin/env bash
#!/bin/sh

if [ "$TRAVIS_CUBERITE_BUILD_TYPE" == "COVERAGE" ]
if [ "$TRAVIS_CUBERITE_BUILD_TYPE" = "COVERAGE" ]
then
find tests -type f -name '*.gcda' -exec sh -c 'cp {} $(dirname {})/../$(basename {})' \;
find tests -type f -name '*.gcda' -exec sh -c 'cp $1 $(dirname $1)/../$(basename $1)' _ {} \;
coveralls --exclude lib --exclude Android >/dev/null
fi


0 comments on commit d1bdc65

Please sign in to comment.