Skip to content

Instantly share code, notes, and snippets.

@alvin0319
Last active September 12, 2021 04:33
Show Gist options
  • Save alvin0319/e9235db7c7a3e0ace0166c33143eeb7e to your computer and use it in GitHub Desktop.
Save alvin0319/e9235db7c7a3e0ace0166c33143eeb7e to your computer and use it in GitHub Desktop.
A PocketMine-MP 4.0.0 autocompiler.
#!/bin/bash
DIR="$(pwd)"
SKIP_COMPILE="false"
INS_DIR="$DIR/install_data"
LOG="$DIR/install.log"
if [ "$(id -u)" != "0" ]; then
echo "It seems that you run this script as non-root user."
echo "If you want to run this script, make sure that run this script as root. try to use this, sudo compile.sh"
exit 1
fi
echo "PocketMine-MP 4.0.0 compiler for Linux"
if [ -f "$LOG" ]; then
rm -rf "$LOG"
fi
if [ -d "$INS_DIR" ]; then
echo "Removing old workspace..."
rm -rf "$INS_DIR"
fi
if [ -f "$DIR/PocketMine-MP.phar" ]; then
echo "Removing old PocketMine-MP.phar..."
rm -rf "$DIR/PocketMine-MP.phar"
fi
touch "$LOG"
mkdir "$INS_DIR" >> "$LOG" 2>&1
cd "$INS_DIR"
echo "Set ulimit to 8192..."
ulimit -n 8192;
echo "Cloning repository..."
git clone -b master https://github.com/pmmp/PocketMine-MP --recurse-submodules >> "$LOG" 2>&1
cd "$INS_DIR/PocketMine-MP"
PM="$INS_DIR/PocketMine-MP"
if [ -d "$DIR/bin" ]; then
SKIP_COMPILE="true"
cp "$DIR/bin" "$PM" -r
echo "Skipping compile PHP..."
fi
if [ "$SKIP_COMPILE" == "false" ]; then
echo "Compiling PHP Binary... It takes 20 ~ 30 minutes."
apt -y install make autoconf automake m4 gzip bzip2 bison g++ git cmake pkg-config re2c libtool libtool-bin >> "$LOG" 2>&1
curl -sL https://raw.githubusercontent.com/pmmp/php-build-scripts/master/compile.sh | bash -s - -g -j$(nproc) >> "$LOG" 2>&1
fi
echo "Getting composer..."
curl -sL https://getcomposer.org/installer >> installer.phar
"$PM/bin/php7/bin/php" "$PM/installer.phar" >> "$LOG" 2>&1
echo "Installing composer dependencies..."
"$PM/bin/php7/bin/php" "$PM/composer.phar" install --no-interaction --ignore-platform-reqs --no-dev >> "$LOG" 2>&1 # Please don't compile dev dependencies...
echo "Building phar..."
"$PM/bin/php7/bin/php" -dphar.readonly=0 "$PM/build/server-phar.php" >> "$LOG" 2>&1
cp "$PM/bin" "$DIR" -r >> "$LOG" 2>&1
cp "$PM/PocketMine-MP.phar" "$DIR" >> "$LOG" 2>&1
echo "Removing install data..."
cd "$DIR"
rm -rf "$INS_DIR" >> "$LOG" 2>&1
echo "Getting start.sh file..."
curl -sL https://raw.githubusercontent.com/pmmp/PocketMine-MP/master/start.sh >> start.sh
chmod 777 start.sh >> "$LOG" 2>&1
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment