configure-tCMS 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/php
  2. <?php
  3. # This bit near the top is used for running via CLI, the class is below this if block
  4. # Assume we're doing things interactively if we're passing in args
  5. if( !empty( $argv[1] ) ) {
  6. switch( $argv[1] ) {
  7. case "help":
  8. $help = "tCMS Configuration Script Options:\n";
  9. $help .= " install -- Guides the user through first time tCMS setup.\n";
  10. $help .= " get <FILE> -- Gets and outputs the values in the supplied JSON file.\n";
  11. $help .= " validate <FILE> -- Compares your config versus the model (sanity check).\n";
  12. $help .= " set <KEY1> <VAL1> <KEY2> <VAL2>... -- Sets the requested config KEY(s) to VALUE(s).\n";
  13. echo $help;
  14. break;
  15. case "install":
  16. echo "[INFO] Some of this function is unimplemented -- for now I'm just making things for testing.\n";
  17. $user_info = posix_getpwuid();
  18. $basedir = $user_info['dir'] . "/.tCMS";
  19. if( !file_exists( $basedir ) ) {
  20. if( !is_dir( $basdir ) ) {
  21. echo "[FATAL] ~/.tCMS already exists but is not a directory! Stopping here.\n";
  22. exit(1);
  23. } else {
  24. $dirs = [
  25. $basedir, "$basedir/bin", "$basedir/lib", "$basedir/conf", "$basedir/themes",
  26. "$basedir/microblog", "$basedir/blog", "$basedir/fileshare"
  27. ];
  28. foreach ( $dirs as $dir ) {
  29. mkdir( $dir );
  30. }
  31. }
  32. # Handle first time install, assume we're being ran via Makefile
  33. $install_base = realpath( dirname( __FILE__ ) );
  34. $files2copy = [ "bin/configure-tCMS"];
  35. foreach ( $files2copy as $file ) {
  36. if( !copy( "$install_base/$file", "$basedir/$file" ) ) {
  37. echo "[FATAL] $file couldnt' be installed!";
  38. exit(1);
  39. }
  40. }
  41. } else {
  42. echo "[INFO] tCMS appears to already be installed. Nothing to do...\n";
  43. exit(0);
  44. }
  45. # TODO keep going here
  46. case "get":
  47. if( empty( $argv[2] ) ) {
  48. echo "[ERROR] get was passed but no file was passed to get!\n";
  49. exit(1);
  50. }
  51. $config_file = realpath( $argv[2] );
  52. $config = configure::get_config_values( $config_file );
  53. print_r( $config );
  54. break;
  55. case "set":
  56. echo "[INFO] Unimplemented\n";
  57. break;
  58. case "validate":
  59. if( empty( $argv[2] ) ) {
  60. echo "[ERROR] validate was passed but no file was passed to validate against!\n";
  61. exit(1);
  62. }
  63. $config_file = realpath( $argv[2] );
  64. $config = configure::get_config_values( $config_file );
  65. $valid = configure::validate_config( $config );
  66. echo ( $valid ) ? "[INFO] Config OK\n" : "[ERROR] Config NOT OK.\n";
  67. exit( $valid );
  68. }
  69. exit(0);
  70. }
  71. ?>