Created
September 17, 2020 12:21
-
-
Save PJZ9n/6208f893768b2377970f833349a41a7e to your computer and use it in GitHub Desktop.
PocketMine-MPのインストーラー(ソースコードで)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
echo "-- PocketMineSourceInstaller --" . PHP_EOL; | |
echo "install" . PHP_EOL; | |
//バージョン入力 | |
version: | |
echo "version: "; | |
$version = trim(fgets(STDIN)); | |
//フォルダ存在確認 | |
echo "check folder..."; | |
if (file_exists("./$version/")) { | |
echo "version $version already exists." . PHP_EOL; | |
goto version; | |
} | |
echo "done." . PHP_EOL; | |
//リリース存在確認 | |
echo "check release..."; | |
$url = "https://github.com/pmmp/PocketMine-MP/releases/tag/" . $version; | |
$context = stream_context_create(["http" => ["ignore_errors" => true]]); | |
$response = file_get_contents($url, false, $context); | |
$isSuccess = strpos($http_response_header[0], "200"); | |
if ($isSuccess === false) { | |
echo "release not found." . PHP_EOL; | |
echo "url: $url" . PHP_EOL; | |
goto version; | |
} | |
echo "done." . PHP_EOL; | |
//最終確認 | |
echo "install ok? (y/N): "; | |
$ok = trim(fgets(STDIN)); | |
if ($ok !== "y") { | |
echo "bye." . PHP_EOL; | |
exit(); | |
} | |
sleep(2); | |
//インストール | |
echo "check environment..." . PHP_EOL; | |
//TODO: コマンド存在チェック方法 | |
echo "git: "; | |
if (strpos(exec("git 2>&1"), "not found") !== false) { | |
echo "not found." . PHP_EOL; | |
goto install_error; | |
} | |
echo "found." . PHP_EOL; | |
sleep(1); | |
echo "tar: "; | |
if (strpos(exec("tar 2>&1"), "not found") !== false) { | |
echo "not found." . PHP_EOL; | |
goto install_error; | |
} | |
echo "found." . PHP_EOL; | |
sleep(1); | |
echo "composer.phar: "; | |
if (!file_exists("./composer.phar")) { | |
echo "not found." . PHP_EOL; | |
echo "download composer.phar..."; | |
$composerPharUrl = "https://getcomposer.org/composer-stable.phar"; | |
if (($composerPhar = file_get_contents($composerPharUrl)) === false) goto install_error; | |
if (file_put_contents("./composer.phar", $composerPhar) === false) goto install_error; | |
echo "done." . PHP_EOL; | |
} else { | |
echo "found." . PHP_EOL; | |
} | |
sleep(1); | |
echo "php binary: "; | |
$phpPath = "./bin/php7/bin/php"; | |
if (!file_exists($phpPath)) { | |
echo "not found." . PHP_EOL; | |
echo "download archived php binary..."; | |
$phpBinaryUrl = "https://jenkins.pmmp.io/job/PHP-7.4-Aggregate/lastStableBuild/artifact/PHP-7.4-Linux-x86_64.tar.gz"; | |
if (($phpBinary = file_get_contents($phpBinaryUrl)) === false) goto install_error; | |
if (file_put_contents("./php-binary.tar.gz", $phpBinary) === false) goto install_error; | |
echo "done." . PHP_EOL; | |
echo "extract archived php binary..."; | |
if (exec("tar -zxvf ./php-binary.tar.gz") === false) goto install_error; | |
echo "done." . PHP_EOL; | |
echo "remove archived php binary..."; | |
if (!unlink("./php-binary.tar.gz")) goto install_error; | |
echo "done." . PHP_EOL; | |
echo "edit php.ini..."; | |
if (($phpIni = file_get_contents("./bin/php7/bin/php.ini")) === false) goto install_error; | |
$phpIni = str_replace(["UTC", "zend_extension="], ["Asia/Tokyo", ";zend_extension="], $phpIni); | |
if (file_put_contents("./bin/php7/bin/php.ini", $phpIni) === false) goto install_error; | |
echo "done." . PHP_EOL; | |
} else { | |
echo "found." . PHP_EOL; | |
} | |
echo "done." . PHP_EOL; | |
sleep(2); | |
echo "create folder..."; | |
if (!mkdir($version)) goto install_error; | |
echo "done." . PHP_EOL; | |
sleep(2); | |
echo "clone pmmp..." . PHP_EOL; | |
system("git clone https://github.com/pmmp/PocketMine-MP.git -b $version ./$version/ --recursive"); | |
echo "done." . PHP_EOL; | |
sleep(2); | |
echo "composer install..." . PHP_EOL; | |
chdir("./$version/");//TODO: hack | |
system("../bin/php7/bin/php ../composer.phar install"); | |
chdir("../");//TODO: hack | |
echo "done." . PHP_EOL; | |
sleep(2); | |
echo "copy php binary..." . PHP_EOL; | |
system("cp -R ./bin/ ./$version/bin/"); | |
echo "done." . PHP_EOL; | |
sleep(2); | |
echo "success!" . PHP_EOL; | |
exit(); | |
install_error: | |
echo PHP_EOL . "install error." . PHP_EOL; | |
echo "removing unfinished files..." . PHP_EOL; | |
system("rm -rf ./$version"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment