Skip to content

Supp company docker #2012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/web/release_notes/24.09.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
// pedro

// lucas
### Other updates
- Add supportingCompany support in Docker scripts. (*LM*)

// James Staub
### Reports
Expand Down
1 change: 1 addition & 0 deletions docker/files/env/default.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Aspen settings
SITE_NAME=aspen.localhost
SUPPORTING_COMPANY=ByWater Solutions
LIBRARY=Test library
TITLE=Test library (title)
URL=http://aspen.localhost
Expand Down
191 changes: 96 additions & 95 deletions docker/files/scripts/createConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,165 +2,166 @@


if (count($argv) < 2) {
echo "To create new configuration files, a directory (where the files will be stored) will be necessary as argument.\n";
die();
echo "To create new configuration files, a directory (where the files will be stored) will be necessary as argument.\n";
die();
} elseif (count($argv) > 2) {
echo "Too many arguments have been passed. The script just needs a directory to start\n";
die(1);
echo "Too many arguments have been passed. The script just needs a directory to start\n";
die(1);
}

$siteDir = $argv[1];

if (!file_exists($siteDir)) {
echo "The directory '$siteDir' does not exist.\n";
die(1);
echo "The directory '$siteDir' does not exist.\n";
die(1);
}

if (!is_dir($siteDir)) {
echo "'$siteDir' is not a directory.\n";
die(1);
echo "'$siteDir' is not a directory.\n";
die(1);
}

echo "--> Creating new configuration files...\n";

$variables = [
//ASPEN
'sitename' => getenv('SITE_NAME'),
'servername' => preg_replace('~https?://~', '', getenv('URL')),
'library' => getenv('LIBRARY'),
'title' => getenv('TITLE'),
'url' => getenv('URL'),
'configDir' => $siteDir,
'solrHost' => getenv('SOLR_HOST') ?? 'localhost',
'solrPort' => getenv('SOLR_PORT') ?? 8983,
'timezone' => getenv('TIMEZONE') ?? 'US/Central',
'aspenAdminPassword' => getenv('ASPEN_ADMIN_PASSWORD'),
'databaseHost' => getenv('DATABASE_HOST') ?? 'localhost',
'databasePort' => getenv('DATABASE_PORT') ?? 3306,
'databaseName' => getenv('DATABASE_NAME'),
'databaseUser' => getenv('DATABASE_USER'),
'databasePassword' => getenv('DATABASE_PASSWORD'),

'enableKoha' => strtolower(getenv('ENABLE_KOHA')),
//ASPEN
'sitename' => getenv('SITE_NAME'),
'servername' => preg_replace('~https?://~', '', getenv('URL')),
'supportingCompany' => getenv('SUPPORTING COMPANY') ?? 'ByWater Solutions',
'library' => getenv('LIBRARY'),
'title' => getenv('TITLE'),
'url' => getenv('URL'),
'configDir' => $siteDir,
'solrHost' => getenv('SOLR_HOST') ?? 'localhost',
'solrPort' => getenv('SOLR_PORT') ?? 8983,
'timezone' => getenv('TIMEZONE') ?? 'US/Central',
'aspenAdminPassword' => getenv('ASPEN_ADMIN_PASSWORD'),
'databaseHost' => getenv('DATABASE_HOST') ?? 'localhost',
'databasePort' => getenv('DATABASE_PORT') ?? 3306,
'databaseName' => getenv('DATABASE_NAME'),
'databaseUser' => getenv('DATABASE_USER'),
'databasePassword' => getenv('DATABASE_PASSWORD'),

'enableKoha' => strtolower(getenv('ENABLE_KOHA')),
];

if ($variables['enableKoha'] === "yes") {
$variables['ilsDriver'] = 'Koha';
$variables['ilsUrl'] = getenv('KOHA_OPAC_URL');
$variables['ilsStaffUrl'] = getenv('KOHA_STAFF_URL');
$variables['ilsDatabaseName'] = getenv('KOHA_DATABASE_NAME');
$variables['ilsDatabaseHost'] = getenv('KOHA_DATABASE_HOST');
$variables['ilsDatabasePort'] = getenv('KOHA_DATABASE_PORT');
$variables['ilsDatabaseUser'] = getenv('KOHA_DATABASE_USER');
$variables['ilsDatabasePassword'] = getenv('KOHA_DATABASE_PASSWORD');
$variables['ilsDatabaseTimeZone'] = getenv('KOHA_DATABASE_TIMEZONE') ?? 'US/Central';
$variables['ilsClientId'] = getenv('KOHA_CLIENT_ID');
$variables['ilsClientSecret'] = getenv('KOHA_CLIENT_SECRET');
$variables['ilsDriver'] = 'Koha';
$variables['ilsUrl'] = getenv('KOHA_OPAC_URL');
$variables['ilsStaffUrl'] = getenv('KOHA_STAFF_URL');
$variables['ilsDatabaseName'] = getenv('KOHA_DATABASE_NAME');
$variables['ilsDatabaseHost'] = getenv('KOHA_DATABASE_HOST');
$variables['ilsDatabasePort'] = getenv('KOHA_DATABASE_PORT');
$variables['ilsDatabaseUser'] = getenv('KOHA_DATABASE_USER');
$variables['ilsDatabasePassword'] = getenv('KOHA_DATABASE_PASSWORD');
$variables['ilsDatabaseTimeZone'] = getenv('KOHA_DATABASE_TIMEZONE') ?? 'US/Central';
$variables['ilsClientId'] = getenv('KOHA_CLIENT_ID');
$variables['ilsClientSecret'] = getenv('KOHA_CLIENT_SECRET');
} else {
$variables['ilsDriver'] = ucfirst(getenv('ILS_DRIVER'));
$variables['ilsDriver'] = ucfirst(getenv('ILS_DRIVER'));
}

