| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #!/usr/bin/env php
- <?php
- umask(007);
- $user_info = posix_getpwuid(posix_geteuid());
- $wd = realpath( dirname( __FILE__ ) . "/../" );
- // Look for the $private_base and $public_base. Assume /var/www/ if no homedir.
- $homedir = ( $user_info['dir'] ? $user_info['dir'] : '/var/www/' );
- $private_base = ( file_exists( "$homedir/.tCMS_basedir" ) ) ? file_get_contents( "$homedir/.tCMS_basedir" ) : "";
- if( empty( $private_base ) ) {
- echo "[NOTE] Make sure the directories you install to are R+W accessible by your web server.\n";
- echo " On most shared hosts (cPanel, etc.) this is fine to leave in your home directory.\n\n";
- 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 for tCMS' public data files.\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 );
- }
- 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" ] );
- # Make sure our webserver (and my horrible code) knows how to find your custom directory
- if( !file_exists($user_info['dir'] . "/.tCMS_basedir") ) {
- echo "[INFO]: For tCMS to know where the directory we installed to was, we will write the following\n";
- echo " into your home directory:\n";
- echo " '" . $user_info["dir"] . "/.tCMS_basedir'\n";
- echo " Please press [enter] to continue.";
- get_string_from_stdin(); # Mostly just to make the user confirm they read this.
- file_put_contents( $user_info['dir'] . "/.tCMS_basedir", realpath($private_base) );
- }
- # Create admin user
- if( !file_exists("$private_base/conf/users.json") ) {
- while( empty($username) ) {
- echo "Please enter in the name you'd like to login to tCMS as administrator (you can add more users later): ";
- $username = get_string_from_stdin();
- }
- while( empty($password) ) {
- echo "Please enter a password for the user: ";
- $password = get_string_from_stdin(1);
- $auth_hash = password_hash( $password, PASSWORD_DEFAULT );
- }
- echo "\n[INFO] Writing user configuration now...\n";
- file_put_contents( "$private_base/conf/users.json", json_encode( [ $username => [ 'auth_hash' => $auth_hash ] ] ) );
- }
- echo "[INFO] Installing public data to $public_base now...\n";
- $files = [ 'themed', 'fileshare', 'index.php', 'sys' ];
- install( $public_base, $wd, $files );
- echo "[INFO] Done.\n";
- exit(0);
- function get_string_from_stdin($noecho=0) {
- if( $noecho ) system('stty -echo');
- $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 );
- if( $noecho ) system('stty echo');
- return $input;
- }
- function install( $to, $from, $files2copy ) {
- if( empty($to) || empty($from) || empty($files2copy) ) die("Bad arguments passed to 'install' function");
- 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 ) {
- if( empty( $dirs ) ) die("Bad arguments passed to 'ensure_directories_exist' function");
- foreach ( $dirs as $dir ) {
- if ( !file_exists( $dir ) ) {
- echo "exec `/bin/mkdir '$dir'`\n";
- mkdir( $dir );
- }
- }
- return;
- }
- ?>
|