2015-11-21 11:24:11 -05:00
|
|
|
#!/bin/sh
|
2015-05-24 05:30:22 -04:00
|
|
|
#|| goto :windows_detected
|
2015-12-10 00:12:05 -05:00
|
|
|
{ # put the whole thing in a block so as not to behave weirdly if interrupted
|
2015-11-21 11:24:11 -05:00
|
|
|
set -e
|
2015-05-24 05:30:22 -04:00
|
|
|
|
2016-01-13 02:29:25 -05:00
|
|
|
#TODO command line parameter handling for non-interactive mode.
|
|
|
|
|
2015-05-24 05:30:22 -04:00
|
|
|
# Do we already have a repo?
|
2016-03-15 21:48:34 -04:00
|
|
|
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."
|
2015-05-24 05:30:22 -04:00
|
|
|
fi
|
2015-08-16 05:07:18 -04:00
|
|
|
|
2015-05-24 05:30:22 -04:00
|
|
|
# Error functions.
|
2015-11-21 11:24:11 -05:00
|
|
|
error ()
|
2015-05-24 05:30:22 -04:00
|
|
|
{
|
|
|
|
echo
|
|
|
|
echo "-----------------"
|
|
|
|
echo "Script aborted, reason:"
|
2016-03-15 21:53:26 -04:00
|
|
|
echo "$@"
|
2015-11-21 11:24:11 -05:00
|
|
|
exit 1
|
2015-05-24 05:30:22 -04:00
|
|
|
}
|
|
|
|
|
2015-11-21 11:24:11 -05:00
|
|
|
missingDepsExit ()
|
2015-05-24 05:30:22 -04:00
|
|
|
{
|
2016-01-12 10:34:21 -05:00
|
|
|
if [ "$1" != "" ]; then
|
|
|
|
echo "You can install the missing depndencies via:"
|
|
|
|
echo "$1"
|
|
|
|
fi
|
2015-05-24 05:30:22 -04:00
|
|
|
echo
|
|
|
|
echo "Please install the dependencies, then come back."
|
|
|
|
echo
|
2015-11-21 11:24:11 -05:00
|
|
|
exit 2
|
2015-05-24 05:30:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Echo: Greetings.
|
2016-01-13 02:29:25 -05:00
|
|
|
echo "
|
|
|
|
Hello, this script will download and compile Cuberite.
|
|
|
|
On subsequent runs, it will update Cuberite.
|
|
|
|
The compilation and download will occur in the current directory.
|
|
|
|
If you're updating, you should run: <Path to Cuberite>/compile.sh
|
|
|
|
Compiling from source takes time, but it usually generates faster
|
|
|
|
executables. If you prefer ready-to-use binaries or if you want
|
|
|
|
more info, please visit: http://cuberite.org/"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
2016-01-12 10:34:21 -05:00
|
|
|
### Dependency checks start. ###
|
|
|
|
MISSING_PACKAGES=""
|
|
|
|
|
|
|
|
# Most distros have the following default package and executable names.
|
|
|
|
GCC_EXE_NAME="g++"
|
|
|
|
CLANG_EXE_NAME="clang"
|
|
|
|
COMPILER_PACKAGE_NAME="gcc g++"
|
|
|
|
|
|
|
|
# Left side: Executable Name, Right side: Package Name. Note that this is TAB delimited. Spaces will not work.
|
|
|
|
PROGRAMS='git git
|
|
|
|
make make
|
|
|
|
cmake cmake'
|
|
|
|
|
2016-01-13 02:29:25 -05:00
|
|
|
# If any OS deviates from the defaults, detect the OS here, and change PROGRAMS, COMPILER_PACKAGE_NAME, etc. as needed.
|
2016-01-12 10:34:21 -05:00
|
|
|
|
|
|
|
# Fedora, CentOS, RHEL, Mageia, openSUSE, Mandriva
|
|
|
|
if (rpm --help > /dev/null 2> /dev/null); then
|
|
|
|
COMPILER_PACKAGE_NAME="gcc-c++"
|
|
|
|
fi
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
# Compiler check.
|
|
|
|
GCC_EXISTS=0
|
|
|
|
CLANG_EXISTS=0
|
2016-01-12 10:34:21 -05:00
|
|
|
$GCC_EXE_NAME --help > /dev/null 2> /dev/null && GCC_EXISTS=1
|
|
|
|
$CLANG_EXE_NAME --help > /dev/null 2> /dev/null && CLANG_EXISTS=1
|
2016-03-15 21:48:34 -04:00
|
|
|
if [ "$GCC_EXISTS" -eq 0 ] && [ "$CLANG_EXISTS" -eq 0 ]; then
|
2016-01-12 10:34:21 -05:00
|
|
|
MISSING_PACKAGES=" $COMPILER_PACKAGE_NAME"
|
2015-05-24 05:30:22 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Depdendency check.
|
2016-01-12 10:34:21 -05:00
|
|
|
checkPackages ()
|
|
|
|
{
|
2016-03-15 21:53:26 -04:00
|
|
|
# note that IFS is a TAB here!
|
|
|
|
echo "$PROGRAMS" | while IFS=' ' read EXE_NAME PACKAGE_NAME __trash__; do
|
2016-03-15 21:48:34 -04:00
|
|
|
command -v $EXE_NAME > /dev/null 2> /dev/null || printf %s " $PACKAGE_NAME"
|
2016-01-12 10:34:21 -05:00
|
|
|
done
|
|
|
|
}
|
|
|
|
MISSING_PACKAGES="$MISSING_PACKAGES`checkPackages`"
|
|
|
|
|
|
|
|
if [ "$MISSING_PACKAGES" != "" ]; then
|
2015-05-24 05:30:22 -04:00
|
|
|
echo
|
|
|
|
echo "-----------------"
|
|
|
|
echo "You have missing compilation dependencies:"
|
2016-01-12 10:34:21 -05:00
|
|
|
echo $MISSING_PACKAGES
|
2015-05-24 05:30:22 -04:00
|
|
|
echo
|
|
|
|
|
|
|
|
# apt-get guide.
|
|
|
|
apt-get --help > /dev/null 2> /dev/null && \
|
2016-03-15 21:53:26 -04:00
|
|
|
missingDepsExit "sudo apt-get install $MISSING_PACKAGES"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
# yum guide.
|
|
|
|
yum --help > /dev/null 2> /dev/null && \
|
2016-03-15 21:53:26 -04:00
|
|
|
missingDepsExit "sudo yum install $MISSING_PACKAGES"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
2016-01-12 10:34:21 -05:00
|
|
|
# zypper guide.
|
|
|
|
zypper --help > /dev/null 2> /dev/null && \
|
2016-03-15 21:53:26 -04:00
|
|
|
missingDepsExit "sudo zypper install $MISSING_PACKAGES"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
# pacman guide.
|
|
|
|
pacman --help > /dev/null 2> /dev/null && \
|
2016-03-15 21:53:26 -04:00
|
|
|
missingDepsExit "sudo pacman -S $MISSING_PACKAGES"
|
2016-01-12 10:34:21 -05:00
|
|
|
|
|
|
|
# urpmi guide.
|
|
|
|
urpmi --help > /dev/null 2> /dev/null && \
|
2016-03-15 21:53:26 -04:00
|
|
|
missingDepsExit "sudo urpmi $MISSING_PACKAGES"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
2016-01-12 10:34:21 -05:00
|
|
|
missingDepsExit ""
|
2015-05-24 05:30:22 -04:00
|
|
|
fi
|
2016-01-12 10:34:21 -05:00
|
|
|
### Dependency checks end. ###
|
2015-05-24 05:30:22 -04:00
|
|
|
|
2015-11-21 08:12:11 -05:00
|
|
|
# Bypass Branch choice and choose master. Because it's the only branch right now.
|
|
|
|
BRANCH="master"
|
|
|
|
|
|
|
|
### Inactive code start. ###
|
2015-11-21 11:24:11 -05:00
|
|
|
inactiveCode ()
|
2015-11-21 08:12:11 -05:00
|
|
|
{
|
|
|
|
|
2015-05-24 05:30:22 -04:00
|
|
|
# Echo: Branch choice.
|
2016-01-13 02:29:25 -05:00
|
|
|
echo "
|
|
|
|
You can choose between 3 branches:
|
|
|
|
* (S)Stable: Choose the stable branch if you want the most
|
|
|
|
reliable server.
|
|
|
|
|
|
|
|
* (T)Testing: The testing branch is less stable,
|
|
|
|
but using it and reporting bugs helps us a lot!
|
|
|
|
|
|
|
|
* (D)Dev: The least stable of the three. (Master branch)
|
|
|
|
Choose the development branch if you want to try new,
|
|
|
|
bleeding-edge features.
|
|
|
|
"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Input: Branch choice.
|
2016-03-15 21:48:34 -04:00
|
|
|
printf %s "Choose the branch (s/t/d): "
|
2015-05-24 05:30:22 -04:00
|
|
|
read BRANCH
|
2016-03-15 21:48:34 -04:00
|
|
|
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
|
2015-05-24 05:30:22 -04:00
|
|
|
|
2015-11-21 08:12:11 -05:00
|
|
|
}
|
|
|
|
### Inactive code end. ###
|
|
|
|
|
2015-05-24 05:30:22 -04:00
|
|
|
# Echo: Compile mode choice.
|
2016-01-13 02:29:25 -05:00
|
|
|
echo "
|
|
|
|
Choose compile mode:
|
|
|
|
* (N)Normal: Compiles normally.
|
|
|
|
Generates the fastest build.
|
|
|
|
|
|
|
|
* (D)Debug: Compiles in debug mode.
|
|
|
|
Makes your console and crashes more verbose.
|
|
|
|
A bit slower than Normal mode. If you plan to help
|
|
|
|
development by reporting bugs, this is preferred.
|
|
|
|
|
|
|
|
|
|
|
|
Note that the script will connect to the internet in order to fetch
|
|
|
|
code after this step. It will then compile your program.
|
|
|
|
"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
# Input: Compile mode choice.
|
2016-03-15 21:48:34 -04:00
|
|
|
printf %s "Choose compile mode: (n/d): "
|
2015-05-24 05:30:22 -04:00
|
|
|
read BUILDTYPE
|
2016-03-15 21:48:34 -04:00
|
|
|
case $BUILDTYPE in
|
|
|
|
d|D)
|
|
|
|
BUILDTYPE="Debug"
|
|
|
|
;;
|
|
|
|
n|N)
|
|
|
|
BUILDTYPE="Release"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "Unrecognized user input."
|
|
|
|
;;
|
|
|
|
esac
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
# Echo: Downloading began.
|
|
|
|
echo
|
2015-08-16 05:07:18 -04:00
|
|
|
echo " --- Downloading Cuberite's source code from the $BRANCH branch..."
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
|
2015-08-16 05:07:18 -04:00
|
|
|
if [ ! -d cuberite ]; then
|
2015-11-21 11:24:11 -05:00
|
|
|
# Git: Clone.
|
2015-05-24 05:30:22 -04:00
|
|
|
echo " --- Looks like your first run, cloning the whole code..."
|
2016-03-15 21:53:41 -04:00
|
|
|
git clone --depth 1 https://github.com/cuberite/cuberite.git -b "$BRANCH"
|
2015-11-21 11:24:11 -05:00
|
|
|
cd cuberite
|
|
|
|
else
|
|
|
|
# Git: Fetch.
|
|
|
|
cd cuberite
|
|
|
|
echo " --- Updating the $BRANCH branch..."
|
2016-03-15 21:53:26 -04:00
|
|
|
git fetch origin "$BRANCH" || error "git fetch failed"
|
|
|
|
git checkout "$BRANCH" || error "git checkout failed"
|
|
|
|
git merge "origin/$BRANCH" || error "git merge failed"
|
2015-05-24 05:30:22 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Git: Submodules.
|
|
|
|
echo " --- Updating submodules..."
|
2015-08-16 05:07:18 -04:00
|
|
|
git submodule update --init
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Cmake.
|
|
|
|
echo " --- Running cmake..."
|
2015-08-16 05:07:18 -04:00
|
|
|
if [ ! -d build-cuberite ]; then mkdir build-cuberite; fi
|
2015-11-21 11:24:11 -05:00
|
|
|
cd build-cuberite
|
2016-03-15 21:53:26 -04:00
|
|
|
cmake .. -DCMAKE_BUILD_TYPE="$BUILDTYPE" || error "cmake failed"
|
2015-05-24 05:30:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Make.
|
|
|
|
echo " --- Compiling..."
|
2016-02-08 07:31:33 -05:00
|
|
|
make -j 2 || error "Compiling failed"
|
2015-05-24 05:30:22 -04:00
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
|
|
# Echo: Compilation complete.
|
2015-11-21 11:24:11 -05:00
|
|
|
cd ../Server
|
2015-05-24 05:30:22 -04:00
|
|
|
echo
|
|
|
|
echo "-----------------"
|
|
|
|
echo "Compilation done!"
|
|
|
|
echo
|
|
|
|
echo "Cuberite awaits you at:"
|
2015-11-21 11:24:11 -05:00
|
|
|
if [ "$BUILDTYPE" = "Debug" ]; then
|
2016-03-15 21:53:26 -04:00
|
|
|
echo "$PWD/Cuberite_debug"
|
2015-09-25 06:49:18 -04:00
|
|
|
else
|
2016-03-15 21:53:26 -04:00
|
|
|
echo "$PWD/Cuberite"
|
2015-09-25 06:49:18 -04:00
|
|
|
fi
|
2016-01-13 01:48:48 -05:00
|
|
|
cd ..
|
2016-01-13 02:29:25 -05:00
|
|
|
echo "
|
|
|
|
You can always update Cuberite by executing:
|
|
|
|
`pwd`/compile.sh
|
|
|
|
|
|
|
|
Enjoy :)"
|
2015-05-24 05:30:22 -04:00
|
|
|
exit 0
|
|
|
|
|
|
|
|
:windows_detected
|
2016-03-15 21:53:26 -04:00
|
|
|
@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
|
2015-12-10 00:12:05 -05:00
|
|
|
}
|