$mandatory = ['sitename', 'servername', 'solrHost', 'solrPort', 'configDir', 'timezone', 'aspenAdminPassword', 'databaseHost', 'databasePort', 'databaseName', 'databaseUser', 'databasePassword'];

if ($variables['enableKoha'] === "yes") {
$kohaKeys = ['ilsDriver', 'ilsUrl', 'ilsStaffUrl', 'ilsDatabaseName', 'ilsDatabaseHost', 'ilsDatabasePort', 'ilsDatabaseUser', 'ilsDatabasePassword', 'ilsDatabaseTimeZone'];
$mandatory = array_merge($mandatory, $kohaKeys);
$kohaKeys = ['ilsDriver', 'ilsUrl', 'ilsStaffUrl', 'ilsDatabaseName', 'ilsDatabaseHost', 'ilsDatabasePort', 'ilsDatabaseUser', 'ilsDatabasePassword', 'ilsDatabaseTimeZone'];
$mandatory = array_merge($mandatory, $kohaKeys);
}

$emptyVariables = 0;

foreach ($variables as $key => $value) {
if (in_array($key, $mandatory) && empty($value)) {
echo "WARNING: Mandatory variable '" . $key . "' is empty.\n";
$emptyVariables++;
}
if (in_array($key, $mandatory) && empty($value)) {
echo "WARNING: Mandatory variable '" . $key . "' is empty.\n";
$emptyVariables++;
}
}

if ($emptyVariables > 0) {
die(1);
die(1);
}

$templateDir = "/usr/local/aspen-discovery/sites/template.linux";
$defaultDir = "/usr/local/aspen-discovery/sites/default";

if (!file_exists($templateDir)) {
echo "ERROR: The template directory '" . $templateDir . "' does not exists.\n";
die(1);
echo "ERROR: The template directory '" . $templateDir . "' does not exists.\n";
die(1);
}
if (!file_exists($defaultDir)) {
echo "ERROR: The default site directory '" . $defaultDir . "' does not exists.\n";
die(1);
echo "ERROR: The default site directory '" . $defaultDir . "' does not exists.\n";
die(1);
}

//Capture any error as ErrorException
set_error_handler("customErrorHandler");

try {
//Copy from template and replace variables
copy($templateDir . '/httpd-{sitename}.conf', "$siteDir/httpd-{$variables['sitename']}.conf");
recursive_copy($templateDir . '/conf', $siteDir . '/conf');
rename($siteDir . '/conf/config.pwd.ini.template', $siteDir . "/conf/config.pwd.ini");
copy($templateDir . '/httpd-{sitename}.conf', "$siteDir/httpd-{$variables['sitename']}.conf");
recursive_copy($templateDir . '/conf', $siteDir . '/conf');
rename($siteDir . '/conf/config.pwd.ini.template', $siteDir . "/conf/config.pwd.ini");

replaceVariables($siteDir . "/httpd-{$variables['sitename']}.conf", $variables);
replaceVariables($siteDir . '/conf/config.ini', $variables);
replaceVariables($siteDir . '/conf/config.cron.ini', $variables);
replaceVariables($siteDir . '/conf/config.pwd.ini', $variables);
replaceVariables($siteDir . "/conf/crontab_settings.txt", $variables);
replaceVariables($siteDir . "/httpd-{$variables['sitename']}.conf", $variables);
replaceVariables($siteDir . '/conf/config.ini', $variables);
replaceVariables($siteDir . '/conf/config.cron.ini', $variables);
replaceVariables($siteDir . '/conf/config.pwd.ini', $variables);
replaceVariables($siteDir . "/conf/crontab_settings.txt", $variables);

//Copy from default site directory
copy($defaultDir . "/conf/badBotsLocal.conf", $siteDir . "/conf/badBotsLocal.conf");
copy($defaultDir . "/conf/badBotsDefault.conf", $siteDir . "/conf/badBotsDefault.conf");
copy($defaultDir . "/conf/badBotsLocal.conf", $siteDir . "/conf/badBotsLocal.conf");
copy($defaultDir . "/conf/badBotsDefault.conf", $siteDir . "/conf/badBotsDefault.conf");

//Set timezone
exec('sudo timedatectl set-timezone "' . $variables['timezone'] . '"');
exec('sudo timedatectl set-timezone "' . $variables['timezone'] . '"');
//Create temp directory
!file_exists('/tmp') ?? mkdir('/tmp');
!file_exists('/tmp') ?? mkdir('/tmp');

} catch (ErrorException $e) {
echo "ERROR MESSAGE : " . $e->getMessage() . "\n";
echo "IN : " . $e->getFile() . ":" . $e->getLine() . "\n";
die(1);
echo "ERROR MESSAGE : " . $e->getMessage() . "\n";
echo "IN : " . $e->getFile() . ":" . $e->getLine() . "\n";
die(1);
}

