Skip to content
Snippets Groups Projects
Commit b9128361 authored by Demian Katz's avatar Demian Katz
Browse files

Made code more functional for clarity; renamed some functions to camelCase for consistency.

parent 2b5f2dba
No related merge requests found
...@@ -32,7 +32,87 @@ $basePath = '/vufind'; ...@@ -32,7 +32,87 @@ $basePath = '/vufind';
echo "VuFind has been found in {$baseDir}.\n\n"; echo "VuFind has been found in {$baseDir}.\n\n";
// Load user settings if we are not forcing defaults:
if (!isset($argv[1]) || !in_array('--use-defaults', $argv)) { if (!isset($argv[1]) || !in_array('--use-defaults', $argv)) {
$overrideDir = getOverrideDir($overrideDir);
$module = getModule();
$basePath = getBasePath($basePath);
}
// Build the Windows start file in case we need it:
buildWindowsConfig($baseDir, $overrideDir, $module);
// Build the import configuration:
buildImportConfig($baseDir, $overrideDir, 'import.properties');
buildImportConfig($baseDir, $overrideDir, 'import_auth.properties');
// Build the custom module, if necessary:
if (!empty($module)) {
buildModule($baseDir, $module);
}
// Build the final configuration:
buildApacheConfig($baseDir, $overrideDir, $basePath, $module);
// Report success:
echo "Apache configuration written to {$overrideDir}/httpd-vufind.conf.\n\n";
echo "You now need to load this configuration into Apache.\n";
echo "You can do it in either of two ways:\n\n";
echo " a) Add this line to your httpd.conf file:\n";
echo " Include {$overrideDir}/httpd-vufind.conf\n\n";
echo " b) Link the configuration to Apache's conf.d directory like this:\n";
echo " ln -s {$overrideDir}/httpd-vufind.conf "
. "/etc/apache2/conf.d/vufind\n\n";
echo "Option b is preferable if your platform supports it (paths may vary),\n";
echo "but option a is more certain to be supported.\n\n";
echo "Once the configuration is linked, restart Apache. You should now be able\n";
echo "to access VuFind at http://localhost{$basePath}\n\n";
echo "For proper use of command line tools, you should also ensure that your\n";
if (empty($module)) {
echo "VUFIND_HOME and VUFIND_LOCAL_DIR environment variables are set to\n";
echo "{$baseDir} and {$overrideDir} respectively.\n\n";
} else {
echo "VUFIND_HOME, VUFIND_LOCAL_MODULES and VUFIND_LOCAL_DIR environment\n";
echo "variables are set to {$baseDir}, {$module} and {$overrideDir} ";
echo "respectively.\n\n";
}
/**
* Get a base path from the user (or return a default).
*
* @param string $basePath Default value
*
* @return string
*/
function getBasePath($basePath)
{
// Get VuFind base path:
while (true) {
$basePathInput = getInput(
"What base path should be used in VuFind's URL? [{$basePath}] "
);
if (!empty($basePathInput)) {
if (!preg_match('/^\/\w*$/', $basePathInput)) {
echo "Error: Base path must be alphanumeric and start with a "
. "slash.\n\n";
} else {
return $basePathInput;
}
} else {
return $basePath;
}
}
}
/**
* Get an override directory from the user (or return a default).
*
* @param string $overrideDir Default value
*
* @return string
*/
function getOverrideDir($overrideDir)
{
// Get override directory path: // Get override directory path:
while (true) { while (true) {
$overrideDirInput = getInput( $overrideDirInput = getInput(
...@@ -42,14 +122,21 @@ if (!isset($argv[1]) || !in_array('--use-defaults', $argv)) { ...@@ -42,14 +122,21 @@ if (!isset($argv[1]) || !in_array('--use-defaults', $argv)) {
if (!is_dir($overrideDirInput) && !@mkdir($overrideDirInput)) { if (!is_dir($overrideDirInput) && !@mkdir($overrideDirInput)) {
echo "Error: Cannot create directory '$overrideDirInput'.\n\n"; echo "Error: Cannot create directory '$overrideDirInput'.\n\n";
} else { } else {
$overrideDir = str_replace('\\', '/', realpath($overrideDirInput)); return str_replace('\\', '/', realpath($overrideDirInput));
break;
} }
} else { } else {
break; return $overrideDir;
} }
} }
}
/**
* Get the custom module name from the user (or blank for none).
*
* @return string
*/
function getModule()
{
// Get custom module name: // Get custom module name:
echo "\nVuFind supports use of a custom module for storing local code "; echo "\nVuFind supports use of a custom module for storing local code ";
echo "changes.\nIf you do not plan to customize the code, you can "; echo "changes.\nIf you do not plan to customize the code, you can ";
...@@ -67,93 +154,11 @@ if (!isset($argv[1]) || !in_array('--use-defaults', $argv)) { ...@@ -67,93 +154,11 @@ if (!isset($argv[1]) || !in_array('--use-defaults', $argv)) {
if (in_array($moduleInput, $illegalModules)) { if (in_array($moduleInput, $illegalModules)) {
echo "\n{$moduleInput} is a reserved name; please try another.\n"; echo "\n{$moduleInput} is a reserved name; please try another.\n";
} else if (empty($moduleInput) || preg_match($regex, $moduleInput)) { } else if (empty($moduleInput) || preg_match($regex, $moduleInput)) {
$module = $moduleInput; return $moduleInput;
break;
} else { } else {
echo "\nIllegal name: {$moduleInput}; please use alphanumeric text.\n"; echo "\nIllegal name: {$moduleInput}; please use alphanumeric text.\n";
} }
} }
// Get VuFind base path:
while (true) {
$basePathInput = getInput(
"What base path should be used in VuFind's URL? [{$basePath}] "
);
if (!empty($basePathInput)) {
if (!preg_match('/^\/\w*$/', $basePathInput)) {
echo "Error: Base path must be alphanumeric and start with a "
. "slash.\n\n";
} else {
$basePath = $basePathInput;
break;
}
} else {
break;
}
}
}
// Build the Windows start file in case we need it:
$batch = "@set VUFIND_HOME={$baseDir}\n" .
"@set VUFIND_LOCAL_DIR={$overrideDir}\n" .
(empty($module) ? '' : "@set VUFIND_LOCAL_MODULES={$module}\n") .
"@call run_vufind.bat %1 %2 %3 %4 %5 %6 %7 %8 %9";
if (!@file_put_contents($baseDir . '/vufind.bat', $batch)) {
die("Problem writing {$baseDir}/vufind.bat.\n\n");
}
// Build the import configuration:
build_import_config($baseDir, $overrideDir, 'import.properties');
build_import_config($baseDir, $overrideDir, 'import_auth.properties');
// Build the custom module, if necessary:
if (!empty($module)) {
build_module($baseDir, $module);
}
// Build the final configuration:
$baseConfig = $baseDir . '/config/vufind/httpd-vufind.conf';
$config = @file_get_contents($baseConfig);
if (empty($config)) {
die("Problem reading {$baseConfig}.\n\n");
}
$config = str_replace("/usr/local/vufind/local", "%override-dir%", $config);
$config = str_replace("/usr/local/vufind", "%base-dir%", $config);
$config = str_replace("/vufind", "%base-path%", $config);
$config = str_replace("%override-dir%", $overrideDir, $config);
$config = str_replace("%base-dir%", $baseDir, $config);
$config = str_replace("%base-path%", $basePath, $config);
if (!empty($module)) {
$config = str_replace(
"#SetEnv VUFIND_LOCAL_MODULES VuFindLocalTemplate",
"SetEnv VUFIND_LOCAL_MODULES {$module}", $config
);
}
if (!@file_put_contents($overrideDir . '/httpd-vufind.conf', $config)) {
die("Problem writing {$overrideDir}/httpd-vufind.conf.\n\n");
}
// Report success:
echo "Apache configuration written to {$overrideDir}/httpd-vufind.conf.\n\n";
echo "You now need to load this configuration into Apache.\n";
echo "You can do it in either of two ways:\n\n";
echo " a) Add this line to your httpd.conf file:\n";
echo " Include {$overrideDir}/httpd-vufind.conf\n\n";
echo " b) Link the configuration to Apache's conf.d directory like this:\n";
echo " ln -s {$overrideDir}/httpd-vufind.conf "
. "/etc/apache2/conf.d/vufind\n\n";
echo "Option b is preferable if your platform supports it (paths may vary),\n";
echo "but option a is more certain to be supported.\n\n";
echo "Once the configuration is linked, restart Apache. You should now be able\n";
echo "to access VuFind at http://localhost{$basePath}\n\n";
echo "For proper use of command line tools, you should also ensure that your\n";
if (empty($module)) {
echo "VUFIND_HOME and VUFIND_LOCAL_DIR environment variables are set to\n";
echo "{$baseDir} and {$overrideDir} respectively.\n\n";
} else {
echo "VUFIND_HOME, VUFIND_LOCAL_MODULES and VUFIND_LOCAL_DIR environment\n";
echo "variables are set to {$baseDir}, {$module} and {$overrideDir} ";
echo "respectively.\n\n";
} }
/** /**
...@@ -180,6 +185,60 @@ function getInput($prompt) ...@@ -180,6 +185,60 @@ function getInput($prompt)
} }
} }
/**
* Generate the Apache configuration.
*
* @param string $baseDir The VuFind base directory
* @param string $overrideDir The VuFind override directory
* @param string $basePath The VuFind URL base path
* @param string $module The VuFind custom module name (or empty for none)
*
* @return void
*/
function buildApacheConfig($baseDir, $overrideDir, $basePath, $module)
{
$baseConfig = $baseDir . '/config/vufind/httpd-vufind.conf';
$config = @file_get_contents($baseConfig);
if (empty($config)) {
die("Problem reading {$baseConfig}.\n\n");
}
$config = str_replace("/usr/local/vufind/local", "%override-dir%", $config);
$config = str_replace("/usr/local/vufind", "%base-dir%", $config);
$config = str_replace("/vufind", "%base-path%", $config);
$config = str_replace("%override-dir%", $overrideDir, $config);
$config = str_replace("%base-dir%", $baseDir, $config);
$config = str_replace("%base-path%", $basePath, $config);
if (!empty($module)) {
$config = str_replace(
"#SetEnv VUFIND_LOCAL_MODULES VuFindLocalTemplate",
"SetEnv VUFIND_LOCAL_MODULES {$module}", $config
);
}
if (!@file_put_contents($overrideDir . '/httpd-vufind.conf', $config)) {
die("Problem writing {$overrideDir}/httpd-vufind.conf.\n\n");
}
}
/**
* Build the Windows-specific startup configuration.
*
* @param string $baseDir The VuFind base directory
* @param string $overrideDir The VuFind override directory
* @param string $module The VuFind custom module name (or empty for none)
*
* @return void
*/
function buildWindowsConfig($baseDir, $overrideDir, $module)
{
$batch = "@set VUFIND_HOME={$baseDir}\n" .
"@set VUFIND_LOCAL_DIR={$overrideDir}\n" .
(empty($module) ? '' : "@set VUFIND_LOCAL_MODULES={$module}\n") .
"@call run_vufind.bat %1 %2 %3 %4 %5 %6 %7 %8 %9";
if (!@file_put_contents($baseDir . '/vufind.bat', $batch)) {
die("Problem writing {$baseDir}/vufind.bat.\n\n");
}
}
/** /**
* Configure a SolrMarc properties file. * Configure a SolrMarc properties file.
* *
...@@ -189,7 +248,7 @@ function getInput($prompt) ...@@ -189,7 +248,7 @@ function getInput($prompt)
* *
* @return void * @return void
*/ */
function build_import_config($baseDir, $overrideDir, $filename) function buildImportConfig($baseDir, $overrideDir, $filename)
{ {
$import = @file_get_contents($baseDir . '/import/' . $filename); $import = @file_get_contents($baseDir . '/import/' . $filename);
$import = str_replace("/usr/local/vufind", $baseDir, $import); $import = str_replace("/usr/local/vufind", $baseDir, $import);
...@@ -215,7 +274,7 @@ function build_import_config($baseDir, $overrideDir, $filename) ...@@ -215,7 +274,7 @@ function build_import_config($baseDir, $overrideDir, $filename)
* *
* @return void * @return void
*/ */
function build_module($baseDir, $module) function buildModule($baseDir, $module)
{ {
// Create directories: // Create directories:
$moduleDir = $baseDir . '/module/' . $module; $moduleDir = $baseDir . '/module/' . $module;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment