Explorar el Código

Installer basically works now.

Andy Baugh hace 9 años
padre
commit
2f42921f7d
Se han modificado 5 ficheros con 87 adiciones y 84 borrados
  1. 1 1
      Makefile
  2. 0 2
      TODO
  3. 0 71
      bin/configure-tCMS
  4. 71 0
      bin/install
  5. 15 10
      templates/default/notconfigured.tmpl

+ 1 - 1
Makefile

@@ -3,4 +3,4 @@ test:
 	prove --exec 'php' t/*.t
 
 install:
-	php sys/admin/lib/configure.php install
+	php bin/install

+ 0 - 2
TODO

@@ -1,6 +1,4 @@
 tCMS2 still left undone (will add to as I think of em)
-* 'make install' target that runs configure.php to do first time config and install.
-* 'configure.php' needs CLI run opts triggered on ARGV not being blank
 * config needs to be based on a model json file.
 * tests for config reading and comparison based on model
 * tests for config validation of user input (wanna make sure we *can* install

+ 0 - 71
bin/configure-tCMS

@@ -1,71 +0,0 @@
-#!/usr/bin/php
-<?php
-# This bit near the top is used for running via CLI, the class is below this if block
-# Assume we're doing things interactively if we're passing in args
-if( !empty( $argv[1] ) ) {
-    switch( $argv[1] ) {
-        case "help":
-            $help  = "tCMS Configuration Script Options:\n";
-            $help .= "  install         -- Guides the user through first time tCMS setup.\n";
-            $help .= "  get <FILE>      -- Gets and outputs the values in the supplied JSON file.\n";
-            $help .= "  validate <FILE> -- Compares your config versus the model (sanity check).\n";
-            $help .= "  set <KEY1> <VAL1> <KEY2> <VAL2>... -- Sets the requested config KEY(s) to VALUE(s).\n";
-            echo $help;
-            break;
-        case "install":
-            echo "[INFO] Some of this function is unimplemented -- for now I'm just making things for testing.\n";
-            $user_info = posix_getpwuid();
-            $basedir = $user_info['dir'] . "/.tCMS";
-            if( !file_exists( $basedir ) ) {
-                if( !is_dir( $basdir ) ) {
-                    echo "[FATAL] ~/.tCMS already exists but is not a directory! Stopping here.\n";
-                    exit(1);
-                } else {
-                    $dirs = [ 
-                        $basedir, "$basedir/bin", "$basedir/lib", "$basedir/conf", "$basedir/themes",
-                        "$basedir/microblog", "$basedir/blog", "$basedir/fileshare"
-                    ];
-                    foreach ( $dirs as $dir ) { 
-                        mkdir( $dir );
-                    }
-                }
-                # Handle first time install, assume we're being ran via Makefile
-                $install_base = realpath( dirname( __FILE__ ) );
-                $files2copy = [ "bin/configure-tCMS"];
-                foreach ( $files2copy as $file ) {
-                    if( !copy( "$install_base/$file", "$basedir/$file" ) ) {
-                        echo "[FATAL] $file couldnt' be installed!";
-                        exit(1);
-                    }
-                }
-            } else {
-                echo "[INFO] tCMS appears to already be installed. Nothing to do...\n";
-                exit(0);
-            }
-            # TODO keep going here
-        case "get":
-            if( empty( $argv[2] ) ) {
-                echo "[ERROR] get was passed but no file was passed to get!\n";
-                exit(1);
-            }
-            $config_file = realpath( $argv[2] );
-            $config = configure::get_config_values( $config_file );
-            print_r( $config );
-            break;
-        case "set":
-            echo "[INFO] Unimplemented\n";
-            break;
-        case "validate":
-            if( empty( $argv[2] ) ) {
-                echo "[ERROR] validate was passed but no file was passed to validate against!\n";
-                exit(1);
-            }
-            $config_file = realpath( $argv[2] );
-            $config = configure::get_config_values( $config_file );
-            $valid  = configure::validate_config( $config );
-            echo ( $valid ) ? "[INFO] Config OK\n" : "[ERROR] Config NOT OK.\n";
-            exit( $valid );
-    }
-    exit(0);
-}
-?>

+ 71 - 0
bin/install

@@ -0,0 +1,71 @@
+#!/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.
+}
+$wd = realpath( dirname( __FILE__ ) . "/../" );
+echo "[INFO] Installing private data to $private_base now...\n";
+$files = [ 'lib', 'templates' ];
+install( $private_base, $wd, $files );
+foreach ( [ "$private_base/blog", "$private_base/microblog" ] as $dir ) {
+    if ( !file_exists( $dir ) ) mkdir( $dir );
+}
+echo "[INFO] Installing public data to $public_base now...\n";
+$files = [ 'css', 'fileshare', 'img', 'index.php', 'sys' ];
+install( $public_base, $wd, $files );
+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;
+}
+?>

+ 15 - 10
templates/default/notconfigured.tmpl

@@ -23,13 +23,8 @@
             }
             section {
                 display: block;
-                width: 100%;
                 margin: 1rem auto 0 auto;
-            }
-            @media( min-width: 768px ) {
-                section {
-                    width: 80%;
-                }
+                padding: 0 1rem;
             }
             #notice {
                 display: table;
@@ -43,12 +38,20 @@
                 display: table-cell;
                 vertical-align: middle;
             }
+            /* Styles for larger viewports */
+            @media( min-width: 768px ) {
+                section {
+                    width: 80%;
+                }
+                #notice {
+                    width: calc( 100% - 1rem);
+                }
+            }
         </style>
     </head>
     <body>
         <nav>
-            <strong>tCMS Configuration <!--Wizard--></strong>
-            <span style="float: right;">Step 1</span>
+            <strong>tCMS Initial Setup</strong>
         </nav>
         <section>
             <div id="notice">
@@ -59,11 +62,13 @@
                 </span>
             </div>
             <p>
-                Please see the
+                <strong>Note:</strong> Please see the
                 <a href="https://tcms.troglodyne.net/index.php?nav=5&post=fileshare/manual/Chapter%2000-Introduction.post">
                     tCMS Manual
                 </a>
-                for instructions on how configure tCMS.
+                for full instructions on how configure tCMS.
+                <br /><br />
+                Please <a href="sys/admin?app=config" alt="Login">Log In</a> and Configure tCMS.
             </p>
         </section>
     </body>