From d45ca0de968260870149d6fa92a932f8f34629ba Mon Sep 17 00:00:00 2001 From: Roan Horning Date: Fri, 3 Mar 2023 20:42:42 -0500 Subject: [PATCH] Make functional stub function make_hpr_sqlite_db --- utils/lib_utils.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/utils/lib_utils.sh b/utils/lib_utils.sh index 9f7d1fc..84990e0 100644 --- a/utils/lib_utils.sh +++ b/utils/lib_utils.sh @@ -117,7 +117,46 @@ function download_hpr_sql { # PARAMETERS: # RETURNS: #------------------------------------------------------------------------------- -function make_hpr_sqlite_db { echo; } +function make_hpr_sqlite_db { + + if [[ ! -d $1 ]] || ! expr $1 : '.*/tmp.*' ; + then + echo "Please provide the temporary directory when calling this function" + return 1 + fi + + local MYSQL2SQLITE=`which mysql2sqlite` + local BIN_PATH="" + + if [ "$MYSQL2SQLITE" = "" ]; + then + if [ $# -gt 1 ] && [ -z "$2" ]; + then + BIN_PATH=$2 + else + BIN_PATH=`find . -type f -name "mysql2sqlite" -print | head -1` + if [ "$BIN_PATH" != "" ]; + then + BIN_PATH=${BIN_PATH/mysql2sqlite//} + else + echo "Could not find mysql2sqlite script." + return 1 + fi + fi + fi + echo $BIN_PATH + + if [ -f $1/hpr.db ]; + then + rm $1/hpr.db + fi + + # Remove lines from hpr.sql that mysql2sqlite can't handle + sed '/^DELIMITER ;;/,/^DELIMITER ;/d' < $1/hpr.sql > $1/hpr-sqlite.sql + + ${BIN_PATH}mysql2sqlite $1/hpr-sqlite.sql | sqlite3 $1/hpr.db + echo "Created hpr.db" +} #--- FUNCTION ---------------------------------------------------------------- # NAME: copy_to_public_dir