-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from OPUS4/4.7.2
Release 4.8 (formerly planned as 4.7.2)
- Loading branch information
Showing
128 changed files
with
988 additions
and
2,877 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,7 @@ | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# @author Thomas Urban <[email protected]> | ||
# @author Jens Schwidder <[email protected]> | ||
# @copyright Copyright (c) 2010-2016, OPUS 4 development team | ||
# @copyright Copyright (c) 2010, OPUS 4 development team | ||
# @license http://www.gnu.org/licenses/gpl.html General Public License | ||
|
||
# | ||
|
@@ -29,7 +27,6 @@ | |
|
||
set -e | ||
|
||
SCRIPT_NAME="$(basename "$0")" | ||
SCRIPT_NAME_FULL="`readlink -f "$0"`" | ||
SCRIPT_PATH="`dirname "$SCRIPT_NAME_FULL"`" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This file is part of OPUS. The software OPUS has been originally developed | ||
# at the University of Stuttgart with funding from the German Research Net, | ||
# the Federal Department of Higher Education and Research and the Ministry | ||
# of Science, Research and the Arts of the State of Baden-Wuerttemberg. | ||
# | ||
# OPUS 4 is a complete rewrite of the original OPUS software and was developed | ||
# by the Stuttgart University Library, the Library Service Center | ||
# Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg, | ||
# the Saarland University and State Library, the Saxon State Library - | ||
# Dresden State and University Library, the Bielefeld University Library and | ||
# the University Library of Hamburg University of Technology with funding from | ||
# the German Research Foundation and the European Regional Development Fund. | ||
# | ||
# LICENCE | ||
# OPUS is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU General Public License as published by the Free Software | ||
# Foundation; either version 2 of the Licence, or any later version. | ||
# OPUS is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. You should have received a copy of the GNU General Public License | ||
# along with OPUS; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# @copyright Copyright (c) 2022, OPUS 4 development team | ||
# @license http://www.gnu.org/licenses/gpl.html General Public License | ||
|
||
# | ||
# Script to set up an OPUS 4 database and database users with optional | ||
# parameters to provide custom database user names & passwords and/or a | ||
# custom database name. If no optional parameters are given, default values | ||
# will be used. | ||
# | ||
# IMPORTANT: This script is also used by other OPUS 4 packages that require | ||
# a database for testing. | ||
# | ||
# TODO merge with setup.sh (get rid of setup.sh or remove redundancy) | ||
# | ||
|
||
script_home="$(dirname "$0")" | ||
script_path="`readlink -f "$0"`" | ||
script_name="$(basename "$0")" | ||
|
||
if [[ "$script_home" == *"/vendor/"* ]]; then | ||
# Framework used as dependency in other Composer project | ||
application_path="$(dirname $(dirname $(dirname $(dirname "$script_home"))))" | ||
framework_path="$(dirname "$script_home")" | ||
else | ||
# Script used in Framework project | ||
application_path="$(dirname $(dirname "$script_path"))" | ||
framework_path=$application_path | ||
fi | ||
|
||
# Full path to configuration file | ||
config_file="$application_path/database.ini" | ||
|
||
# Define variables and their default values | ||
sqluser='root' | ||
admin="${OPUS4_DEV_DB_ADMIN:-opus4admin}" | ||
adminpwd="${OPUS4_DEV_DB_ADMIN_PWD:-opusadminpwd}" | ||
user="${OPUS4_DEV_DB_USER:-opus4}" | ||
userpwd="${OPUS4_DEV_DB_USER_PWD:-opususerpwd}" | ||
dbname='opusdb' | ||
host='localhost' | ||
port='3306' | ||
mysql='mysql' | ||
|
||
initEnabled=0 | ||
createEnabled=0 | ||
configEnabled=0 | ||
|
||
# Print command line help to stderr | ||
displayHelp() { | ||
DEFAULT='\033[0;33m' # Purple color for default values | ||
OPTION='\033[1;32m' # Green | ||
NC='\033[0m' # No Color | ||
|
||
echo "Usage: $script_name [OPTIONS]" >&2 | ||
echo | ||
echo -e "The script will ask for the SQL root password interactively, unless it is" | ||
echo -e "specified using option ${OPTION}--sqlpwd${NC}. Using this option will automatically enable" | ||
echo -e "${OPTION}--init${NC}, ${OPTION}--config${NC} and ${OPTION}--database${NC}. This is used for testing on GitHub and for" | ||
echo -e "setting up Vagrant-VMs." | ||
echo | ||
echo "Options:" | ||
echo | ||
echo -e " ${OPTION}--help${NC} (${OPTION}-h${NC}) Print out help" | ||
echo -e " ${OPTION}--init${NC} (${OPTION}-i${NC}) Initialize database schema" | ||
echo -e " ${OPTION}--config${NC} (${OPTION}-c${NC}) Write config (database.ini)" | ||
echo -e " ${OPTION}--database${NC} (${OPTION}-d${NC}) Create database" | ||
echo | ||
echo -e " DEFAULT" | ||
echo -e " ${OPTION}--sqluser${NC} SQL root user (${DEFAULT}$sqluser${NC})" | ||
echo -e " ${OPTION}--sqlpwd${NC} SQL root password" | ||
echo -e " ${OPTION}--admin${NC} Admin name (${DEFAULT}$admin${NC})" | ||
echo -e " ${OPTION}--adminpwd${NC} Admin password (${DEFAULT}$adminpwd${NC})" | ||
echo -e " ${OPTION}--user${NC} User name (${DEFAULT}$user${NC})" | ||
echo -e " ${OPTION}--userpwd${NC} User password (${DEFAULT}$userpwd${NC})" | ||
echo -e " ${OPTION}--dbname${NC} Database name (${DEFAULT}$dbname${NC})" | ||
echo -e " ${OPTION}--host${NC} MySQL host (${DEFAULT}$host${NC})" | ||
echo -e " ${OPTION}--port${NC} MySQL port (${DEFAULT}$port${NC})" | ||
echo -e " ${OPTION}--mysql${NC} MySQL client (${DEFAULT}$mysql${NC})" | ||
echo | ||
echo "Examples:" | ||
echo | ||
echo -e " $script_name" | ||
echo -e " $script_name ${OPTION}--help"${NC} | ||
echo -e " $script_name ${OPTION}--adminpwd${NC} ${DEFAULT}ADMINPWD${NC} ${OPTION}--userpwd${NC} ${DEFAULT}USERPWD${NC}" | ||
echo -e " $script_name ${OPTION}-i --dbname${NC} ${DEFAULT}opusdbtest${NC}" | ||
echo | ||
exit 1 | ||
} | ||
|
||
# Display command line help if '-h' or '--help' is given as first option | ||
if [ $# -gt 0 ]; then | ||
if [[ $1 == "-h" || $1 == "--help" ]]; then | ||
displayHelp | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# Parse any other command line options | ||
while [ $# -gt 0 ]; do | ||
if [[ $1 == "--"* ]]; then # only deal with long options | ||
if [[ -n "$2" && $2 != "-"* ]]; then # ignore options without a value | ||
# Create variable name from option name | ||
v="${1/--/}" # uses parameter expansion removing '--' | ||
|
||
# Read option value into variable | ||
declare "$v"="$2" | ||
|
||
# Process next option | ||
shift | ||
else | ||
v="${1/--/}" | ||
case $v in | ||
"init") initEnabled=1;; | ||
"config") configEnabled=1;; | ||
"database") createEnabled=1;; | ||
esac | ||
fi | ||
else | ||
case $1 in | ||
"-i") initEnabled=1;; | ||
"-c") configEnabled=1;; | ||
"-d") createEnabled=1;; | ||
esac | ||
fi | ||
shift | ||
done | ||
|
||
# if SQL root password is set as parameter enable all steps TODO perhaps changes this later | ||
if [[ $sqlpwd ]]; then | ||
initEnabled=1 | ||
configEnabled=1 | ||
createEnabled=1 | ||
fi | ||
|
||
createDatabase() | ||
{ | ||
# Querying MySQL root password | ||
[[ -z $sqlpwd ]] && read -p "MySQL root user password: " -s sqlpwd | ||
|
||
sql=$(cat <<-ENDSTRING | ||
CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET = UTF8 DEFAULT COLLATE = UTF8_GENERAL_CI; | ||
CREATE USER IF NOT EXISTS '$admin'@'localhost' IDENTIFIED WITH mysql_native_password BY '${adminpwd}'; | ||
GRANT ALL PRIVILEGES ON $dbname.* TO '$admin'@'localhost'; | ||
CREATE USER IF NOT EXISTS '$user'@'localhost' IDENTIFIED WITH mysql_native_password BY '$userpwd'; | ||
GRANT SELECT,INSERT,UPDATE,DELETE ON $dbname.* TO '$user'@'localhost'; | ||
FLUSH PRIVILEGES; | ||
ENDSTRING | ||
) | ||
|
||
export MYSQL_PWD=$sqlpwd && mysql --default-character-set=utf8 -h $host -P $port -u $sqluser -v -e "$sql" | ||
} | ||
|
||
createConfigFile() | ||
{ | ||
cat <<EOF >$config_file | ||
; Database connection parameters for running unit tests. | ||
[production] | ||
db.params.host = '$host' | ||
db.params.port = '$port' | ||
; TODO use regular OPUS user account for tests | ||
db.params.username = '$admin' | ||
db.params.password = '$adminpwd' | ||
db.params.dbname = '$dbname' | ||
; TODO resolve need to specify credentials twice (unless regular user is used above) | ||
opusdb.params.admin.name = '$admin' | ||
opusdb.params.admin.password = '$adminpwd' | ||
[testing : production] | ||
EOF | ||
} | ||
|
||
initSchema() | ||
{ | ||
export APPLICATION_PATH=$application_path && php "$framework_path/db/createdb.php" | ||
} | ||
|
||
if [[ $createEnabled == 0 && $configEnabled == 0 && $initEnabled == 0 ]]; then | ||
displayHelp | ||
exit 0 | ||
fi | ||
|
||
if [[ $createEnabled == "1" ]]; then | ||
echo "Create database ..." | ||
createDatabase | ||
fi | ||
|
||
if [[ $configEnabled == "1" ]]; then | ||
echo "Create config file ..." | ||
createConfigFile | ||
fi | ||
|
||
if [[ $initEnabled == "1" ]]; then | ||
# requires database and config file | ||
echo "Initialize database schema ..." | ||
initSchema | ||
fi | ||
|
Oops, something went wrong.