| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/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);
- }
- ?>
|