Commands
dbm version
Show version of dbm module.
$# dbrm dbm version
Version: 0.1.0
dbm info
Show active parameters of dbrm module.
$# dbrm dbm info
LOCAL_DIR = /tmp/database-release-manager
LOCAL_CONFIG_FILE = /home/geaaru/.local/share/dbrm/dbrm.conf
MODULES_DIR = /usr/share/dbrm/modules
SQLCA = sqlite|mariadb|psql
DRM_DB = ./test.db
DBM_HISTORY = /tmp/database-release-manager/.dbm_history
DRM_PROFILE = 1
DRM_PROFILES_PATH = /home/geaaru/.local/share/dbrm/profiles
MARIADB_USER = root
MARIADB_PWD = pwd
MARIADB_DB = test
MARIADB_HOST =
MARIADB_DIR = .
MARIADB_TMZ = UTC
MARIADB_COMPILE_FILES_EXCLUDED =
MARIADB_EXTRA_OPTIONS =
MARIADB_ENABLE_COMMENTS =
SQLITEDB = ./test.db
TODO:
- Execute call of info modules to every connector adapter without statically manage it inside this function.
dbm initenv
Create a new empty dbrm database and copy example file of dbrm.conf on new project directory.
initenv options:
--to-current-dir
: Initialize dbrm stuff on current directory [.]. If this option is used is not possible use
--to-dir option.
--to-dir <TARGET_DIR>
: Initialize dbrm stuff on a target directory passed in input.
--enable-profiles
: Enable Profiles Features on new project.
--help|-h
: Show initenv command options.
Exit Values:
1
: On error or if a dbrm.conf file or dbrm.db file is already present.
0
: On success
$# dbrm dbm initenv --help
[--to-current-dir] Initialize current directory [.].
[--to-dir target] Initialize target directory.
[--enable-profiles] Enable profiles mode and create related directories.
[--help|-h] Show help message.
$# dbrm dbm initenv --to-dir /tmp/dbrm --enable-profiles
Creating database /tmp/dbrm/dbrm.db...OK
Created profile 1.
Directory is now initialized.
Modify dev.conf file under dbrm-profile directory for complete configuration.
TODO:
- Add option to initialized initenv method of a list of connection adapters.
dbm shell
Enter on dbm sqlite database file.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm shell
SQLite version 3.13.0 2016-05-18 10:57:30
Enter ".help" for usage hints.
sqlite>
dbm show_profiles
Show list of configured profiles. This method is used only if Profiles Feature is enabled.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_profiles
===============================================================================================================
ID PROFILE_NAME DEFAULT CONFIG_FILE CREATION_DATE UPDATE_DATE
===============================================================================================================
1 test1 test.conf 2015-01-18 15:17:43 2015-01-18 21:25:25
2 dev * dev.conf 2015-01-18 16:59:17 2015-01-18 21:29:57
On example, files test.conf and dev.conf must be under directory defined by DRM_PROFILES_PATH variable.
dbm show_releases
Show releases history.
show_releases options:
-b ID_BRANCH
: Filter list for a particular Branch Id.
-h
: Show show_releases command options.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_releases
===============================================================================================================
ID RELEASE_DATE VERSION UPDATE_DATE ADAPTER ID_ORDER BRANCH DIRECTORY NAME
===============================================================================================================
1 2013-05-05 20:41:29 0.1.0 2013-05-08 13:04:56 oracle 1 1 . Test Platform
4 2013-05-06 14:50:29 0.1.1 2013-11-18 01:11:35 oracle 1 2 . Test Platform
9 2013-11-18 01:09:14 0.2.0 2013-11-18 01:09:14 oracle 2 1 . Test Platform
5 2013-11-18 00:33:10 0.1.2 2013-11-18 01:11:35 oracle 2 2 . Test Platform
12 2013-11-18 00:00:01 0.3.0 2013-11-18 01:15:47 oracle 3 1 . Test Platform
13 2013-11-18 00:00:01 0.4.0 2013-11-18 01:15:47 oracle 4 1 . Test Platform
TODO:
- Manage help message like other modules with both -h and --help options.
dbm show_scripts
Show list of scripts configured and assigned to a release.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_scripts
===============================================================================================================
ID TYPE ACTIVE DIRECTORY ID_RELEASE ID_ORDER UPDATE_DATE FILENAME
===============================================================================================================
1 update_script 1 update_script/ 1 1 2013-05-05 21:26:37 update__0.1.0.sql
6 update_script 1 update_script/ 4 1 2013-05-06 14:52:30 patch_0_1.1.sql
4 update_script 1 update_script/ 9 1 2014-02-03 16:25:45 update_0.2.0.sql
5 update_script 1 update_script/ 12 1 2014-02-03 16:25:21 update_0.3.0.sql
TODO:
- Manage help message like other modules with both -h and --help options.
- Add filter options (for id release, filename, etc.)
dbm show_script_types
Show list of script types.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_script_types
===============================================================================================================
CODE DESCRIPTION
===============================================================================================================
foreign_key Foreign Key Script
function Function definition script
initial_ddl Initial DDL Script
insert Insert on table script
package Package definition script
procedure Procedure definition script
sequence Sequences Script
trigger Trigger Script
type Types Script (For example for a TYPE definition on Oracle)
update_script Update Script
view View definition script
dbm show_rel_dep
Show list of releases dependencies with scripts.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_rel_dep
===============================================================================================================
ID_RELEASE DEPENDENCY CREATION_DATE
===============================================================================================================
2 1 2013-05-05 21:58:58
3 1 2013-05-05 21:59:10
3 2 2013-05-05 21:58:53
3 4 2013-05-06 14:55:01
dbm show_inhibit_scripts
Show list of inhibitions scripts between releases.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_inhibit_scripts
===============================================================================================================
ID_SCRIPT ID_RELEASE_FROM ID_RELEASE_TO CREATION_DATE
===============================================================================================================
6 1 2 2013-05-05 23:33:12
dbm show_rel_ded_scripts
Show list of release dedicated scripts.
Exit Values:
1
: On error
0
: On success
$# dbrm dbm show_rel_ded_scripts
No scripts available.
dbm show_adapters
Show list of adapters availables.
Exit Values:
1
: On error
0
: On success
$ dbrm dbm show_adapters
===============================================================================================================
ADAPTER DESCRIPTION
===============================================================================================================
mariadb MySQL/MariaDb Database Adapter
oracle Oracle Database Adapter
sqlite SQLite Database Adapter
dbm move_release
Move release position of the same Branch.
move_release options:
-r VERSION
: Version of the release to move
-n NAME
: Name of the release to move
-a VERSION_TO
: Move selected release after VERSION_TO
-b VERSION_TO
: Move selected release before VERSION_TO
-h
: Show move_release command options.
Exit Values:
1
: On error.
0
: On success
TODO:
- add long options arguments.
dbm update_release
Update information about a particular release.
update_release options:
-n NAME
: Name of the release to update.
-v VERSION
: Version of the release to update.
-d YYYY-MM-DD
: Date of the release to update.
-a ADAPTER
: Adapter value to update on release.
-b ID_BRANCH
: Branch Id value to update on release.
-i ID_RELEASE
: Id of the release to update
--dir DIR
: Directory of the release to update
-h
: Show update_release command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm update_release -i 5 -a oracle -d ./0.1.2
Release 5 updated correctly.
dbm add_profile
Insert a new configuration profile.
app_profile options:
--name NAME
: Name of the profile to insert.
--file FILE
: Configuration file to use on new profile. FILE contains only filename.
--default
: Enable new profile as default.
-h
: Show app_profile command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm add_profile --name test_profile --file profile1.conf
Created profile 7.
dbm del_profile
Delete a configured profile.
del_profile options:
--name NAME
: Name of the profile to delete.
--id ID_PROFILE
: Id of the profile to delete
-h
: Show del_profile command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm del_profile --id 7
Profile 7 is been deleted.
dbm set_profile
Set default profile.
set_profile options:
--name PROFILE_NAME
: Name of the profile to set.
--id ID_PROFILE
: Id of the profile to set.
-h
: Show set_profile command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm set_profile --id 7
Profile 7 is now set as default.
dbm insert_release
Insert a new release to project.
insert_release options:
-n RELEASE_NAME
: Name of the release to add.
-d YYYY-MM-DD
: Release date of the release to add.
-v VERSION
: Version of the release to add.
-a ADAPTER
: Adapter used by the release to add (default is oracle).
-o ID_ORDER
: Id order of the release to add.
-b BRANCH_ID
: Id of the branch connected to release to add.
-dir DIRECTORY
: Directory of the release to add.
-h
: Show insert_release command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_release
[-n name] Release Name.
[-d YYYY-MM-DD] Release Date. (Use now if not available)
[-v version] Release Version
[-a adapter] Release Adapter (default is Oracle).
[-o id_order] Release Id Order (optional).
[-b id_branch] Release Id Branch (default master branch {1}).
[--dir directory] Release directory (default is [.]).
$# dbrm dbm insert_release -n 'Project1' -d 2017-04-24 -v 1.2.3 -a mariadb --dir .
Release Project1 v. 1.2.3 insert correctly.
dbm remove_release
Remove a release from project.
remove_release options:
-r RELEASE_ID
: Id of the release to remove.
-f
: For remove of the selected release without confirmation question.
-h
: Show remove_release command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm remove_release
[-r id_release] Id Release of the script to remove.
[-f] Force remove without confirmation question.
$# dbrm dbm remove_release -r 15
Are you sure to remove release with id 15? [N/y]y
Release 15 is been removed.
TODO:
- use also long options for command arguments.
dbm remove_script
Remove a script from project.
remove_script options:
-i SCRIPT_ID
: Id of the script to remove.
-h
: Show remove_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm remove_script
[-i id_script] Id Script of the script to remove.
$# dbrm dbm remove_script -i 10
Script 10 removed correctly.
TODO:
- use also long options for command arguments.
dbm update_script
Update information about a script.
update_script options:
-i SCRIPT_ID
: Id of the script to update.
-f FILENAME
: Script filename to update.
-n NAME
: Name of the release of the script to update.
-v VERSION
: Version of the release of the script to update.
-t STYPE
: Type of the script to update
-a FLAG
: Set active (1) or disable (0) flag of the script.
-d DIRECTORY
: Directory of the script to update.
-o ID_ORDER
: Id order of the script to update (optional).
-r RELEASE_ID
: Id of the release of the script.
If this option is present are not needed release name and release version.
-h
: Show update_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm update_script -h
[-i id_script] Id Script.
[-f filename] Script filename.
[-n name] Release Name.
[-v version] Release Version
[-t script_type] Script Type.
[-a 0|1] Set active flag.
[-d directory] Directory of the script.
[-o id_order] Script Id Order (optional). Default is used MAX(id) of the same id_release.
[-r id_release] Id_release of the script. Use this instead of release name and version.
$# dbrm dbm update_script -i 10 -a 1
Script 10 updated correctly.
TODO:
- use also long options for command arguments.
dbm insert_script
Insert a new script to a release.
insert_script options:
-f FILENAME
: Script filename.
-n NAME
: Name of the release of the script to insert.
-v VERSION
: Version of the release of the script to insert.
-t STYPE
: Type of the script to insert.
-a FLAG
: Set active (1) or disable (0) flag of the script.
-d DIRECTORY
: Directory of the script to insert.
-o ID_ORDER
: Id order of the script to update (optional).
Default is used MAX(id) of the same id_release.
-r RELEASE_ID
: Id of the release of the script.
If this option is present are not needed release name and release version.
-h
: Show insert_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_script
[-f filename] Script filename.
[-n name] Release Name.
[-v version] Release Version
[-t script_type] Script Type.
[-a 0|1] Set active flag. Default is 1 (active)
[-d directory] Directory of the script.
[-o id_order] Script Id Order (optional). Default is used MAX(id) of the same id_release.
[-r id_release] Id_release of the script. Use this instead of release name and version.
[-h] Show this message.
$# dbrm dbm insert_script -f script1.sql -a 1 -r 10 -t update_script
Script script1.sql insert correctly.
TODO:
- use also long options for command arguments.
dbm insert_script_type
Insert a script type.
insert_script_type options:
-c CODE
: String used as code of the script type.
-d DESCRIPTION
: Description of the script type.
-h
: Show insert_script_type command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_script_type
[-c code] Script Type Code.
[-d description] Script Type Description
$# dbrm dbm insert_script_type -c regression_test -d 'Script used for check regression issue'
Script Type regression_test insert correctly.
TODO:
- use also long options for command arguments.
dbm insert_rel_dep
Insert a release dependency.
insert_rel_dep options:
-n NAME
: Name of the release where add a new dependency.
-t VERSION_TO
: Version of the release that has a dependency.
-f VERSION_FROM
: Version of the release that is needed for VERSION_TO.
-h
: Show insert_rel_dep command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_rel_dep -h
[-n name] Release Name.
[-t version_to] Release version that has a dependency.
[-f version_from] Release version needed.
$# dbrm dbm insert_rel_dep -n 'Project1' -t '0.1.1' -f '0.1.0'
Insert release dependency to Project1 v.0.1.1 correctly.
TODO:
- use also long options for command arguments.
dbm remove_rel_dep
Remove a release dependency.
remove_rel_dep options:
-n NAME
: Name of the release where remove dependency.
-t VERSION_TO
: Version of the release that has a dependency.
-f VERSION_FROM
: Version of the release that is needed for VERSION_TO.
-h
: Show remove_rel_dep command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm remove_rel_dep -h
[-n name] Release Name.
[-t version_to] Release version that has a dependency.
[-f version_from] Release version needed.
$# dbrm dbm remove_rel_dep -n 'Project1' -t '0.1.1' -f '0.1.0'
Remove release dependency to Project1 v.0.1.1 with 0.1.0 correctly.
TODO:
- use also long options for command arguments.
dbm insert_inhibit_script
Insert a release inhibited script.
insert_inhibit_script options:
-n NAME
: Name of the release where add an inhibited script between two version.
-i SCRIPT_ID
: Id of the script to inhibit.
-t VERSION_TO
: Version of the release target of the installation.
-f VERSION_FROM
: Version of the release source of the installation.
-h
: Show insert_inhibit_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_inhibit_script -h
[-n name] Release Name.
[-i id_script] Script Id.
[-t version_to] Release version target of the installation.
[-f version_from] Release version source of the installation.
$# dbrm dbm insert_inhibit_script -n 'Project1' -t '0.2.0' -f '0.1.0' -i 10
Record insert correctly.
TODO:
- use also long options for command arguments.
dbm insert_ded_script
Insert a release dedicated script.
insert_ded_script options:
-n NAME
: Name of the release where add an dedicated script between two version.
-i SCRIPT_ID
: Id of the script to insert.
-t VERSION_TO
: Version of the release target of the installation.
-f VERSION_FROM
: Version of the release source of the installation.
-h
: Show insert_ded_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_ded_script -h
[-n name] Release Name.
[-i id_script] Script Id.
[-t version_to] Release version target of the installation.
[-f version_from] Release version source of the installation.
$# dbrm dbm insert_ded_script -n 'Project1' -t '0.2.0' -f '0.1.0' -i 10
Record insert correctly.
TODO:
- use also long options for command arguments.
dbm remove_inhibit_script
Remove a release inhibited script.
remove_inhibit_script options:
-n NAME
: Name of the release where remove an inhibited script between two version.
-i SCRIPT_ID
: Id of the script to remove.
-t VERSION_TO
: Version of the release target of the installation.
-f VERSION_FROM
: Version of the release source of the installation.
-h
: Show remove_inhibit_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm remove_inhibit_script -h
[-n name] Release Name.
[-i id_script] Script Id.
[-t version_to] Release version target of the installation.
[-f version_from] Release version source of the installation.
$# dbrm dbm remove_ded_script -n 'Project1' -t '0.2.0' -f '0.1.0' -i 10
Record removed correctly.
TODO:
- use also long options for command arguments.
dbm remove_ded_script
Remove a release inhibited script.
remove_ded_script options:
-n NAME
: Name of the release where remove a dedicated script between two version.
-i SCRIPT_ID
: Id of the script to remove.
-t VERSION_TO
: Version of the release target of the installation.
-f VERSION_FROM
: Version of the release source of the installation.
-h
: Show remove_ded_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm remove_ded_script -h
[-n name] Release Name.
[-i id_script] Script Id.
[-t version_to] Release version target of the installation.
[-f version_from] Release version source of the installation.
$# dbrm dbm remove_dev_script -n 'Project1' -t '0.2.0' -f '0.1.0' -i 10
Record removed correctly.
TODO:
- use also long options for command arguments.
dbm show_branches
Show list of branches.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm show_branches
===============================================================================================================
ID CREATION_DATE UPDATE_DATE NAME
===============================================================================================================
1 2013-05-21 08:41:52 2013-05-21 08:41:52 master
2 2013-11-18 00:27:57 2013-11-18 00:27:57 0.1.x
dbm insert_branch
Insert a new branch.
insert_branch options:
-n NAME
: Name of the branch to insert.
-d YYYY-MM-DD
: Date of the branch (optional). Default valeu is now.
-h
: Show insert_branch command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm insert_branch
[-n name] Branch Name.
[-d YYYY-MM-DD] Branch Date. (Use now if not available)
$# dbrm dbm insert_branch -n 'master'
Branches master insert correctly.
TODO:
- use also long options for command arguments.
dbm move_script
Move a release script.
move_script options:
-i SCRIPT_ID
: Id of the script to move.
-a SCRIPT_ID_X
: Move script after script with id SCRIPT_ID_X.
-b SCRIPT_ID_X
: Move script before script with id SCRIPT_ID_X.
-r ID_RELEASE
: Release id of the script to move.
-h
: Show move_script command options.
Exit Values:
1
: On error.
0
: On success
$# dbrm dbm move_script -h
[-i id_script] Id script of the script to move.
[-a x] After script with id x.
[-b x] Before script with id x.
[-r id_release] Id Release of the script to move.
$# dbrm dbm move_script -i 10 -a 11 -r 1
Moved correctly script 10 of the release 1 after script 11.
TODO:
- use also long options for command arguments.
dbm upgrade
Upgrade DBRM database with last revision.
Exit Values:
1
: On error.
0
: On success
API
_dbm_init
Method called when module dbm is initialized.
Load all *.inc files of dbm module that contains help messages and command line parser of the dbm module commands.
Returns:
(Show/Hide)_dbm_init() {
# Load dbm module files
for i in $DBRM_CORE_FILES_DIR/dbm/*.inc ; do
. $i
done
return 0
}
_dbm_post_init
Internal function called after initialization of dbm module.
On this function is:
- check if exists internal sqlite database (DRM_DB variable) otherwise is created.
- check if it is defined DBM_UNDO_SCRIPT variable relative to undo commands.
If is not defined then $LOCAL_DIR/dbm_undo.sh script file is used.
- check if it is defined DBM_HISTORY variable relative to command history log.
If is not defined then $LOCAL_DIR/.dbm_history file is used.
(Show/Hide)_dbm_post_init () {
# Check if exists DRM_DB
[[ $DEBUG ]] && echo "(dbm_post_init: Check if is present sqlite internal db file: $DRM_DB)"
if [[ ! -e $DRM_DB ]] ; then
if [[ -z "$DRM_PROFILE" || $DRM_PROFILE -eq 0 ]] ; then
[[ $DEBUG ]] && echo "(dbm_post_init: Create sqlite internal db file: $DRM_DB)"
_sqlite_create -c "$DRM_DB" -s "$dbm_schema" || error_handled "Error on create $DRM_DB file."
_dbm_exts_check_extensions "0" || error_handled "Error on initialize extensions."
fi
else
if [[ x"$2" != x"upgrade" && x"$2" != x"shell" && x"$2" != x"info" ]] ; then
# Check if it is needed an upgrade
_dbm_exts_check_dbm || error_handled \
"Execute 'dbrm dbm upgrade' to upgrade internal database."
fi
fi
# Check if is defined undo script path
if [[ -z "$DBM_UNDO_SCRIPT" ]] ; then
# Use default path
DBM_UNDO_SCRIPT=$LOCAL_DIR/dbm_undo.sh
else
if [[ ! -e $DBM_UNDO_SCRIPT ]] ; then
error_generate "Invalid DBM Undo script path defined."
fi
fi
# Check if is defined history script path
if [[ -z "$DBM_HISTORY" ]] ; then
# Use default path
DBM_HISTORY=$LOCAL_DIR/.dbm_history
else
if [[ ! -e $DBM_HISTORY ]] ; then
error_generate "Invalid DBM history file path defined."
fi
fi
[[ $DEBUG ]] && echo "(dbm_post_init: Use undo script: $DBM_UNDO_SCRIPT.)"
export DBM_UNDO_SCRIPT DBM_HISTORY
}
_dbm_upgrade
Internal function called by upgrade command that upgrade and/or verify
DBRM database file.
(Show/Hide)_dbm_upgrade () {
local i=0
local tschema=""
# Check if all tables are present
for i in $dbm_tables ; do
if _sqlite_exists_table -c "$DRM_DB" -t "$i" ; then
_sqlite_get_tschema_from_file "$dbm_schema" "$i" || \
error_generate "Error on retrieve schema of the table $i."
query="$_sqlite_ans"
_sqlite_query -c "$DRM_DB" -q "$query" || \
error_handled "Error on create table $i."
out_handler_print "Created table $i correctly."
fi
done
# Check if all modules are present on Extensions table.
_dbm_exts_check_extensions || error_generate "Error on verify extentensions."
# Check if it is needed execute upgrade scripts for dbm module.
return 0
}
_dbm_how_many_profiles
Internal function that count number of configured profiles.
Return:
0
: on success. Store number profiles on _sqlite_ans variable.
1
: on error
(Show/Hide)_dbm_how_many_profiles () {
local query=""
_sqlite_query -c "$DRM_DB" -q "SELECT COUNT(1) AS P FROM Profiles" || return 1
return 0
}
_dbm_get_profile_by_name
Store on DRM_PROFILE_FILE
variable complete path of the configuration file of the
profile with name passed in input.
Check also if file exists.
Parameters:
Return:
0
: on success. Set DRM_PROFILE_FILE variable.
1
: on error
(Show/Hide)_dbm_get_profile_by_name () {
local query=""
local name="$1"
check_var "DRM_PROFILES_PATH" || \
error_handled \
"You must define DRM_PROFILES_PATH variable on configuration file"
query="
SELECT conf_file
FROM Profiles
WHERE profile_name = '$profile_name'"
_sqlite_query -c "$DRM_DB" -q "$query" || return 1
if [ x"$_sqlite_ans" == x"" ] ; then
return 1
fi
DRM_PROFILE_FILE="$DRM_PROFILES_PATH/$_sqlite_ans"
if [ ! -f $DRM_PROFILE_FILE ] ; then
error_generate "Profile file $DRM_PROFILE_FILE not found."
fi
export DRM_PROFILE_FILE
return 0
}
_dbm_get_default_profile_filepath
Store on DRM_PROFILE_FILE
variable complete path of the configuration
file of the active profile.
Check also if file exists.
Return:
0
: on success. Set DRM_PROFILE_FILE variable.
1
: on error
(Show/Hide)_dbm_get_default_profile_filepath () {
local query=""
check_var "DRM_PROFILES_PATH" || error_handled "You must define DRM_PROFILES_PATH variable on configuration file"
query="
SELECT conf_file
FROM Profiles
WHERE default_profile = 1
LIMIT 1"
_sqlite_query -c "$DRM_DB" -q "$query" || return 1
if [ x"$_sqlite_ans" == x"" ] ; then
return 1
fi
DRM_PROFILE_FILE="$DRM_PROFILES_PATH/$_sqlite_ans"
if [ ! -f $DRM_PROFILE_FILE ] ; then
error_generate "Profile file $DRM_PROFILE_FILE not found."
fi
export DRM_PROFILE_FILE
return 0
}
_dbm_check_if_exist_prof_byid
Check if exists a profile by Id.
Parameters:
$1
: id of the profile to check.
Return:
0
: profile exists.
1
: profile not exists.
(Show/Hide)_dbm_check_if_exist_prof_byid () {
local id_profile="$1"
local query="
SELECT COUNT(1)
FROM Profiles
WHERE id_profile = $id_profile"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Invalid id_profile $id_profile."
fi
return 0
}
_dbm_check_if_exist_prof_byname
Check if exists a profile by name.
Parameters:
$1
: Name of the profile to check.
Return:
0
: profile exists.
1
: profile not exists.
(Show/Hide)_dbm_check_if_exist_prof_byname () {
local profile_name="$1"
local query="
SELECT COUNT(1)
FROM Profiles
WHERE profile_name = '$profile_name'"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Invalid profile_name $profile_name."
fi
return 0
}
_dbm_check_if_exist_rel
Check if exists release by name and version.
Parameters:
$1
: Name of the release to check.
$2
: Version of the release to check
Return:
0
: release is present.
1
: release is not present.
(Show/Hide)_dbm_check_if_exist_rel () {
local rel_name="$1"
local rel_version="$2"
local query="SELECT COUNT(1) AS res FROM Releases WHERE name = '$rel_name' AND version = '$rel_version'"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Invalid version $rel_version."
fi
return 0
}
_dbm_retrieve_script_data
Retrieve script data.
If second parameter is valorized then are set these variables:
DBM_SCRIPT_ID
: Script Id
DBM_SCRIPT_FILENAME
: Script filename
DBM_SCRIPT_TYPE
: Script type string.
DBM_SCRIPT_ACTIVE
: Active flag
DBM_SCRIPT_DIR
: Directory of the script.
DBM_SCRIPT_ID_RELEASE
: Id of the release connected to script.
DBM_SCRIPT_ID_ORDER
: Id Order of the script.
DBM_SCRIPT_REL_NAME
: Release name connected to script.
DBM_SCRIPT_REL_VERSION
: Release version connected to script.
DBM_SCRIPT_ADAPTER
: adapter of the script.
Parameters:
$1
: Script Id
$2
: Set 1 or to a string with a len grether then 0 to set described variables.
Return:
(Show/Hide)_dbm_retrieve_script_data () {
local id_script="$1"
local set_variables="$2"
local query="
SELECT s.id_script,s.filename,s.type,
s.active,s.directory,s.id_release,
s.id_order,
r.name,
r.version,
r.db_adapter,
s.creation_date,s.update_date
FROM Scripts s, Releases r
WHERE id_script = $id_script
AND s.id_release = r.id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_generate "Unexpected error on retrieve data of the script $id_script"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Error on retrive data of the script $id_script."
fi
if [ ! -z "$set_variables" ] ; then
DBM_SCRIPT_ID=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[1]}'`
DBM_SCRIPT_FILENAME=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[2]}'`
DBM_SCRIPT_TYPE=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[3]}'`
DBM_SCRIPT_ACTIVE=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[4]}'`
DBM_SCRIPT_DIR=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[5]}'`
DBM_SCRIPT_ID_RELEASE=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[6]}'`
DBM_SCRIPT_ID_ORDER=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[7]}'`
DBM_SCRIPT_REL_NAME=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[8]}'`
DBM_SCRIPT_REL_VERSION=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[9]}'`
DBM_SCRIPT_ADAPTER=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[10]}'`
fi
return 0
}
_dbm_retrieve_first_release
Retrieve first release data by release/project name.
If release is present then are valorized these variables:
DBM_REL_ID_RELEASE
: Id of the release.
DBM_REL_VERSION
: Version of the release.
Parameters:
$1
: Name of the release/project.
Return:
(Show/Hide)_dbm_retrieve_first_release () {
local name="$1"
local query="
SELECT r.id_release,
r.version
FROM Releases r
WHERE r.name = '$name'
ORDER BY r.id_order
LIMIT 1
"
_sqlite_query -c "$DRM_DB" -q "$query" || \
error_generate "Unexpected error on retrieve first release for project $name"
if [ -z "$_sqlite_ans" ] ; then
error_generate "No release found for project $name"
fi
DBM_REL_ID_RELEASE=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[1]}'`
DBM_REL_VERSION=`echo $_sqlite_ans | awk '{split($0,a,"|"); print a[2]}'`
return 0
}
_dbm_check_if_exist_id_script
Check if exists a script by Id.
Parameters:
$1
: Id of the script
$2
: Id of the release (optional).
Return:
0
: script is present.
1
: script isn't present. (An exit 1 command is call if not present)
(Show/Hide)_dbm_check_if_exist_id_script () {
local id_script="$1"
local id_release="$2"
local query="SELECT COUNT(1) AS res FROM Scripts WHERE id_script = $id_script"
if [ -n "$id_release" ] ; then
query=$query" AND id_release = $id_release"
fi
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Invalid id_script $id_script."
fi
return 0
}
_dbm_check_if_exist_id_branch
Check if exists a branch with input id.
Parameters:
Return:
0
: branch is present
1
: branch isn't present. (An exit 1 command is call if not present)
(Show/Hide)_dbm_check_if_exist_id_branch () {
local id_branch="$1"
local query="SELECT COUNT(1) AS res FROM Branches WHERE id_branch = $id_branch"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Invalid id_branch $id_branch."
fi
return 0
}
_dbm_check_if_exist_id_rel
Check if exists a release with input id.
Parameters:
Return:
0
: release is present
1
: release isn't present. (An exit 1 command is call if not present)
(Show/Hide)_dbm_check_if_exist_id_rel () {
local id_release="$1"
local query="SELECT COUNT(1) AS res FROM Releases WHERE id_release = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" != x"1" ] ; then
error_generate "Invalid id_release $id_release."
fi
return 0
}
_dbm_retrieve_field_rel
Retrieve a list of fields related with a release (by name and version).
On success, data are available through _sqlite_ans
variable
Parameters:
$1
: a list of fields separeted by , to retrieve
$2
: name of the release
$3
: version of the release.
Return:
0
: on success
1
: on error. (An exit 1 command is call if no data are found)
(Show/Hide)_dbm_retrieve_field_rel () {
local field="$1"
local rel_name="$2"
local rel_version="$3"
local query="SELECT $field FROM Releases WHERE name = '$rel_name' AND version = '$rel_version'"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" == x"" ] ; then
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "Error on retrieve field $field for release $rel_name and version $rel_version\n"
error_generate "Invalid version $rel_version."
fi
return 0
}
_dbm_retrieve_field_rel_byid
Retrieve a list of fields related with a release (by id)
On success, data are available through _sqlite_ans
variable
Parameters:
$1
: a list of fields separeted by , to retrieve
$2
: id of the release
Return:
0
: on success
1
: on error. (An exit 1 command is call if no data are found)
(Show/Hide)_dbm_retrieve_field_rel_byid () {
local field="$1"
local id_release="$2"
local query="SELECT $field FROM Releases WHERE id_release = $id_release "
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" == x"" ] ; then
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "Error on retrieve field $field for release id $id_release.\n"
error_generate "Invalid version $id_release."
fi
return 0
}
_dbm_retrieve_field_script
Retrieve a list of fields related with a script (by id).
On success, data are available through _sqlite_ans
variable
Parameters:
$1
: a list of fields separeted by , to retrieve
$2
: id of the script
Return:
0
: on success
1
: on error. (An exit 1 command is call if no data are found)
(Show/Hide)_dbm_retrieve_field_script () {
local field="$1"
local id_script="$2"
local query="SELECT $field FROM Scripts WHERE id_script = $id_script"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" == x"" ] ; then
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "Error on retrieve field $field for script with id $id_script\n"
error_generate "Invalid id_script $id_script"
fi
return 0
}
_dbm_get_table_schema
Retrieve database schema of the input table of DBRM module.
Parameters:
Return:
0
: on success
1
: on error. (An exit 1 command is call on error).
(Show/Hide)_dbm_get_table_schema () {
local table="$1"
local query=".schema $table"
_sqlite_query -c "$DRM_DB" -t "$table" || error_handled ""
return 0
}
_dbm_remove_all_scripts_rel_inhib
Remove all inhibited scripts from a release.
Parameters:
Return:
0
: on success
1
: on error. (An exit 1 command is call on error).
(Show/Hide)_dbm_remove_all_scripts_rel_inhib () {
local id_release="$1"
local query=""
local id_script=""
local release_from=""
local release_to=""
local creation_date=""
local name=""
# Check if there are record
query="
SELECT COUNT(1) AS CNT
FROM ScriptRelInhibitions
WHERE id_release_from = $id_release
OR id_release_to = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ $_sqlite_ans -ne 0 ] ; then
query="
SELECT R.name,
SRI.id_script,
R.version AS rel_from,
R2.version AS rel_to
FROM ScriptRelInhibitions SRI,
Releases R,
Releases R2
WHERE R.id_release = SRI.id_release_from
AND R2.id_release = SRI.id_release_to
AND (
SRI.id_release_from = $id_release
OR SRI.id_release_to = $id_release
)"
# TODO permit to set creation_date on insert script_inhibition_rel record.
# SRI.creation_date
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
IFS=$'\n'
for row in $_sqlite_ans ; do
#[[ $DEBUG ]] && echo "ROW = ${row}"
name=`echo $row | awk '{split($0,a,"|"); print a[1]}'`
id_script=`echo $row | awk '{split($0,a,"|"); print a[2]}'`
release_from=`echo $row | awk '{split($0,a,"|"); print a[3]}'`
release_to=`echo $row | awk '{split($0,a,"|"); print a[4]}'`
_dbm_save2undo "dbrm dbm insert_inhibit_script -n \"$name\" -i $id_script -t $release_to -f $release_from "
done
unset IFS
# Create undo script for every record
query="
DELETE FROM ScriptRelInhibitions
WHERE id_release_from = $id_release
OR id_release_to = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" == x"" ] ; then
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "Error on field $field for release id $id_release.\n"
error_generate "Invalid version $id_release."
fi
fi
return 0
}
_dbm_remove_release
Remove a release
Parameters:
$1
: id of the release to remove
Return:
0
: on success
1
: on error. (An exit 1 command is call on error).
(Show/Hide)_dbm_remove_release () {
local id_release="$1"
local query=""
local name=""
local version=""
local release_date=""
local id_order=""
local db_adapter=""
local id_branch=""
local directory=""
# Retrieve release data
query="
SELECT name, version, release_date, id_order, db_adapter,
id_branch, directory
FROM Releases
WHERE id_release = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
IFS=$'\n'
for row in $_sqlite_ans ; do
#[[ $DEBUG ]] && echo "ROW = ${row}"
name=`echo $row | awk '{split($0,a,"|"); print a[1]}'`
version=`echo $row | awk '{split($0,a,"|"); print a[2]}'`
release_date=`echo $row | awk '{split($0,a,"|"); print a[3]}' | awk '{split($0,a," "); print a[1]}'`
id_order=`echo $row | awk '{split($0,a,"|"); print a[4]}'`
db_adapter=`echo $row | awk '{split($0,a,"|"); print a[5]}'`
id_branch=`echo $row | awk '{split($0,a,"|"); print a[6]}'`
directory=`echo $row | awk '{split($0,a,"|"); print a[7]}'`
_dbm_save2undo "dbrm dbm insert_release -n \"$name\" -d \"$release_date\" -v \"$version\" -a $db_adapter -b $id_branch --dir \"$directory\" "
done
unset IFS
query="DELETE FROM Releases WHERE id_release = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error on remove release $id_release!"
return 0
}
_dbm_update_idorder
Update id order of a list of release of the same branch.
Parameters:
Return:
0
: on success
1
: on error. (An exit 1 command is call on error).
(Show/Hide)_dbm_update_idorder () {
local id_branch="$1"
local idx=0
local id_release=""
local query="
SELECT id_release
FROM Releases
WHERE id_branch = $id_branch
ORDER BY id_order
"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error on retrieve list of id_release!"
declare -a list_id_rels
IFS=$'\n'
for row in $_sqlite_ans ; do
id_release=`echo $row | awk '{split($0,a,"|"); print a[1]}'`
list_id_rels[$idx]=$id_release
let idx++
done
unset IFS
# Update list of id
id_order=1
idx=0
for e in ${!list_id_rels[@]}
do
id_release=${list_id_rels[$e]}
query="
UPDATE Releases
SET id_order = $id_order
WHERE id_release = $id_release
"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error on update id_release $id_release"
let id_order++
done
unset list_id_rels
return 0
}
_dbm_remove_all_scripts_rel_ded
Remove all dedicated scripts from a release.
Parameters:
Return:
0
: on success
1
: on error. (An exit 1 command is call on error).
(Show/Hide)_dbm_remove_all_scripts_rel_ded () {
local id_release="$1"
local query=""
local id_script=""
local release_from=""
local release_to=""
local creation_date=""
local name=""
# Check if there are record
query="
SELECT COUNT(1) AS CNT
FROM ScriptRelDedicated
WHERE id_release_from = $id_release
OR id_release_to = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ $_sqlite_ans -ne 0 ] ; then
query="
SELECT R.name,
SRD.id_script,
R.version AS rel_from,
R2.version AS rel_to
FROM ScriptRelDedicated SRD,
Releases R,
Releases R2
WHERE R.id_release = SRD.id_release_from
AND R2.id_release = SRD.id_release_to
AND (
SRD.id_release_from = $id_release
OR SRD.id_release_to = $id_release
)"
# TODO permit to set creation_date on insert script_dedicated_rel record.
# SRI.creation_date
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
IFS=$'\n'
for row in $_sqlite_ans ; do
#[[ $DEBUG ]] && echo "ROW = ${row}"
name=`echo $row | awk '{split($0,a,"|"); print a[1]}'`
id_script=`echo $row | awk '{split($0,a,"|"); print a[2]}'`
release_from=`echo $row | awk '{split($0,a,"|"); print a[3]}'`
release_to=`echo $row | awk '{split($0,a,"|"); print a[4]}'`
_dbm_save2undo "dbrm dbm insert_ded_script -n \"$name\" -i $id_script -t $release_to -f $release_from "
done
unset IFS
# Create undo script for every record
query="
DELETE FROM ScriptRelDedicated
WHERE id_release_from = $id_release
OR id_release_to = $id_release"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled "Unexpected error!"
if [ x"$_sqlite_ans" == x"" ] ; then
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "Error on field $field for release id $id_release.\n"
error_generate "Invalid version $id_release."
fi
fi
return 0
}
_dbm_save2undo
Save input command to undo file.
Parameters:
Return:
0
: on success
1
: on error.
(Show/Hide)_dbm_save2undo () {
local msg="$1"
echo "$msg" >> $DBM_UNDO_SCRIPT
return $?
}
_dbm_save2history
Save input command to history file.
Parameters:
Return:
0
: on success
1
: on error.
(Show/Hide)_dbm_save2history () {
local msg="$1"
echo "$msg" >> $DBM_HISTORY
return $?
}
_dbm_exts_check_extensions
Check if all extensions/modules are present on table
Extensions. If not insert row with version.
If there a new version of a module call module upgrade function if is present.
Parameters:
$1
: string for enable quiet mode (optional).
Return:
0
: on success
1
: on error.
(Show/Hide)_dbm_exts_check_extensions () {
local ans=0
local v=""
local i=""
local quiet=${1:-0}
for i in $modules ; do
eval v=\$${i}_version
[[ x"${quiet}" != x"0" ]] && \
out_handler_print "Check if extension $i is present..."
_dbm_exts_is_present "$i"
if [ $? -eq 0 ] ; then
[[ x"${quiet}" != x"0" ]] && \
out_handler_print "Extension $i is already present."
# Check if version is equal to current extensions.
if [ "$v" != "${_ext_version}" ] ; then
[[ x"${quiet}" != x"0" ]] && \
out_handler_print "New version of $i module. I check for upgrade function."
if [ "$i" != "dbm" ] ; then
if type -t ${i}_upgrade > /dev/null ; then
${i}_upgrade "$v" || error_handled \
"(_dbm_exts_check_extensions): Error on upgrade extension $i."
fi
fi
_dbm_exts_update_extension "$i" "$v" || error_handled ""
fi
ans=0
else
# Install extension row.
[[ x"${quiet}" != x"0" ]] && \
out_handler_print "Extension $i is not present. I add it."
_dbm_exts_inst_extension "$i" "$v" || error_handled ""
fi
done
return $ans
}
_dbm_exts_is_present
Check if an extension is present on Extensions table.
Save extension version to _ext_version
variable.
Parameters:
$1
: Name of the extension.
Return:
0
: extension is present
1
: on error or if extension is not present.
(Show/Hide)_dbm_exts_is_present () {
local ext="$1"
query="
SELECT version
FROM Extensions
WHERE ext_name = '$ext'
"
_sqlite_query -c "$DRM_DB" -q "$query" || return 1
if [[ x"$_sqlite_ans" == x"\ " || x"$_sqlite_ans" == x"" ]] ; then
# Extension is not present.
return 1
fi
_ext_version="$_sqlite_ans"
return 0
}
_dbm_exts_inst_extension
Install a new extension in Extensions table.
Parameters:
$1
: Name of the extension.
$2
: Version of the extension.
Return:
0
: on success.
1
: on error.
(Show/Hide)_dbm_exts_inst_extension () {
local ename="$1"
local eversion="$2"
if [[ -z "$ename" || -z "$eversion" ]] ; then
return 1
fi
local query="
INSERT INTO Extensions
(ext_name,
version,
creation_date,
update_date)
VALUES (
'$ename',
'$eversion',
DATETIME('now'),
DATETIME('now')
);
"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled \
"(_dbm_exts_inst_extension): Error on insert extension $ename (version $eversion)."
return 0
}
_dbm_exts_update_extension
Update extension row in Extensions table.
Parameters:
$1
: Name of the extension.
$2
: Version of the extension.
Return:
0
: on success.
1
: on error.
(Show/Hide)_dbm_exts_update_extension () {
local ename="$1"
local eversion="$2"
if [[ -z "$ename" || -z "$eversion" ]] ; then
return 1
fi
local query="
UPDATE Extensions
SET version = '${eversion}',
update_date = DATETIME('now')
WHERE ext_name = '${ename}'
"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled \
"(_dbm_exts_inst_extension): Error on update extension $ename (version $eversion)."
return 0
}
_dbm_exts_update_extension
Update extension row in Extensions table.
Parameters:
$1
: Name of the extension.
$2
: Version of the extension.
Return:
0
: on success.
1
: on error.
(Show/Hide)_dbm_exts_update_extension () {
local ename="$1"
local eversion="$2"
if [[ -z "$ename" || -z "$eversion" ]] ; then
return 1
fi
local query="
UPDATE Extensions
SET version = '${eversion}',
update_date = DATETIME('now')
WHERE ext_name = '${ename}'
"
_sqlite_query -c "$DRM_DB" -q "$query" || error_handled \
"(_dbm_exts_inst_extension): Error on update extension $ename (version $eversion)."
return 0
}
_dbm_exts_check_dbm
Check if dbm module is upgraded.
Return:
0
: if dbm is updated.
1
: on error or an a dbrm dbm upgrade is needed
(Show/Hide)_dbm_exts_check_dbm () {
if _sqlite_exists_table -c "$DRM_DB" -t "Extensions" ; then
return 1
fi
_dbm_exts_is_present "dbm" || return 1
if [ "${dbm_version}" != "${_ext_version}" ] ; then
return 1
fi
return 0
}
_dbm_initenv_help
Print on stdout help message of command initenv
Return:
(Show/Hide)_dbm_initenv_help () {
echo -en "[--to-current-dir] Initialize current directory [.].\n"
echo -en "[--to-dir target] Initialize target directory.\n"
echo -en "[--enable-profiles] Enable profiles mode and create related directories.\n"
echo -en "[--help|-h] Show help message.\n"
echo -en "\n"
return 0
}
# dbm_dbm_initenv_help_end
# dbm__dbm_check_initenv_args
_dbm_check_initenv_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_initenv_args: $@)\n"
local short_options="h"
local long_options="to-dir: help to-current-dir enable-profiles"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) || \
error_handled "Invalid parameters"
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_initenv_args: Found $# params)\n"
if [ $# -le 0 ] ; then
_dbm_initenv_help
return 1
fi
DBM_INIT_CURRDIR=0
DBM_INIT_DIR=""
DBM_INIT_TARGETDIR=0
DBM_INIT_PROFILES=0
while [ $# -gt 0 ] ; do
case "$1" in
--to-current-dir)
DBM_INIT_CURRDIR=1
;;
--to-dir)
DBM_INIT_TARGETDIR=1
DBM_INIT_DIR="$2"
shift
;;
--enable-profiles)
DBM_INIT_PROFILES=1
;;
-h|--help)
_dbm_initenv_help
return 1
;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [[ $DBM_INIT_CURRDIR -eq 1 && $DBM_INIT_TARGETDIR -eq 1 ]] ; then
out_handler_print "Use only --to-dir or --to-current-dir option."
return 1
fi
if [[ $DBM_INIT_TARGETDIR -eq 1 ]] ; then
if [ ! -d $DBM_INIT_DIR ] ; then
out_handler_print "Invalid directory $DBM_INIT_DIR."
return 1
fi
else
# Set DBM_INIT_DIR to .
DBM_INIT_DIR=.
fi
return 0
}
#***
# dbm__dbm_ins_rel_help
_dbm_ins_rel_help () {
echo -en "[-n name] Release Name.\n"
echo -en "[-d YYYY-MM-DD] Release Date. (Use now if not available)\n"
echo -en "[-v version] Release Version\n"
echo -en "[-a adapter] Release Adapter (default is Oracle).\n"
echo -en "[-o id_order] Release Id Order (optional).\n"
echo -en "[-b id_branch] Release Id Branch (default master branch {1}).\n"
echo -en "[-dir directory] Release directory (default is [.]).\n"
echo -en "\n"
return 0
}
# dbm__dbm_ins_rel_help_end
# dbm__dbm_check_ins_rel_args
_dbm_check_ins_rel_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_rel_args args: $@)\n"
local short_options="n:d:v:o:a:b:h"
local long_options="dir:"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_ins_rel_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_rel_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-n) DBM_REL_NAME="$2" ;shift;;
-d) DBM_REL_DATE="$2" ;shift;;
-v) DBM_REL_VERSION="$2" ;shift;;
-o) DBM_REL_ORDER="$2" ;shift;;
-a) DBM_REL_ADAPTER="$2" ;shift;;
-b) DBM_REL_BRANCH="$2" ;shift;;
--dir)
DBM_REL_DIR="$2"
shift
;;
-h)
_dbm_ins_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_REL_NAME" ] ; then
echo "Missing Release Name"
return 1
fi
if [ -z "$DBM_REL_DATE" ] ; then
DBM_REL_DATE="DATETIME('now')"
else
DBM_REL_DATE="'$DBM_REL_DATE'"
fi
if [ -z "$DBM_REL_ADAPTER" ] ; then
DBM_REL_ADAPTER="oracle";
fi
if [ -z "$DBM_REL_DIR" ] ; then
DBM_REL_DIR="."
fi
if [ -z "$DBM_REL_VERSION" ] ; then
echo "Missing Release Verion"
return 1
fi
return 0
}
# dbm__dbm_check_ins_rel_args_end
# dbm__dbm_add_prof_help
_dbm_add_prof_help () {
echo -en "[--name name] Profile name to insert.\n"
echo -en "[--file file] Filename of the profile. Example: prof1.conf.\n"
echo -en "[--default] Set new profile as default.\n"
echo -en "[-h] Show this help message.\n"
return 0
}
# dbm__dbm_add_prof_help_end
# dbm__dbm_prof_help
_dbm_prof_help () {
echo -en "[--name profile_name] Name of the profile.\n"
echo -en "[--id id_profile] Id of the profile.\n"
echo -en "[-h] Show this help message.\n"
return 0
}
# dbm__dbm_prof_help_end
# dbm__dbm_check_prof_args
_dbm_check_prof_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_del_prof_args args: $@)\n"
local short_options="h"
local long_options="id: name:"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) \
|| error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_prof_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_del_prof_args: Found $# params)\n"
DBM_PROFILE_BYNAME=0
DBM_PROFILE_BYID=0
while [ $# -gt 0 ] ; do
case "$1" in
--name)
DBM_PROFILE_NAME="$2"
DBM_PROFILE_BYNAME=1
shift
;;
--id)
DBM_PROFILE_ID="$2"
DBM_PROFILE_BYID=1
shift
;;
-h)
_dbm_prof_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [[ $DBM_PROFILE_BYID -eq 0 && $DBM_PROFILE_BYNAME -eq 0 ]] ; then
echo "A profile name or profile id is needed."
return 1
fi
if [[ $DBM_PROFILE_BYID -eq 1 && $DBM_PROFILE_BYNAME -eq 1 ]] ; then
echo "Set only profile id or only profile name."
return 1
fi
return 0
}
# dbm__dbm_check_prof_args_end
# dbm__dbm_check_add_prof_args
_dbm_check_add_prof_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_add_prof_args args: $@)\n"
local short_options="h"
local long_options="default name: file:"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_add_prof_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_add_prof_args: Found $# params)\n"
DBM_PROFILE_DEFAULT=0
while [ $# -gt 0 ] ; do
case "$1" in
--name) DBM_PROFILE_NAME="$2"
shift
;;
--file)
DBM_PROFILE_FILENAME="$2"
shift
;;
--default)
DBM_PROFILE_DEFAULT=1
;;
-h)
_dbm_add_prof_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_PROFILE_NAME" ] ; then
echo "Missing Profile Name"
return 1
fi
if [ -z "$DBM_PROFILE_FILENAME" ] ; then
echo "Missing Profile filename."
return 1
fi
return 0
}
# dbm__dbm_check_add_prof_args_end
# dbm__dbm_check_ins_bra_args
_dbm_check_ins_bra_args () {
local ans=0
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_bra_args args: $@)\n"
help_msg() {
echo -en "[-n name] Branch Name.\n"
echo -en "[-d YYYY-MM-DD] Branch Date. (Use now if not available)\n"
}
# Reinitialize opt index position
OPTIND=1
while getopts "n:d:v:o:a:b:h" opts "$@" ; do
case $opts in
n) DBM_BRA_NAME="$OPTARG";;
d) DBM_BRA_DATE="$OPTARG";;
h)
help_msg
return 1
;;
esac
done
if [ -z "$DBM_BRA_NAME" ] ; then
help_msg
ans=1
else
if [ -z "$DBM_BRA_DATE" ] ; then
DBM_BRA_DATE="DATETIME('now')"
else
DBM_BRA_DATE="'$DBM_REL_DATE'"
fi
fi
unset -f help_msg
return $ans
}
# dbm__dbm_check_ins_bra_args_end
# dbm__dbm_check_ins_script_type_args
_dbm_check_ins_script_type_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_script_type_args args: $@)\n"
_dbm_ins_script_type_help () {
echo -en "[-c code] Script Type Code.\n"
echo -en "[-d description] Script Type Description\n"
return 0
}
# Reinitialize opt index position
OPTIND=1
while getopts "c:d:h" opts "$@" ; do
case $opts in
c) DBM_SCRIPT_TYPE_CODE="$OPTARG";;
d) DBM_SCRIPT_TYPE_DESCR="$OPTARG";;
h)
_dbm_ins_script_type_help
return 1
;;
esac
done
if [[ -z "$DBM_SCRIPT_TYPE_CODE" && -z "$DBM_SCRIPT_TYPE_DESCR" ]] ; then
_dbm_ins_script_type_help
return 1
fi
if [ -z "$DBM_SCRIPT_TYPE_CODE" ] ; then
echo "Missing Script Type Code."
return 1
fi
if [ -z "$DBM_SCRIPT_TYPE_DESCR" ] ; then
echo "Missing Script Type Descr"
return 1
fi
unset -f _dbm_ins_script_type_help
return 0
}
# dbm__dbm_check_ins_script_type_args_end
# dbm__dbm_check_ins_script_args
_dbm_check_ins_script_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_script_args args: $@)\n"
_dbm_ins_script_help () {
echo -en "[-f filename] Script filename.\n"
echo -en "[-n name] Release Name.\n"
echo -en "[-v version] Release Version\n"
echo -en "[-t script_type] Script Type.\n"
echo -en "[-a 0|1] Set active flag. Default is 1 (active)\n"
echo -en "[-d directory] Directory of the script.\n"
echo -en "[-o id_order] Script Id Order (optional). Default is used MAX(id) of the same id_release.\n"
echo -en "[-r id_release] Id_release of the script. Use this instead of release name and version.\n"
echo -en "[-h] Show this message.\n"
return 0
}
local short_options="f:t:a:d:hr:n:v:o:"
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_ins_script_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_script_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-f) DBM_SCRIPT_FILENAME="$2";shift;;
-t) DBM_SCRIPT_TYPE="$2";shift;;
-a) DBM_SCRIPT_ACTIVE="$2";shift;;
-d) DBM_SCRIPT_DIRECTORY="$2";shift;;
-r) DBM_SCRIPT_ID_RELEASE="$2";shift;;
-n) DBM_SCRIPT_REL_NAME="$2";shift;;
-v) DBM_SCRIPT_REL_VERSION="$2";shift;;
-o) DBM_SCRIPT_ID_ORDER="$2";shift;;
-h)
_dbm_ins_script_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_SCRIPT_FILENAME" ] ; then
echo "Missing Script Filename"
return 1
fi
if [ -z "$DBM_SCRIPT_TYPE" ] ; then
echo "Missing Script Type"
return 1
fi
if [ -z "$DBM_SCRIPT_ID_RELEASE" ] ; then
if [[ -z "$DBM_SCRIPT_REL_VERSION" || -z "$DBM_SCRIPT_REL_NAME" ]] ; then
echo "Missing Release Version or Release Name or Id Release."
return 1
fi
fi
if [ -z "$DBM_SCRIPT_DIRECTORY" ] ; then
echo "Missing Script Directory."
return 1
fi
if [ -z "$DBM_SCRIPT_ACTIVE" ] ; then
DBM_SCRIPT_ACTIVE="1"
else
if [[ x"$DBM_SCRIPT_ACTIVE" != x"1" && x"$DBM_SCRIPT_ACTIVE" != x"0" ]] ; then
DBM_SCRIPT_ACTIVE="1"
fi
fi
unset -f _dbm_ins_script_help
return 0
}
# dbm__dbm_check_ins_script_args_end
# dbm__dbm_check_rel_dep_args
_dbm_check_rel_dep_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_rel_dep_args args: $@)\n"
# Reinitialize opt index position
OPTIND=1
while getopts "n:t:f:h" opts "$@" ; do
case $opts in
n) DBM_REL_NAME="$OPTARG";;
t) DBM_REL_VERSION_TO="$OPTARG";;
f) DBM_REL_VERSION_FROM="$OPTARG";;
h)
echo -en "[-n name] Release Name.\n"
echo -en "[-t version_to] Release version that has a dependency.\n"
echo -en "[-f version_from] Release version needed.\n"
return 1
;;
esac
done
if [ -z "$DBM_REL_NAME" ] ; then
echo "Missing Release Name."
return 1
fi
if [ -z "$DBM_REL_VERSION_TO" ] ; then
echo "Missing Release version that has a dependency."
return 1
fi
if [ -z "$DBM_REL_VERSION_FROM" ] ; then
echo "Missing Release version needed on target."
return 1
fi
if [ "$DBM_REL_VERSION_FROM" == "$DBM_REL_VERSION_TO" ] ; then
echo "Both version are equal. Error."
return 1
fi
return 0
}
# dbm__dbm_check_rel_dep_args_end
# dbm__dbm_check_upd_script_args
_dbm_check_upd_script_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_upd_script_args args: $@)\n"
_dbm_check_upd_script_help () {
echo -en "[-i id_script] Id Script.\n"
echo -en "[-f filename] Script filename.\n"
echo -en "[-n name] Release Name.\n"
echo -en "[-v version] Release Version\n"
echo -en "[-t script_type] Script Type.\n"
echo -en "[-a 0|1] Set active flag.\n"
echo -en "[-d directory] Directory of the script.\n"
echo -en "[-o id_order] Script Id Order (optional). Default is used MAX(id) of the same id_release.\n"
echo -en "[-r id_release] Id_release of the script. Use this instead of release name and version.\n"
}
# Reinitialize opt index position
OPTIND=1
while getopts "i:f:t:a:d:hr:n:v:o:" opts "$@" ; do
case $opts in
i) DBM_SCRIPT_ID="$OPTARG";;
f) DBM_SCRIPT_FILENAME="$OPTARG";;
t) DBM_SCRIPT_TYPE="$OPTARG";;
a) DBM_SCRIPT_ACTIVE="$OPTARG";;
d) DBM_SCRIPT_DIRECTORY="$OPTARG";;
r) DBM_SCRIPT_ID_RELEASE="$OPTARG";;
n) DBM_SCRIPT_REL_NAME="$OPTARG";;
v) DBM_SCRIPT_REL_VERSION="$OPTARG";;
o) DBM_SCRIPT_ID_ORDER="$OPTARG";;
h)
_dbm_check_upd_script_help
return 1
;;
esac
done
if [ -z "$DBM_SCRIPT_ID" ] ; then
echo "Missing Script Id."
return 1
fi
if [ ! -z "$DBM_SCRIPT_ACTIVE" ] ; then
if [[ x"$DBM_SCRIPT_ACTIVE" != x"1" && x"$DBM_SCRIPT_ACTIVE" != x"0" ]] ; then
DBM_SCRIPT_ACTIVE="1"
fi
fi
unset -f _dbm_check_upd_script_help
return 0
}
# dbm__dbm_check_upd_script_args_end
# dbm__dbm_check_rm_script_args
_dbm_check_rm_script_args () {
local show_help=false
_dbm_rm_script_help () {
echo -en "[-i id_script] Id Script of the script to remove.\n"
}
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_rm_script_args args: $@)\n"
local short_options="i:h"
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_rm_script_help
unset -f _dbm_rm_script_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_rm_script_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-i) DBM_SCRIPT_ID="$2";shift;;
-h)
show_help=true
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ $show_help == true ] ; then
_dbm_rm_script_help
ans = 1
else
ans = 0
if [ -z "$DBM_SCRIPT_ID" ] ; then
echo "Missing Script Id."
ans = 1
fi
fi
unset -f _dbm_rm_script_help
return $ans
}
# dbm__dbm_check_rm_script_args_end
# dbm__dbm_check_upd_release_args
_dbm_check_upd_release_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_upd_release_args: $@)\n"
_dbm_upd_release_help () {
echo -en "[-n name] Release Name.\n"
echo -en "[-d YYYY-MM-DD] Release Date.\n"
echo -en "[-v version] Release Version\n"
echo -en "[-a adapter] Release Adapter.\n"
echo -en "[-b id_branch] Id Branch.\n"
echo -en "[-i id_release] Id Release to update.\n"
echo -en "[--dir directory] Directory to update.\n"
echo -en "\n"
}
DBM_REL_NAME_UPD=0
DBM_REL_DATE_UPD=0
DBM_REL_VERSION_UPD=0
DBM_REL_ADAPTER_UPD=0
DBM_REL_BRANCH_UPD=0
DBM_REL_DIR_UPD=0
local short_options="b:n:d:a:v:i:h"
local long_options="dir:"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_upd_release_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_upd_release_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case $1 in
-n)
DBM_REL_NAME="$2"
DBM_REL_NAME_UPD=1
shift
;;
-d)
DBM_REL_DATE="$2"
DBM_REL_DATE_UPD=1
shift
;;
-v)
DBM_REL_VERSION="$2"
DBM_REL_VERSION_UPD=1
shift
;;
-a)
DBM_REL_ADAPTER="$2"
DBM_REL_ADAPTER_UPD=1
shift
;;
-b)
DBM_REL_BRANCH="$2"
DBM_REL_BRANCH_UPD=1
shift
;;
-i)
DBM_REL_ID="$2"
shift
;;
-h)
_dbm_upd_release_help
return 1
;;
--)
DBM_REL_DIR="$2"
DBM_REL_DIR_UPD=1
shift
;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
if [[ $DBM_REL_NAME_UPD -eq 0 && $DBM_REL_DATE_UPD -eq 0 &&
$DBM_REL_VERSION_UPD -eq 0 && $DBM_REL_ADAPTER_UPD -eq 0 &&
$DBM_REL_BRANCH_UPD -eq 0 && $DBM_REL_DIR_UPD -eq 0 ]] ; then
echo -en "No fields to update.\n"
return 1
fi
unset -f _dbm_upd_release_help
return 0
}
# dbm__dbm_check_upd_release_args_end
# dbm__dbm_check_move_release_args
_dbm_check_move_release_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_inhibit_script_args args: $@)\n"
_dbm_mv_release_help () {
echo -en "[-r version] Release version.\n"
echo -en "[-n name] Release Name.\n"
echo -en "[-a version_to] After release version_to.\n"
echo -en "[-b version_to] Before release version_to.\n"
echo -en "\n"
echo -en "Example: -n 'Project1' -r '0.1.1' -a '0.1.0' (Release 0.1.1 after release 0.1.0)\n"
}
DBM_BEFORE=0
DBM_AFTER=0
# Reinitialize opt index position
OPTIND=1
while getopts "b:n:a:r:h" opts "$@" ; do
case $opts in
n) DBM_REL_NAME="$OPTARG";;
b) DBM_BEFORE=1
DBM_REL_VERSION_TO="$OPTARG";;
a) DBM_AFTER=1
DBM_REL_VERSION_TO="$OPTARG";;
r) DBM_REL_VERSION_FROM="$OPTARG";;
h)
_dbm_mv_release_help
return 1
;;
esac
done
if [ -z "$DBM_REL_NAME" ] ; then
_dbm_mv_release_help
#echo "Missing Release Name."
return 1
fi
if [ -z "$DBM_REL_VERSION_FROM" ] ; then
echo "Missing Release version."
return 1
fi
if [[ $DBM_BEFORE == 1 && $DBM_AFTER == 1 ]] ; then
echo "Both after and before are used. Error."
return 1
fi
if [[ $DBM_BEFORE == 0 && $DBM_AFTER == 0 ]] ; then
echo "Missing -a or -b parameter."
return 1
fi
unset -f _dbm_mv_release_help
return 0
}
# dbm__dbm_check_move_release_args_end
# dbm__dbm_check_inhibit_script_args
_dbm_check_inhibit_script_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_inhibit_script_args args: $@)\n"
# Reinitialize opt index position
OPTIND=1
while getopts "i:n:t:f:h" opts "$@" ; do
case $opts in
i) DBM_SCRIPT_ID="$OPTARG";;
n) DBM_REL_NAME="$OPTARG";;
t) DBM_REL_VERSION_TO="$OPTARG";;
f) DBM_REL_VERSION_FROM="$OPTARG";;
h)
echo -en "[-n name] Release Name.\n"
echo -en "[-i id_script] Script Id.\n"
echo -en "[-t version_to] Release version target of the installation.\n"
echo -en "[-f version_from] Release version source of the installation.\n"
return 1
;;
esac
done
if [ -z "$DBM_SCRIPT_ID" ] ; then
echo "Missing Script Id."
return 1
fi
if [ -z "$DBM_REL_NAME" ] ; then
echo "Missing Release Name."
return 1
fi
if [ -z "$DBM_REL_VERSION_TO" ] ; then
echo "Missing Release version that has a dependency."
return 1
fi
if [ -z "$DBM_REL_VERSION_FROM" ] ; then
echo "Missing Release version needed on target."
return 1
fi
if [ "$DBM_REL_VERSION_FROM" == "$DBM_REL_VERSION_TO" ] ; then
echo "Both version are equal. Error."
return 1
fi
return 0
}
# dbm__dbm_check_inhibit_script_args_end
# dbm__dbm_check_move_script_args
_dbm_check_move_script_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_move_script_args: $@)\n"
_dbm_move_script_help () {
echo -en "[-i id_script] Id script of the script to move.\n"
echo -en "[-a x] After script with id x.\n"
echo -en "[-b x] Before script with id x.\n"
echo -en "[-r id_release] Id Release of the script to move.\n"
}
DBM_BEFORE=0
DBM_AFTER=0
# Reinitialize opt index position
OPTIND=1
while getopts "b:i:a:r:h" opts "$@" ; do
case $opts in
r) DBM_REL_ID="$OPTARG";;
b) DBM_BEFORE=1
DBM_SCRIPT_ID_TO="$OPTARG";;
a) DBM_AFTER=1
DBM_SCRIPT_ID_TO="$OPTARG";;
i) DBM_SCRIPT_ID_FROM="$OPTARG";;
h)
_dbm_move_script_help
return 1
;;
esac
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
if [ -z "$DBM_SCRIPT_ID_FROM" ] ; then
echo "Missing Script Id."
return 1
fi
if [[ $DBM_BEFORE == 1 && $DBM_AFTER == 1 ]] ; then
echo "Both after and before are used. Error."
return 1
fi
if [[ $DBM_BEFORE == 0 && $DBM_AFTER == 0 ]] ; then
echo "Missing -a or -b parameter."
return 1
fi
unset -f _dbm_move_script_help
return 0
}
# dbm__dbm_check_move_script_args_end
# dbm__dbm_check_rem_rel_args
_dbm_check_rem_rel_args () {
local short_options="r:hf"
[[ $DEBUG ]] && echo -en "(_dbm_check_rem_rel_args args: $@)\n"
_dbm_rem_rel_help () {
echo -en "[-r id_release] Id Release of the script to remove.\n"
echo -en "[-f] Force remove without confirmation question.\n"
}
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || \
error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_rem_rel_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_rem_rel_args: Found $# params)\n"
DBM_FORCE_RM=0
while [ $# -gt 0 ] ; do
case "$1" in
-r) DBM_REL_ID="$2" ;shift;;
-f) DBM_FORCE_RM="1" ;;
-h)
_dbm_rem_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
unset -f _dbm_rem_rel_help
return 0
}
# dbm__dbm_check_rem_rel_args_end
# dbm__dbm_show_rel_args
_dbm_show_rel_args () {
local short_options="b:h"
[[ $DEBUG ]] && echo -en "(_dbm_check_show_rel_args args: $@)\n"
_dbm_show_rel_help () {
echo -en "[-b id_branch] Id branch to filter.\n"
}
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || \
error_handled "Invalid parameters"
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_show_rel_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-b) DBM_BRANCH_ID="$2" ;shift;;
-h)
_dbm_show_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
unset -f _dbm_show_rel_help
return 0
}
# dbm__dbm_show_rel_args_end
# vim: syn=sh filetype=sh
_dbm_check_initenv_args
Internal function for parse command line arguments related to
initenv
command.
Command Arguments:
--to-current-dir
: Initialize current directory.
--to-dir target
: Initialize target directory.
--enable-profiles
: Enable profiles mode.
--help|-h
: Show help message.
Variables Used:
DBM_INIT_CURRDIR
: Set to 1 if --to-current-dir option is used. Default is 0.
DBM_INIT_DIR
: Set with target directory of the --to-dir option.
DBM_INIT_TARGETDIR
: Set to 1 if --to-dir option is used. Default is 0.
DBM_INIT_PROFILES
: Set to 1 if --enable-profiles is present. Default is 0.
Return:
0
: on success
1
: on error
(Show/Hide)
_dbm_ins_rel_help
Print on stdout help message of command insert_releas
.
Return:
(Show/Hide)_dbm_ins_rel_help () {
echo -en "[-n name] Release Name.\n"
echo -en "[-d YYYY-MM-DD] Release Date. (Use now if not available)\n"
echo -en "[-v version] Release Version\n"
echo -en "[-a adapter] Release Adapter (default is Oracle).\n"
echo -en "[-o id_order] Release Id Order (optional).\n"
echo -en "[-b id_branch] Release Id Branch (default master branch {1}).\n"
echo -en "[-dir directory] Release directory (default is [.]).\n"
echo -en "\n"
return 0
}
_dbm_check_ins_rel_args
Internal function for parse command line arguments related to
insert_release
command.
Command Arguments:
-n RELEASE_NAME
: Name of the release to add.
-d YYYY-MM-DD
: Release date of the release to add.
-v VERSION
: Version of the release to add.
-a ADAPTER
: Adapter used by the release to add (default is oracle).
-o ID_ORDER
: Id order of the release to add.
-b BRANCH_ID
: Id of the branch connected to release to add.
-dir DIRECTORY
: Directory of the release to add.
-h
: Show insert_release command options.
Variables Used:
DBM_REL_NAME
: Release name
DBM_REL_DATE
: Release date
DBM_REL_VERSION
: Release version
DBM_REL_ORDER
: Release order id.
DBM_REL_ADAPTER
: Release adapter
DBM_REL_BRANCH
: Release branch id.
DBM_REL_DIR
: Release directory.
Return:
0
: on success
1
: on error
(Show/Hide)
_dbm_add_prof_help
Print on stdout help message of add_profile
command.
Return:
(Show/Hide)_dbm_add_prof_help () {
echo -en "[--name name] Profile name to insert.\n"
echo -en "[--file file] Filename of the profile. Example: prof1.conf.\n"
echo -en "[--default] Set new profile as default.\n"
echo -en "[-h] Show this help message.\n"
return 0
}
_dbm_prof_help
Print on stdout help message of del_profile
/set_profile
command.
Return:
(Show/Hide)_dbm_prof_help () {
echo -en "[--name profile_name] Name of the profile.\n"
echo -en "[--id id_profile] Id of the profile.\n"
echo -en "[-h] Show this help message.\n"
return 0
}
_dbm_check_prof_args
Internal function for parse command line arguments related to
del_profile
and set_profile
command.
Command Arguments:
--name NAME
: Name of the profile.
--id ID_PROFILE
: Id of the profile
-h
: Show command options.
Variables Used:
DBM_PROFILE_BYNAME
: Set to 1 if is set profile id. Default value is 0.
DBM_PROFILE_BYID
: Set to 1 if is set profile name. Default value is 0.
DBM_PROFILE_NAME
: Name of the profile.
DBM_PROFILE_ID
: Id of the profile.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_prof_help () {
echo -en "[--name profile_name] Name of the profile.\n"
echo -en "[--id id_profile] Id of the profile.\n"
echo -en "[-h] Show this help message.\n"
return 0
}
_dbm_check_add_prof_args
Internal function for parse command line arguments related to add_profile
command.
Command Arguments:
--name NAME
: Name of the profile
--file FILE
: Profile filename
--default
: Set new profile as default/active.
-h
: Show command options.
Variables Used:
DBM_PROFILE_DEFAULT
: Set new profile as default (value 1) or not (value 0).
Default value is 0.
DBM_PROFILE_FILENAME
: Filename of the profile.
DBM_PROFILE_NAME
: Name of the profile.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_add_prof_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_add_prof_args args: $@)\n"
local short_options="h"
local long_options="default name: file:"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_add_prof_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_add_prof_args: Found $# params)\n"
DBM_PROFILE_DEFAULT=0
while [ $# -gt 0 ] ; do
case "$1" in
--name) DBM_PROFILE_NAME="$2"
shift
;;
--file)
DBM_PROFILE_FILENAME="$2"
shift
;;
--default)
DBM_PROFILE_DEFAULT=1
;;
-h)
_dbm_add_prof_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_PROFILE_NAME" ] ; then
echo "Missing Profile Name"
return 1
fi
if [ -z "$DBM_PROFILE_FILENAME" ] ; then
echo "Missing Profile filename."
return 1
fi
return 0
}
_dbm_check_ins_bra_args
Internal function for parse command line arguments related to insert_branch
command.
Command Arguments:
-n NAME
: Name of the branch to insert.
-d YYYY-MM-DD
: Date of the branch (optional). Default valeu is now.
-h
: Show command options.
Variables Used:
DBM_BRA_NAME
: Name of the branch.
DBM_BRA_DATE
: Date of the branch.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_ins_bra_args () {
local ans=0
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_bra_args args: $@)\n"
help_msg() {
echo -en "[-n name] Branch Name.\n"
echo -en "[-d YYYY-MM-DD] Branch Date. (Use now if not available)\n"
}
# Reinitialize opt index position
OPTIND=1
while getopts "n:d:v:o:a:b:h" opts "$@" ; do
case $opts in
n) DBM_BRA_NAME="$OPTARG";;
d) DBM_BRA_DATE="$OPTARG";;
h)
help_msg
return 1
;;
esac
done
if [ -z "$DBM_BRA_NAME" ] ; then
help_msg
ans=1
else
if [ -z "$DBM_BRA_DATE" ] ; then
DBM_BRA_DATE="DATETIME('now')"
else
DBM_BRA_DATE="'$DBM_REL_DATE'"
fi
fi
unset -f help_msg
return $ans
}
_dbm_check_ins_script_type_args
Internal function for parse command line arguments related to insert_script_type
command.
Command Arguments:
-c CODE
: String used as code of the script type.
-d DESCRIPTION
: Description of the script type.
-h
: Show command options.
Variables Used:
DBM_SCRIPT_TYPE_CODE
: Code of the script type.
DBM_SCRIPT_TYPE_DESCR
: Description of the script type.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_ins_script_type_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_script_type_args args: $@)\n"
_dbm_ins_script_type_help () {
echo -en "[-c code] Script Type Code.\n"
echo -en "[-d description] Script Type Description\n"
return 0
}
# Reinitialize opt index position
OPTIND=1
while getopts "c:d:h" opts "$@" ; do
case $opts in
c) DBM_SCRIPT_TYPE_CODE="$OPTARG";;
d) DBM_SCRIPT_TYPE_DESCR="$OPTARG";;
h)
_dbm_ins_script_type_help
return 1
;;
esac
done
if [[ -z "$DBM_SCRIPT_TYPE_CODE" && -z "$DBM_SCRIPT_TYPE_DESCR" ]] ; then
_dbm_ins_script_type_help
return 1
fi
if [ -z "$DBM_SCRIPT_TYPE_CODE" ] ; then
echo "Missing Script Type Code."
return 1
fi
if [ -z "$DBM_SCRIPT_TYPE_DESCR" ] ; then
echo "Missing Script Type Descr"
return 1
fi
unset -f _dbm_ins_script_type_help
return 0
}
_dbm_check_ins_script_args
Internal function for parse command line arguments related to insert_script
command.
Command Arguments:
-f FILENAME
: Script filename.
-n NAME
: Name of the release of the script to insert.
-v VERSION
: Version of the release of the script to insert.
-t STYPE
: Type of the script to insert.
-a FLAG
: Set active (1) or disable (0) flag of the script.
-d DIRECTORY
: Directory of the script to insert.
-o ID_ORDER
: Id order of the script to update (optional).
Default is used MAX(id) of the same id_release.
-r RELEASE_ID
: Id of the release of the script.
If this option is present are not needed release name and release version.
-h
: Show command options.
Variables Used:
DBM_SCRIPT_TYPE
: Code of the script type.
DBM_SCRIPT_FILENAME
: Name of the script file.
DBM_SCRIPT_ACTIVE
: Script status: active (1) or disable (0).
DBM_SCRIPT_DIRECTORY
: Directory of the script. Relative path from LOCAL_DIR
.
DBM_SCRIPT_ID_RELEASE
: Id of the release related with script.
DBM_SCRIPT_REL_NAME
: Release name.
DBM_SCRIPT_REL_VERSION
: Release version.
DBM_SCRIPT_ID_ORDER
: Id order of the release script.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_ins_script_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_script_args args: $@)\n"
_dbm_ins_script_help () {
echo -en "[-f filename] Script filename.\n"
echo -en "[-n name] Release Name.\n"
echo -en "[-v version] Release Version\n"
echo -en "[-t script_type] Script Type.\n"
echo -en "[-a 0|1] Set active flag. Default is 1 (active)\n"
echo -en "[-d directory] Directory of the script.\n"
echo -en "[-o id_order] Script Id Order (optional). Default is used MAX(id) of the same id_release.\n"
echo -en "[-r id_release] Id_release of the script. Use this instead of release name and version.\n"
echo -en "[-h] Show this message.\n"
return 0
}
local short_options="f:t:a:d:hr:n:v:o:"
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_ins_script_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_script_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-f) DBM_SCRIPT_FILENAME="$2";shift;;
-t) DBM_SCRIPT_TYPE="$2";shift;;
-a) DBM_SCRIPT_ACTIVE="$2";shift;;
-d) DBM_SCRIPT_DIRECTORY="$2";shift;;
-r) DBM_SCRIPT_ID_RELEASE="$2";shift;;
-n) DBM_SCRIPT_REL_NAME="$2";shift;;
-v) DBM_SCRIPT_REL_VERSION="$2";shift;;
-o) DBM_SCRIPT_ID_ORDER="$2";shift;;
-h)
_dbm_ins_script_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_SCRIPT_FILENAME" ] ; then
echo "Missing Script Filename"
return 1
fi
if [ -z "$DBM_SCRIPT_TYPE" ] ; then
echo "Missing Script Type"
return 1
fi
if [ -z "$DBM_SCRIPT_ID_RELEASE" ] ; then
if [[ -z "$DBM_SCRIPT_REL_VERSION" || -z "$DBM_SCRIPT_REL_NAME" ]] ; then
echo "Missing Release Version or Release Name or Id Release."
return 1
fi
fi
if [ -z "$DBM_SCRIPT_DIRECTORY" ] ; then
echo "Missing Script Directory."
return 1
fi
if [ -z "$DBM_SCRIPT_ACTIVE" ] ; then
DBM_SCRIPT_ACTIVE="1"
else
if [[ x"$DBM_SCRIPT_ACTIVE" != x"1" && x"$DBM_SCRIPT_ACTIVE" != x"0" ]] ; then
DBM_SCRIPT_ACTIVE="1"
fi
fi
unset -f _dbm_ins_script_help
return 0
}
_dbm_check_rel_dep_args
Internal function for parse command line arguments related to insert_rel_dept
command.
Command Arguments:
-n NAME
: Name of the release where add a new dependency.
-t VERSION_TO
: Version of the release that has a dependency.
-f VERSION_FROM
: Version of the release that is needed for VERSION_TO.
-h
: Show command options.
Variables Used:
DBM_REL_NAME
: Name of the release.
DBM_REL_VERSION_TO
: Release version target of the dependency.
DBM_REL_VERSION_FROM
: Release version of the release source for the dependency.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_rel_dep_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_ins_rel_dep_args args: $@)\n"
# Reinitialize opt index position
OPTIND=1
while getopts "n:t:f:h" opts "$@" ; do
case $opts in
n) DBM_REL_NAME="$OPTARG";;
t) DBM_REL_VERSION_TO="$OPTARG";;
f) DBM_REL_VERSION_FROM="$OPTARG";;
h)
echo -en "[-n name] Release Name.\n"
echo -en "[-t version_to] Release version that has a dependency.\n"
echo -en "[-f version_from] Release version needed.\n"
return 1
;;
esac
done
if [ -z "$DBM_REL_NAME" ] ; then
echo "Missing Release Name."
return 1
fi
if [ -z "$DBM_REL_VERSION_TO" ] ; then
echo "Missing Release version that has a dependency."
return 1
fi
if [ -z "$DBM_REL_VERSION_FROM" ] ; then
echo "Missing Release version needed on target."
return 1
fi
if [ "$DBM_REL_VERSION_FROM" == "$DBM_REL_VERSION_TO" ] ; then
echo "Both version are equal. Error."
return 1
fi
return 0
}
_dbm_check_upd_script_args
Internal function for parse command line arguments related to update_script
command.
Command Arguments:
-i SCRIPT_ID
: Id of the script to update.
-f FILENAME
: Script filename to update.
-n NAME
: Name of the release of the script to update.
-v VERSION
: Version of the release of the script to update.
-t STYPE
: Type of the script to update
-a FLAG
: Set active (1) or disable (0) flag of the script.
-d DIRECTORY
: Directory of the script to update.
-o ID_ORDER
: Id order of the script to update (optional).
-r RELEASE_ID
: Id of the release of the script.
If this option is present are not needed release name and release version.
-h
: Show update_script command options.
Variables Used:
DBM_SCRIPT_ID
: Id of the script to update.
DBM_SCRIPT_FILENAME
: Filename of the script.
DBM_SCRIPT_TYPE
: Type of the script to update.
DBM_SCRIPT_ACTIVE
: Status of the script.
DBM_SCRIPT_DIRECTORY
: Directory of the script
DBM_SCRIPT_ID_RELEASE
: Id release of the script
DBM_SCRIPT_REL_NAME
: Release name related with script to update
DBM_SCRIPT_REL_VERSION
: Release version related with script to update
DBM_SCRIPT_ID_ORDER
: Order Id of the script
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_upd_script_args () {
[[ $DEBUG ]] && echo -en "(_dbm_check_upd_script_args args: $@)\n"
_dbm_check_upd_script_help () {
echo -en "[-i id_script] Id Script.\n"
echo -en "[-f filename] Script filename.\n"
echo -en "[-n name] Release Name.\n"
echo -en "[-v version] Release Version\n"
echo -en "[-t script_type] Script Type.\n"
echo -en "[-a 0|1] Set active flag.\n"
echo -en "[-d directory] Directory of the script.\n"
echo -en "[-o id_order] Script Id Order (optional). Default is used MAX(id) of the same id_release.\n"
echo -en "[-r id_release] Id_release of the script. Use this instead of release name and version.\n"
}
# Reinitialize opt index position
OPTIND=1
while getopts "i:f:t:a:d:hr:n:v:o:" opts "$@" ; do
case $opts in
i) DBM_SCRIPT_ID="$OPTARG";;
f) DBM_SCRIPT_FILENAME="$OPTARG";;
t) DBM_SCRIPT_TYPE="$OPTARG";;
a) DBM_SCRIPT_ACTIVE="$OPTARG";;
d) DBM_SCRIPT_DIRECTORY="$OPTARG";;
r) DBM_SCRIPT_ID_RELEASE="$OPTARG";;
n) DBM_SCRIPT_REL_NAME="$OPTARG";;
v) DBM_SCRIPT_REL_VERSION="$OPTARG";;
o) DBM_SCRIPT_ID_ORDER="$OPTARG";;
h)
_dbm_check_upd_script_help
return 1
;;
esac
done
if [ -z "$DBM_SCRIPT_ID" ] ; then
echo "Missing Script Id."
return 1
fi
if [ ! -z "$DBM_SCRIPT_ACTIVE" ] ; then
if [[ x"$DBM_SCRIPT_ACTIVE" != x"1" && x"$DBM_SCRIPT_ACTIVE" != x"0" ]] ; then
DBM_SCRIPT_ACTIVE="1"
fi
fi
unset -f _dbm_check_upd_script_help
return 0
}
_dbm_check_rm_script_args
Internal function for parse command line arguments related to remove_script
command.
Command Arguments:
-i SCRIPT_ID
: Id of the script to remove.
-h
: Show command options.
Variables Used:
DBM_SCRIPT_ID
: Id of the script to remove.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_rm_script_args () {
local show_help=false
_dbm_rm_script_help () {
echo -en "[-i id_script] Id Script of the script to remove.\n"
}
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_rm_script_args args: $@)\n"
local short_options="i:h"
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_rm_script_help
unset -f _dbm_rm_script_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_rm_script_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-i) DBM_SCRIPT_ID="$2";shift;;
-h)
show_help=true
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ $show_help == true ] ; then
_dbm_rm_script_help
ans = 1
else
ans = 0
if [ -z "$DBM_SCRIPT_ID" ] ; then
echo "Missing Script Id."
ans = 1
fi
fi
unset -f _dbm_rm_script_help
return $ans
}
_dbm_check_upd_release_args
Internal function for parse command line arguments related to update_release
command.
Command Arguments:
-n NAME
: Name of the release to update.
-v VERSION
: Version of the release to update.
-d YYYY-MM-DD
: Date of the release to update.
-a ADAPTER
: Adapter value to update on release.
-b ID_BRANCH
: Branch Id value to update on release.
-i ID_RELEASE
: Id of the release to update
--dir DIR
: Directory of the release to update
-h
: Show command options.
Variables Used:
DBM_REL_NAME_UPD
: Name of the release
DBM_REL_DATE_UPD
: Date of the release
DBM_REL_VERSION_UPD
: Version of the release
DBM_REL_ADAPTER_UPD
: Adapter of the release
DBM_REL_BRANCH_UPD
: Branch of the release
DBM_REL_DIR_UPD
: Directory of the release.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_upd_release_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_upd_release_args: $@)\n"
_dbm_upd_release_help () {
echo -en "[-n name] Release Name.\n"
echo -en "[-d YYYY-MM-DD] Release Date.\n"
echo -en "[-v version] Release Version\n"
echo -en "[-a adapter] Release Adapter.\n"
echo -en "[-b id_branch] Id Branch.\n"
echo -en "[-i id_release] Id Release to update.\n"
echo -en "[--dir directory] Directory to update.\n"
echo -en "\n"
}
DBM_REL_NAME_UPD=0
DBM_REL_DATE_UPD=0
DBM_REL_VERSION_UPD=0
DBM_REL_ADAPTER_UPD=0
DBM_REL_BRANCH_UPD=0
DBM_REL_DIR_UPD=0
local short_options="b:n:d:a:v:i:h"
local long_options="dir:"
$(set -- $(getopt -u -q -a -o "$short_options" -l "$long_options" -- "$@")) || error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_upd_release_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_upd_release_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case $1 in
-n)
DBM_REL_NAME="$2"
DBM_REL_NAME_UPD=1
shift
;;
-d)
DBM_REL_DATE="$2"
DBM_REL_DATE_UPD=1
shift
;;
-v)
DBM_REL_VERSION="$2"
DBM_REL_VERSION_UPD=1
shift
;;
-a)
DBM_REL_ADAPTER="$2"
DBM_REL_ADAPTER_UPD=1
shift
;;
-b)
DBM_REL_BRANCH="$2"
DBM_REL_BRANCH_UPD=1
shift
;;
-i)
DBM_REL_ID="$2"
shift
;;
-h)
_dbm_upd_release_help
return 1
;;
--)
DBM_REL_DIR="$2"
DBM_REL_DIR_UPD=1
shift
;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
if [[ $DBM_REL_NAME_UPD -eq 0 && $DBM_REL_DATE_UPD -eq 0 &&
$DBM_REL_VERSION_UPD -eq 0 && $DBM_REL_ADAPTER_UPD -eq 0 &&
$DBM_REL_BRANCH_UPD -eq 0 && $DBM_REL_DIR_UPD -eq 0 ]] ; then
echo -en "No fields to update.\n"
return 1
fi
unset -f _dbm_upd_release_help
return 0
}
_dbm_check_move_release_args
Internal function for parse command line arguments related to move_release
command.
Command Arguments:
-r RELEASE_ID
: Id of the release to remove.
-f
: For remove of the selected release without confirmation question.
-h
: Show command options.
Variables Used:
DBM_BEFORE
: Set to 1 when move require that a version is moved before another. Default 0.
DBM_AFTER
: Set to 1 when move require that a version is moved after another. Default 0.
DBM_REL_NAME
: Name of the release
DBM_REL_VERSION_TO
: Version to use for move
DBM_REL_VERSION_FROM
: Version to move.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_move_release_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_inhibit_script_args args: $@)\n"
_dbm_mv_release_help () {
echo -en "[-r version] Release version.\n"
echo -en "[-n name] Release Name.\n"
echo -en "[-a version_to] After release version_to.\n"
echo -en "[-b version_to] Before release version_to.\n"
echo -en "\n"
echo -en "Example: -n 'Project1' -r '0.1.1' -a '0.1.0' (Release 0.1.1 after release 0.1.0)\n"
}
DBM_BEFORE=0
DBM_AFTER=0
# Reinitialize opt index position
OPTIND=1
while getopts "b:n:a:r:h" opts "$@" ; do
case $opts in
n) DBM_REL_NAME="$OPTARG";;
b) DBM_BEFORE=1
DBM_REL_VERSION_TO="$OPTARG";;
a) DBM_AFTER=1
DBM_REL_VERSION_TO="$OPTARG";;
r) DBM_REL_VERSION_FROM="$OPTARG";;
h)
_dbm_mv_release_help
return 1
;;
esac
done
if [ -z "$DBM_REL_NAME" ] ; then
_dbm_mv_release_help
#echo "Missing Release Name."
return 1
fi
if [ -z "$DBM_REL_VERSION_FROM" ] ; then
echo "Missing Release version."
return 1
fi
if [[ $DBM_BEFORE == 1 && $DBM_AFTER == 1 ]] ; then
echo "Both after and before are used. Error."
return 1
fi
if [[ $DBM_BEFORE == 0 && $DBM_AFTER == 0 ]] ; then
echo "Missing -a or -b parameter."
return 1
fi
unset -f _dbm_mv_release_help
return 0
}
_dbm_check_inhibit_script_args
Internal function for parse command line arguments related to insert_inhibit_script
command.
Command Arguments:
-n NAME
: Name of the release where add an inhibited script between two version.
-i SCRIPT_ID
: Id of the script to inhibit.
-t VERSION_TO
: Version of the release target of the installation.
-f VERSION_FROM
: Version of the release source of the installation.
-h
: Show command options.
Variables Used:
DBM_SCRIPT_ID
: Script Id
DBM_REL_NAME
: Name of the release
DBM_REL_VERSION_TO
: Version to use for inhibition as source.
DBM_REL_VERSION_FROM
: Version to for inhibition as target.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_inhibit_script_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_ins_inhibit_script_args args: $@)\n"
# Reinitialize opt index position
OPTIND=1
while getopts "i:n:t:f:h" opts "$@" ; do
case $opts in
i) DBM_SCRIPT_ID="$OPTARG";;
n) DBM_REL_NAME="$OPTARG";;
t) DBM_REL_VERSION_TO="$OPTARG";;
f) DBM_REL_VERSION_FROM="$OPTARG";;
h)
echo -en "[-n name] Release Name.\n"
echo -en "[-i id_script] Script Id.\n"
echo -en "[-t version_to] Release version target of the installation.\n"
echo -en "[-f version_from] Release version source of the installation.\n"
return 1
;;
esac
done
if [ -z "$DBM_SCRIPT_ID" ] ; then
echo "Missing Script Id."
return 1
fi
if [ -z "$DBM_REL_NAME" ] ; then
echo "Missing Release Name."
return 1
fi
if [ -z "$DBM_REL_VERSION_TO" ] ; then
echo "Missing Release version that has a dependency."
return 1
fi
if [ -z "$DBM_REL_VERSION_FROM" ] ; then
echo "Missing Release version needed on target."
return 1
fi
if [ "$DBM_REL_VERSION_FROM" == "$DBM_REL_VERSION_TO" ] ; then
echo "Both version are equal. Error."
return 1
fi
return 0
}
_dbm_check_move_script_args
Internal function for parse command line arguments related to move_script
command.
Command Arguments:
-i SCRIPT_ID
: Id of the script to move.
-a SCRIPT_ID_X
: Move script after script with id SCRIPT_ID_X.
-b SCRIPT_ID_X
: Move script before script with id SCRIPT_ID_X.
-r ID_RELEASE
: Release id of the script to move.
-h
: Show command options.
Variables Used:
DBM_REL_ID
: Release id of the script.
DBM_BEFORE
: Set to 1 when script must be move before another. Default 0.
DBM_AFTER
: Set to 1 when script must be move after another. Default 0.
DBM_SCRIPT_ID_TO
: Version to use for move as target
DBM_SCRIPT_ID_FROM
: Version to use for move as source
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_move_script_args () {
[[ $DEBUG && $DEBUG == true ]] && echo -en "(_dbm_check_move_script_args: $@)\n"
_dbm_move_script_help () {
echo -en "[-i id_script] Id script of the script to move.\n"
echo -en "[-a x] After script with id x.\n"
echo -en "[-b x] Before script with id x.\n"
echo -en "[-r id_release] Id Release of the script to move.\n"
}
DBM_BEFORE=0
DBM_AFTER=0
# Reinitialize opt index position
OPTIND=1
while getopts "b:i:a:r:h" opts "$@" ; do
case $opts in
r) DBM_REL_ID="$OPTARG";;
b) DBM_BEFORE=1
DBM_SCRIPT_ID_TO="$OPTARG";;
a) DBM_AFTER=1
DBM_SCRIPT_ID_TO="$OPTARG";;
i) DBM_SCRIPT_ID_FROM="$OPTARG";;
h)
_dbm_move_script_help
return 1
;;
esac
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
if [ -z "$DBM_SCRIPT_ID_FROM" ] ; then
echo "Missing Script Id."
return 1
fi
if [[ $DBM_BEFORE == 1 && $DBM_AFTER == 1 ]] ; then
echo "Both after and before are used. Error."
return 1
fi
if [[ $DBM_BEFORE == 0 && $DBM_AFTER == 0 ]] ; then
echo "Missing -a or -b parameter."
return 1
fi
unset -f _dbm_move_script_help
return 0
}
# dbm__dbm_check_move_script_args_end
# dbm__dbm_check_rem_rel_args
_dbm_check_rem_rel_args () {
local short_options="r:hf"
[[ $DEBUG ]] && echo -en "(_dbm_check_rem_rel_args args: $@)\n"
_dbm_rem_rel_help () {
echo -en "[-r id_release] Id Release of the script to remove.\n"
echo -en "[-f] Force remove without confirmation question.\n"
}
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || \
error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_rem_rel_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_rem_rel_args: Found $# params)\n"
DBM_FORCE_RM=0
while [ $# -gt 0 ] ; do
case "$1" in
-r) DBM_REL_ID="$2" ;shift;;
-f) DBM_FORCE_RM="1" ;;
-h)
_dbm_rem_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
unset -f _dbm_rem_rel_help
return 0
}
# dbm__dbm_check_rem_rel_args_end
# dbm__dbm_show_rel_args
_dbm_show_rel_args () {
local short_options="b:h"
[[ $DEBUG ]] && echo -en "(_dbm_check_show_rel_args args: $@)\n"
_dbm_show_rel_help () {
echo -en "[-b id_branch] Id branch to filter.\n"
}
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || \
error_handled "Invalid parameters"
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_show_rel_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-b) DBM_BRANCH_ID="$2" ;shift;;
-h)
_dbm_show_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
unset -f _dbm_show_rel_help
return 0
}
# dbm__dbm_show_rel_args_end
# vim: syn=sh filetype=sh
_dbm_check_rem_rel_args
Internal function for parse command line arguments related to remove_release
command.
Command Arguments:
-r RELEASE_ID
: Id of the release to remove.
-f
: For remove of the selected release without confirmation question.
-h
: Show command options.
Variables Used:
DBM_FORCE_RM
: Set to 1 when is not ask configuration question before remove release.
DBM_REL_ID
: Id of the release to remove
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_check_rem_rel_args () {
local short_options="r:hf"
[[ $DEBUG ]] && echo -en "(_dbm_check_rem_rel_args args: $@)\n"
_dbm_rem_rel_help () {
echo -en "[-r id_release] Id Release of the script to remove.\n"
echo -en "[-f] Force remove without confirmation question.\n"
}
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || \
error_handled "Invalid parameters"
if [ $# -lt 2 ] ; then
_dbm_rem_rel_help
return 1
fi
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_rem_rel_args: Found $# params)\n"
DBM_FORCE_RM=0
while [ $# -gt 0 ] ; do
case "$1" in
-r) DBM_REL_ID="$2" ;shift;;
-f) DBM_FORCE_RM="1" ;;
-h)
_dbm_rem_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
if [ -z "$DBM_REL_ID" ] ; then
echo "Missing Release Id."
return 1
fi
unset -f _dbm_rem_rel_help
return 0
}
_dbm_check_show_rel_args
Internal function for parse command line arguments related to show_releases
command.
Command Arguments:
-b ID_BRANCH
: Filter list for a particular Branch Id.
-h
: Show command options.
Variables Used:
DBM_BRANCH_ID
: Id of the branch to use as filter.
Return:
0
: on success
1
: on error
(Show/Hide)_dbm_show_rel_args () {
local short_options="b:h"
[[ $DEBUG ]] && echo -en "(_dbm_check_show_rel_args args: $@)\n"
_dbm_show_rel_help () {
echo -en "[-b id_branch] Id branch to filter.\n"
}
$(set -- $(getopt -u -q -a -o "$short_options" -- "$@")) || \
error_handled "Invalid parameters"
[[ $DEBUG && $DEBUG == true ]] && \
echo -en "(_dbm_check_show_rel_args: Found $# params)\n"
while [ $# -gt 0 ] ; do
case "$1" in
-b) DBM_BRANCH_ID="$2" ;shift;;
-h)
_dbm_show_rel_help
return 1
;;
--) ;;
*)
error_generate "Invalid parameter $1."
;;
esac
shift
done
unset -f _dbm_show_rel_help
return 0
}