#!/bin/bash
apt-get update
apt-get install -y git curl wget jq file tar unzip zip
mkdir -p /mnt/server/
cd /mnt/server || exit 1
ARCH=$([[ "$(uname -m)" == "x86_64" ]] && printf "x86_64" || printf "arm64")
VERSION="${VERSION:-PM5}"
VERSION="${VERSION^^}"
download_php_binary() {
local php_binary_url
if [[ "$VERSION" == "PM5" ]]; then
php_binary_url="https://github.com/pmmp/PHP-Binaries/releases/download/pm5-latest/PHP-8.2-Linux-${ARCH}-PM5.tar.gz"
elif [[ "$VERSION" == "PM4" ]]; then
php_binary_url="https://github.com/pmmp/PHP-Binaries/releases/download/pm4-latest/PHP-8.1-Linux-${ARCH}-PM4.tar.gz"
else
printf "Unsupported version: %s\n" "${VERSION}"
exit 1
fi
printf "Downloading PHP binary for %s from %s\n" "$VERSION" "$php_binary_url"
curl --location --progress-bar "$php_binary_url" | tar -xzv
}
set_php_extension_dir() {
printf "Configuring php.ini\n"
EXTENSION_DIR=$(find "bin" -name '*debug-zts*')
grep -q '^extension_dir' bin/php7/bin/php.ini && \
sed -i'bak' "s{^extension_dir=.*{extension_dir=\"$EXTENSION_DIR\"{" bin/php7/bin/php.ini || \
echo "extension_dir=\"$EXTENSION_DIR\"" >>bin/php7/bin/php.ini
}
download_pmmp() {
DOWNLOAD_LINK=$(curl -sSL https://update.pmmp.io/api?channel="$API_CHANNEL" | jq -r '.download_url')
printf "Downloading %s from %s\n" "$VERSION" "${DOWNLOAD_LINK}"
curl --location --progress-bar "${DOWNLOAD_LINK}" --output PocketMine-MP.phar
}
if [[ "${VERSION}" == "PM4" ]]; then
API_CHANNEL="4"
elif [[ "${VERSION}" == "PM5" ]]; then
API_CHANNEL="stable"
else
printf "Unsupported version: %s\n" "${VERSION}"
exit 1
fi
REQUIRED_PHP_VERSION=$(curl -sSL https://update.pmmp.io/api?channel="$API_CHANNEL" | jq -r '.php_version')
if [[ "${ARCH}" == "x86_64" ]]; then
download_php_binary
else
apt-get install -y make autoconf automake m4 bzip2 bison g++ cmake pkg-config re2c libtool-bin
mkdir -p /mnt/server/build_cache/archives
mkdir -p /mnt/server/build_cache/compilation
echo "Running curl to download compile.sh for PHP version $REQUIRED_PHP_VERSION"
curl --location --progress-bar --remote-name https://raw.githubusercontent.com/pmmp/PHP-Binaries/latest/compile.sh
chmod +x compile.sh
cat <<EOF
----------------------------------------
| |
| Compiling PHP Binary for ARM64 |
| |
| This is a time consuming process |
----------------------------------------
EOF
printf "\n\nCompiling PHP binary, this is a slow process and will take time\n"
THREADS=$(grep -c ^processor /proc/cpuinfo) || THREADS=1
./compile.sh -j "${THREADS}" -c /mnt/server/build_cache/archives -l /mnt/server/build_cache/compilation -z "${REQUIRED_PHP_VERSION}"
rm compile.sh
rm -rf install_data/
fi
download_pmmp
set_php_extension_dir || exit 1
if [[ ! -f server.properties ]]; then
printf "Downloading default server.properties template\n"
curl --location --progress-bar --remote-name https://raw.githubusercontent.com/parkervcp/eggs/master/game_eggs/minecraft/bedrock/pocketmine_mp/server.properties
fi
printf "Creating default file and folder structure\n"
touch banned-ips.txt banned-players.txt ops.txt white-list.txt server.log
mkdir -p players worlds plugins resource_packs
cat <<EOF
----------------------------------------
| |
| PocketMine-MP Installation Done |
| |
----------------------------------------
EOF