install 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. while( empty($username) ) {
  32. echo "Please enter in the name you'd like to login to tCMS as (you can add more users later):";
  33. $username = get_string_from_stdin();
  34. }
  35. while( empty($password) ) { # PHP has no standardized way to do this, so do it with shell, "pray it goes ok".
  36. $password = shell_exec('read -s PW; echo $PW');
  37. }
  38. $wd = realpath( dirname( __FILE__ ) . "/../" );
  39. echo "[INFO] Installing private data to $private_base now...\n";
  40. $files = [ 'lib', 'templates' ];
  41. install( $private_base, $wd, $files );
  42. ensure_directories_exist( [ "$private_base/blog", "$private_base/microblog", "$private_base/conf" ] );
  43. echo "[INFO] Writing user configuration and generating 4096-bit RSA public/private keypair...\n";
  44. #HEREHERE pick up here
  45. #file_put_contents('');
  46. #TODO Generate private/public keypair with passphrase of user entered credentials.
  47. echo "[INFO] Installing public data to $public_base now...\n";
  48. $files = [ 'css', 'fileshare', 'img', 'index.php', 'sys' ];
  49. install( $public_base, $wd, $files );
  50. ensure_directories_exist( [ "$public_base/css/custom", "$public_base/img/icon/custom" ] );
  51. if( $private_base != $user_info['dir'] . "/.tCMS" ) {
  52. file_put_contents( "$public_base/basedir", $private_base );
  53. }
  54. echo "[INFO] Done.\n";
  55. exit(0);
  56. function get_string_from_stdin() {
  57. $STDIN = fopen( "php://stdin", "r" );
  58. $input = fgets( $STDIN, 4096 ); # Not gonna read something longer than the maximum path length for ext
  59. $input = rtrim( $input ); # Trim any trailing spaces
  60. fclose( $STDIN );
  61. return $input;
  62. }
  63. function install( $to, $from, $files2copy ) {
  64. if( file_exists( $to ) && !is_dir( $to ) ) {
  65. echo "[FATAL] $to already exists but is not a directory! Stopping here.\n";
  66. exit(1);
  67. }
  68. if ( !file_exists( $to ) ) mkdir( $to );
  69. # XXX Prolly won't work on directories
  70. foreach ( $files2copy as $file ) {
  71. # Referencing it by path as some systems have aliases on this command
  72. $cmd = "/bin/cp -rf '$from/$file' '$to/'";
  73. echo "exec `$cmd`\n";
  74. $out = shell_exec($cmd);
  75. echo $out;
  76. }
  77. return;
  78. }
  79. function ensure_directories_exist( $dirs ) {
  80. foreach ( $dirs as $dir ) {
  81. if ( !file_exists( $dir ) ) {
  82. echo "exec `/bin/mkdir '$dir'`\n";
  83. mkdir( $dir );
  84. }
  85. }
  86. return;
  87. }
  88. ?>