diff --git a/auth.json b/auth.json new file mode 100644 index 0000000..d657cbb --- /dev/null +++ b/auth.json @@ -0,0 +1,5 @@ +{ + "github-oauth": { + "github.com": "ec785da935d5535e151f7b3386190265f00e8fe2" + } +} diff --git a/index.php b/index.php index 626fda5..45c9551 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,4 @@ listen(); + // delete /_install_tmp using composer functionality + if (is_dir('_install_tmp') && file_exists('_install_tmp/composer/vendor/autoload.php')) { + // include the extracted composer libraries + require_once '_install_tmp/composer/vendor/autoload.php'; + + $fs = new Composer\Util\Filesystem(); + $fs->removeDirectory('_install_tmp'); + } + + $server = new Flarum\Forum\Server(__DIR__); + + $server->listen(); + +} elseif ((ini_get('allow_url_fopen') && !ini_get('phar.readonly')) || file_exists('scripts/composer.phar')) { + // prevent time out of page, drawback of running in browser + @set_time_limit(0); + // prevent extracting composer anew if already exists + if (!is_dir('_install_tmp/composer')) { + // attempt to download the latest composer file + if (!file_exists('scripts/composer.phar') && ini_get('allow_url_fopen')) { + file_put_contents('https://getcomposer.org/installer', 'scripts/composer.phar'); + } + // use Phar to extract the composer package + $composer = new Phar('scripts/composer.phar'); + // create a temporary directory for saving the package + mkdir('_install_tmp'); + // extract composer + $composer->extractTo('_install_tmp/composer'); + } + // if extraction succeeded, let's run the update command. + if (is_dir('_install_tmp/composer') && file_exists('_install_tmp/composer/vendor/autoload.php')) { + // force memory to at least 1GB (default for composer) otherwise composer will run out of memory + if (function_exists('ini_set')) { + ini_set('memory_limit', '1G'); + } + + // sets a home directory for storing information + putenv('COMPOSER_HOME=' . getcwd() . '/_install_tmp/home'); + // prevents any interaction composer might require + putenv('COMPOSER_NO_INTERACTION=true'); + + // run the composer installation command + $application = new Composer\Console\Application(); + + // set the input for the composer install command + $input = new Symfony\Component\Console\Input\ArrayInput([ + 'command' => 'install', + '--no-dev' => true, + '--prefer-dist' => true, + '--optimize-autoloader' => true, + '-q' => true + ]); + $application->run($input); + + // The application run call ends the process, expecting to have run in terminal. + // Running within a separate process will definitely cause new issues. + // A refresh of the page is needed to see the installation wizard. + } +} else { + throw new Exception('This method of installation is currently unsupported.'); +} \ No newline at end of file diff --git a/scripts/composer.phar b/scripts/composer.phar new file mode 100755 index 0000000..7afa6d6 Binary files /dev/null and b/scripts/composer.phar differ