| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/usr/bin/php
- <?php
- echo "[NOTE] Make sure the directories you install to are R+W accessible by your web server.\n";
- $user_info = posix_getpwuid(posix_geteuid());
- echo "Please enter the directory you wish for tCMS' private data files to be stored under.\n";
- echo "Default [" . $user_info['dir'] . "/.tCMS]: ";
- $input = get_string_from_stdin();
- if( empty( $input ) ) {
- $private_base = $user_info['dir'] . "/.tCMS";
- } else {
- # At least *try* to get the real path. If not, can't do much other than trust it works.
- $private_base = realpath( dirname( $input ) ) . "/" . basename( $input );
- }
- echo "Please enter the directory you wish for tCMS' public data files to be stored under.\n";
- echo "Default [" . $user_info['dir'] . "/public_html]: ";
- $input = get_string_from_stdin();
- if( empty( $input ) ) {
- $public_base = $user_info['dir'] . "/public_html";
- } else {
- $public_base = realpath( dirname( $input ) ) . "/" . basename( $input );
- }
- # Make sure our webserver (and my horrible code) knows how to find your custom directory
- if( $private_base != $user_info['dir'] . "/.tCMS" ) {
- echo "[WARN]: For tCMS to know where this directory we install to is, we will write the following\n";
- echo " into your document root for the default/virtual host you control on your Web Server:\n";
- echo " '$public_base/basedir'\n";
- echo " Please add an HTACCESS or similar blocker to prevent public acess to this file if you\n";
- echo " wish to prevent this information disclosure. Please press [enter] to continue.";
- get_string_from_stdin(); # Mostly just to make the user confirm they read this.
- }
- while( empty($username) ) {
- echo "Please enter in the name you'd like to login to tCMS as (you can add more users later):";
- $username = get_string_from_stdin();
- }
- while( empty($password) ) { # PHP has no standardized way to do this, so do it with shell, "pray it goes ok".
- $password = shell_exec('read -s PW; echo $PW');
- }
- $wd = realpath( dirname( __FILE__ ) . "/../" );
- echo "[INFO] Installing private data to $private_base now...\n";
- $files = [ 'lib', 'templates' ];
- install( $private_base, $wd, $files );
- ensure_directories_exist( [ "$private_base/blog", "$private_base/microblog", "$private_base/conf" ] );
- echo "[INFO] Writing user configuration and generating 4096-bit RSA public/private keypair...\n";
- #HEREHERE pick up here
- #file_put_contents('');
- #TODO Generate private/public keypair with passphrase of user entered credentials.
- echo "[INFO] Installing public data to $public_base now...\n";
- $files = [ 'css', 'fileshare', 'img', 'index.php', 'sys' ];
- install( $public_base, $wd, $files );
- ensure_directories_exist( [ "$public_base/css/custom", "$public_base/img/icon/custom" ] );
- if( $private_base != $user_info['dir'] . "/.tCMS" ) {
- file_put_contents( "$public_base/basedir", $private_base );
- }
- echo "[INFO] Done.\n";
- exit(0);
- function get_string_from_stdin() {
- $STDIN = fopen( "php://stdin", "r" );
- $input = fgets( $STDIN, 4096 ); # Not gonna read something longer than the maximum path length for ext
- $input = rtrim( $input ); # Trim any trailing spaces
- fclose( $STDIN );
- return $input;
- }
- function install( $to, $from, $files2copy ) {
- if( file_exists( $to ) && !is_dir( $to ) ) {
- echo "[FATAL] $to already exists but is not a directory! Stopping here.\n";
- exit(1);
- }
- if ( !file_exists( $to ) ) mkdir( $to );
- # XXX Prolly won't work on directories
- foreach ( $files2copy as $file ) {
- # Referencing it by path as some systems have aliases on this command
- $cmd = "/bin/cp -rf '$from/$file' '$to/'";
- echo "exec `$cmd`\n";
- $out = shell_exec($cmd);
- echo $out;
- }
- return;
- }
- function ensure_directories_exist( $dirs ) {
- foreach ( $dirs as $dir ) {
- if ( !file_exists( $dir ) ) {
- echo "exec `/bin/mkdir '$dir'`\n";
- mkdir( $dir );
- }
- }
- return;
- }
- ?>
|