Skip to content

Commit

Permalink
imp: Better entrypoint.sh for builder container.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byloth committed Dec 15, 2023
1 parent 6435f5a commit 8eb97e4
Showing 1 changed file with 60 additions and 30 deletions.
90 changes: 60 additions & 30 deletions builder/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
#
function echoerr()
{
echo "${@}" >&2
echo ${@} >&2
}

function success()
Expand Down Expand Up @@ -52,18 +52,16 @@ function mysql_dump()

# Sub-functions:
#
function init_world_db()
{
cd "${DATABASE_DIR}"

./InstallFullDB.sh -InstallAll "${MYSQL_SUPERUSER}" "${MYSQL_SUPERPASS}" DeleteAll
}
function update_world_db()
{
cd "${DATABASE_DIR}"

./InstallFullDB.sh -World
./InstallFullDB.sh -UpdateCore
if [[ "${1}" == "--clear" ]]
then
./InstallFullDB.sh -World
else
./InstallFullDB.sh -UpdateCore
fi
}

# Main functions:
Expand Down Expand Up @@ -98,15 +96,29 @@ function extract_resources_from_client()
}
function init_db()
{
cd "${MANGOS_DIR}/sql"
cd "${DATABASE_DIR}"

mysql_execute < create/db_create_mysql.sql
mysql_execute "${MANGOS_WORLD_DBNAME}" < base/mangos.sql
mysql_execute "${MANGOS_CHARACTERS_DBNAME}" < base/characters.sql
mysql_execute "${MANGOS_LOGS_DBNAME}" < base/logs.sql
mysql_execute "${MANGOS_REALMD_DBNAME}" < base/realmd.sql
echo ""
echo "This procedure will create all the databases required by the server"
echo " to run properly and will initialize them with the default data."
echo ""
echo -e " $(warning "WARNING!" --underline)"
echo -e " $(warning "") Please note that, if you have already initialized the databases before,"
echo -e " this procedure will prune $(info "ALL") of your data and"
echo -e " they will be lost $(info "FOREVER") (it's a very long time)!"
echo ""
read -p "Are you sure to continue? [N]: " ANSWER

if [[ "${ANSWER}" == "y" ]] || [[ "${ANSWER}" == "Y" ]]
then
echo -e " └ Please, wait... Initializing databases..."
echo ""
echo -e " --------------------------------------"

init_world_db
./InstallFullDB.sh -InstallAll "${MYSQL_SUPERUSER}" "${MYSQL_SUPERPASS}" DeleteAll
else
echo -e " └ Ok, no problem! Databases have been left untouched."
fi
}
function backup_db()
{
Expand Down Expand Up @@ -269,22 +281,40 @@ function restore_db()
}
function update_db()
{
echo ""
echo -e " $(warning "WARNING!" --underline)"
echo -e " $(warning "") This procedure will prune all customized data you"
echo -e " may have loaded into your \"$(info "${MANGOS_WORLD_DBNAME}")\" database."
echo -e ""
read -p "Are you sure to continue? [N]: " ANSWER

if [[ "${ANSWER}" == "y" ]] || [[ "${ANSWER}" == "Y" ]]
if [[ -n "${1}" ]]
then
echo -e " └ Please, wait... Updating database..."
echo -e ""
echo -e " --------------------------------------"
if [[ "${1}" == "--clear" ]]
then
echo ""
echo -e " $(warning "WARNING!" --underline)"
echo -e " $(warning "") This procedure will prune all customized data you"
echo -e " may have loaded into your \"$(info "${MANGOS_WORLD_DBNAME}")\" database."
echo ""
read -p "Are you sure to continue? [N]: " ANSWER

if [[ "${ANSWER}" == "y" ]] || [[ "${ANSWER}" == "Y" ]]
then
echo -e " └ Please, wait... Updating database..."
echo ""
echo -e " --------------------------------------"

update_world_db --clear
else
echo -e " └ Ok, no problem! Database have been left untouched."
fi
else
echoerr ""
echoerr -e " $(error "ERROR!" --underline)"
echoerr -e " $(error "") Unknown option: \"$(info "${1}")\""

update_world_db
# TODO: Add the help message.
# echoerr ""
# echoerr " Run \"$(info "update-db --help")\" for more information."

exit 1
fi
else
echo -e " └ Ok, no problem! Database have been left untouched."
update_world_db
fi
}

Expand Down Expand Up @@ -319,7 +349,7 @@ case "${1}" in
update-db)
shift

update_db
update_db ${@}
;;
*)
cd "${HOME_DIR}"
Expand Down

0 comments on commit 8eb97e4

Please sign in to comment.