sample_installer.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Sample cli installer script
  4. */
  5. // change to true to run this script. Change back to false when done.
  6. $enabled = false;
  7. // none of the following may be empty
  8. $params = array(
  9. // database parameters
  10. 'dbuser' => '',
  11. 'dbpassword' => '',
  12. 'dbname' => '',
  13. // site settings
  14. 'sitename' => '',
  15. 'siteemail' => '',
  16. 'wwwroot' => '',
  17. 'dataroot' => '',
  18. // admin account
  19. 'displayname' => '',
  20. 'email' => '',
  21. 'username' => '',
  22. 'password' => '',
  23. );
  24. // Do not edit below this line. //////////////////////////////
  25. if (!$enabled) {
  26. echo "To enable this script, change \$enabled to true.\n";
  27. echo "You *must* disable this script after a successful installation.\n";
  28. exit;
  29. }
  30. if (PHP_SAPI !== 'cli') {
  31. echo "You must use the command line to run this script.";
  32. exit;
  33. }
  34. $elggRoot = dirname(dirname(__DIR__));
  35. require_once "$elggRoot/vendor/autoload.php";
  36. $installer = new ElggInstaller();
  37. // install and create the .htaccess file
  38. $installer->batchInstall($params, TRUE);
  39. // at this point installation has completed (otherwise an exception halted execution).
  40. // try to rewrite the script to disable it.
  41. if (is_writable(__FILE__)) {
  42. $code = file_get_contents(__FILE__);
  43. if (preg_match('~\\$enabled\\s*=\\s*(true|1)\\s*;~i', $code)) {
  44. // looks safe to rewrite
  45. $code = preg_replace('~\\$enabled\\s*=\\s*(true|1)\\s*;~i', '$enabled = false;', $code);
  46. file_put_contents(__FILE__, $code);
  47. echo "\nNote: This script has been disabled for your safety.\n";
  48. exit;
  49. }
  50. }
  51. echo "\nWarning: You *must* disable this script by setting \$enabled = false;.\n";
  52. echo "Leaving this script enabled could endanger your installation.\n";