install 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/php
  2. <?php
  3. echo "[NOTE] Make sure the directories you install to are R+W accessible by your web server.\n";
  4. $user_info = posix_getpwuid(posix_geteuid());
  5. echo "Please enter the directory you wish for tCMS' private data files to be stored under.\n";
  6. echo "Default [" . $user_info['dir'] . "/.tCMS]: ";
  7. $input = get_string_from_stdin();
  8. if( empty( $input ) ) {
  9. $private_base = $user_info['dir'] . "/.tCMS";
  10. } else {
  11. # At least *try* to get the real path. If not, can't do much other than trust it works.
  12. $private_base = realpath( dirname( $input ) ) . "/" . basename( $input );
  13. }
  14. echo "Please enter the directory you wish for tCMS' public data files to be stored under.\n";
  15. echo "Default [" . $user_info['dir'] . "/public_html]: ";
  16. $input = get_string_from_stdin();
  17. if( empty( $input ) ) {
  18. $public_base = $user_info['dir'] . "/public_html";
  19. } else {
  20. $public_base = realpath( dirname( $input ) ) . "/" . basename( $input );
  21. }
  22. # Make sure our webserver (and my horrible code) knows how to find your custom directory
  23. if( $private_base != $user_info['dir'] . "/.tCMS" ) {
  24. echo "[WARN]: For tCMS to know where this directory we install to is, we will write the following\n";
  25. echo " into your document root for the default/virtual host you control on your Web Server:\n";
  26. echo " '$public_base/basedir'\n";
  27. echo " Please add an HTACCESS or similar blocker to prevent public acess to this file if you\n";
  28. echo " wish to prevent this information disclosure. Please press [enter] to continue.";
  29. get_string_from_stdin(); # Mostly just to make the user confirm they read this.
  30. }
  31. #TODO Add question here asking for administrator user setup. DO NOT ALLOW DEFAULT VALUES
  32. $wd = realpath( dirname( __FILE__ ) . "/../" );
  33. echo "[INFO] Installing private data to $private_base now...\n";
  34. $files = [ 'lib', 'templates' ];
  35. install( $private_base, $wd, $files );
  36. ensure_directories_exist( [ "$private_base/blog", "$private_base/microblog", "$private_base/conf" ] );
  37. #TODO Generate private/public keypair with passphrase of user entered credentials.
  38. echo "[INFO] Installing public data to $public_base now...\n";
  39. $files = [ 'css', 'fileshare', 'img', 'index.php', 'sys' ];
  40. install( $public_base, $wd, $files );
  41. ensure_directories_exist( [ "$public_base/css/custom", "$public_base/img/icon/custom" ] );
  42. if( $private_base != $user_info['dir'] . "/.tCMS" ) {
  43. file_put_contents( "$public_base/basedir", $private_base );
  44. }
  45. echo "[INFO] Done.\n";
  46. exit(0);
  47. function get_string_from_stdin() {
  48. $STDIN = fopen( "php://stdin", "r" );
  49. $input = fgets( $STDIN, 4096 ); # Not gonna read something longer than the maximum path length for ext
  50. $input = rtrim( $input ); # Trim any trailing spaces
  51. fclose( $STDIN );
  52. return $input;
  53. }
  54. function install( $to, $from, $files2copy ) {
  55. if( file_exists( $to ) && !is_dir( $to ) ) {
  56. echo "[FATAL] $to already exists but is not a directory! Stopping here.\n";
  57. exit(1);
  58. }
  59. if ( !file_exists( $to ) ) mkdir( $to );
  60. # XXX Prolly won't work on directories
  61. foreach ( $files2copy as $file ) {
  62. # Referencing it by path as some systems have aliases on this command
  63. $cmd = "/bin/cp -rf '$from/$file' '$to/'";
  64. echo "exec `$cmd`\n";
  65. $out = shell_exec($cmd);
  66. echo $out;
  67. }
  68. return;
  69. }
  70. function ensure_directories_exist( $dirs ) {
  71. foreach ( $dirs as $dir ) {
  72. if ( !file_exists( $dir ) ) {
  73. echo "exec `/bin/mkdir '$dir'`\n";
  74. mkdir( $dir );
  75. }
  76. }
  77. return;
  78. }
  79. ?>