install 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $wd = realpath( dirname( __FILE__ ) . "/../" );
  32. echo "[INFO] Installing private data to $private_base now...\n";
  33. $files = [ 'lib', 'templates' ];
  34. install( $private_base, $wd, $files );
  35. foreach ( [ "$private_base/blog", "$private_base/microblog" ] as $dir ) {
  36. if ( !file_exists( $dir ) ) mkdir( $dir );
  37. }
  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. if( $private_base != $user_info['dir'] . "/.tCMS" ) {
  42. file_put_contents( "$public_base/basedir", $private_base );
  43. }
  44. echo "[INFO] Done.\n";
  45. exit(0);
  46. function get_string_from_stdin() {
  47. $STDIN = fopen( "php://stdin", "r" );
  48. $input = fgets( $STDIN, 4096 ); # Not gonna read something longer than the maximum path length for ext
  49. $input = rtrim( $input ); # Trim any trailing spaces
  50. fclose( $STDIN );
  51. return $input;
  52. }
  53. function install( $to, $from, $files2copy ) {
  54. if( file_exists( $to ) && !is_dir( $to ) ) {
  55. echo "[FATAL] $to already exists but is not a directory! Stopping here.\n";
  56. exit(1);
  57. }
  58. if ( !file_exists( $to ) ) mkdir( $to );
  59. # XXX Prolly won't work on directories
  60. foreach ( $files2copy as $file ) {
  61. # Referencing it by path as some systems have aliases on this command
  62. $cmd = "/bin/cp -rf '$from/$file' '$to/'";
  63. echo "exec `$cmd`\n";
  64. $out = shell_exec($cmd);
  65. echo $out;
  66. }
  67. return;
  68. }
  69. ?>