echo "--> Configurations have been set successfully\n";

function customErrorHandler(int $errno, string $errstr, string $errfile, int $errline): void {
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting.
return;
}
if ($errno === E_DEPRECATED || $errno === E_USER_DEPRECATED) {
// Do not throw an Exception for deprecation warnings as new or unexpected
// deprecations would break the application.
return;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting.
return;
}
if ($errno === E_DEPRECATED || $errno === E_USER_DEPRECATED) {
// Do not throw an Exception for deprecation warnings as new or unexpected
// deprecations would break the application.
return;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}

function replaceVariables($filename, $variables): void {
$contents = file($filename);
$fHnd = fopen($filename, 'w');
foreach ($contents as $line) {
foreach ($variables as $name => $value) {
$line = str_replace('{' . $name . '}', $value, $line);
}
fwrite($fHnd, $line);
}
fclose($fHnd);
$contents = file($filename);
$fHnd = fopen($filename, 'w');
foreach ($contents as $line) {
foreach ($variables as $name => $value) {
$line = str_replace('{' . $name . '}', $value, $line);
}
fwrite($fHnd, $line);
}
fclose($fHnd);
}

function recursive_copy($src, $dst): void {
$dir = opendir($src);
@mkdir($dst);
while (($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
recursive_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
$dir = opendir($src);
@mkdir($dst);
while (($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
recursive_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}

36 changes: 21 additions & 15 deletions docker/files/scripts/initDatabase.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

//Initialize database
// Initialize database

echo "--> Initializing database...\n";

$aspenAdminPassword = getenv('ASPEN_ADMIN_PASSWORD');
$supportingCompany = getenv('SUPPORTING_COMPANY') ?? 'ByWater Solutions';
$databaseHost = getenv('DATABASE_HOST') ?? 'localhost';
$databasePort = getenv('DATABASE_PORT') ?? 3306;
$databaseName = getenv('DATABASE_NAME');
Expand All @@ -13,38 +14,43 @@
$databaseDsn = "mysql:host=$databaseHost;port=$databasePort;dbname=$databaseName";

$mysqlConnectionCommand = "mariadb -u$databaseUser -p$databasePassword -h$databaseHost";
$databasePort != "3306" ?? $mysqlConnectionCommand .= " --port=$databasePort";
$databasePort != "3306" ?? $mysqlConnectionCommand .= " --port=$databasePort";

//Check if aspen database has already been initialized
try {
$statement = 'SELECT libraryId FROM library LIMIT 1;';
$aspenDatabase = new PDO($databaseDsn, $databaseUser, $databasePassword);
$updateUserStmt = $aspenDatabase->prepare($statement);
$statement = 'SELECT libraryId FROM library LIMIT 1;';
$aspenDatabase = new PDO($databaseDsn, $databaseUser, $databasePassword);
$updateUserStmt = $aspenDatabase->prepare($statement);
} catch (PDOException $e) {
echo "ERROR MESSAGE : " . $e->getMessage() . "\n";
echo "IN : " . $e->getFile() . ":" . $e->getLine() . "\n";
die(1);
echo "ERROR MESSAGE : " . $e->getMessage() . "\n";
echo "IN : " . $e->getFile() . ":" . $e->getLine() . "\n";
die(1);
}

try {
$updateUserStmt->execute();
echo "--> Aspen database has already been initialized!\n";
die(0);
$updateUserStmt->execute();
echo "--> Aspen database has already been initialized!\n";
die(0);
} catch (PDOException $e) {
# Aspen database is empty yet
# Aspen database is empty yet
}

//Load default database
$aspenDir = '/usr/local/aspen-discovery/';
echo "--> Loading default database...\n";
exec("$mysqlConnectionCommand $databaseName < $aspenDir/install/aspen.sql", $output, $errorCode);
if ($errorCode != 0) {
echo " ERROR : Database '{$databaseName}' could not be loaded\n";
die(1);
echo " ERROR : Database '{$databaseName}' could not be loaded\n";
die(1);
}
echo "--> Default database has been successfully loaded\n";

//Connect to the database
// Connect to the database
$aspenDatabase = new PDO($databaseDsn, $databaseUser, $databasePassword);
$updateUserStmt = $aspenDatabase->prepare("UPDATE user set cat_password=" . $aspenDatabase->quote($aspenAdminPassword) . ", password=" . $aspenDatabase->quote($aspenAdminPassword) . " where username = 'aspen_admin'");
$updateUserStmt->execute();

// Assign supportingCompany in the database

$postSupportingCompanyStmt = $aspenDatabase->prepare("UPDATE system_variables set supportingCompany=" . $aspenDatabase->quote($supportingCompany));
$postSupportingCompanyStmt->execute();