improve getdbcreds

This commit is contained in:
Jakobus Schürz 2022-07-04 15:42:39 +02:00
parent cdd277782e
commit 1cd015e6d9

View file

@ -1012,30 +1012,6 @@ get_crtime() {
done
}
# jira-confluence-specific is temporary in here
#function getdbcreds_jira () {
# [ $# -eq 0 ] return 1
#
# DB_FILE=$1
#
# DB_URL="$(grep -oPm1 "(?<=<url>)[^<]+" ${DB_FILE})"
# DB_USER="$(grep -oPm1 "(?<=<username>)[^<]+" ${DB_FILE})"
# DB_PWD="$(grep -oPm1 "(?<=<password>)[^<]+" ${DB_FILE})"
# DB_HOST="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*):\(.*\)/\(.*\)$@\1@')"
# DB_PORT="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*):\(.*\)/\(.*\)$@\2@')"
# DB_NAME="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*):\(.*\)/\(.*\)$@\3@')"
#
# cat << \
# EOF
# DB_HOST: ${DB_HOST}
# DB_PORT: ${DB_PORT}
# DB_NAME: ${DB_NAME}
# DB_USER: ${DB_USER}
# DB_PWD: ${DB_PWD}
#EOF
# return 0
#}
is_btrfs_subvolume() {
sudo btrfs subvolume show "$1" >/dev/null
@ -1106,27 +1082,19 @@ getusedip () {
}
function getdbcreds_jra () {
case $# in
0)
gojirahome
DB_FILE=dbconfig.xml
#cd -
;;
1)
DB_FILE=$1
;;
*)
echo "wrong number of arguments"
return 1
;;
esac
#DB_URL="$(grep -oPm1 "(?<=<url>)[^<]+" ${DB_FILE})"
#DB_USER="$(grep -oPm1 "(?<=<username>)[^<]+" ${DB_FILE})"
#DB_PWD="$(grep -oPm1 "(?<=<password>)[^<]+" ${DB_FILE})"
DB_URL="$(xmllint --xpath "jira-database-config/jdbc-datasource/url/text()" ${DB_FILE})"
DB_USER="$(xmllint --xpath "jira-database-config/jdbc-datasource/username/text()" ${DB_FILE})"
DB_PWD="$(xmllint --xpath "jira-database-config/jdbc-datasource/password/text()" ${DB_FILE})"
local APP_INST=/opt/atlassian/jira
local JRA_HOME=$(awk -F "=" '/jira.home/ {gsub(/ /, "", $0); print $2}' "${APP_INST}/atlassian-jira/WEB-INF/classes/jira-application.properties")
local DB_FILE="${JRA_HOME}/dbconfig.xml"
if [ xmllint --version >/dev/null 2>&1 ]; then
DB_URL="$(xmllint --xpath "jira-database-config/jdbc-datasource/url/text()" ${DB_FILE})"
DB_USER="$(xmllint --xpath "jira-database-config/jdbc-datasource/username/text()" ${DB_FILE})"
DB_PWD="$(xmllint --xpath "jira-database-config/jdbc-datasource/password/text()" ${DB_FILE})"
else
echo "please install xmllint »apt install libxml2-utils«"
DB_URL="$(grep -oPm1 "(?<=<url>)[^<]+" ${DB_FILE})"
DB_USER="$(grep -oPm1 "(?<=<username>)[^<]+" ${DB_FILE})"
DB_PWD="$(grep -oPm1 "(?<=<password>)[^<]+" ${DB_FILE})"
fi
DB_HOST="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*\):\(.*\)/\(.*\)$@\1@')"
DB_PORT="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*\):\(.*\)/\(.*\)$@\2@')"
DB_NAME="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*\):\(.*\)/\(.*\)$@\3@')"
@ -1135,27 +1103,19 @@ function getdbcreds_jra () {
}
function getdbcreds_cnf () {
case $# in
0)
gocnfhome
DB_FILE=confluence.cfg.xml
;;
1)
DB_FILE=$1
;;
*)
echo "wrong number of arguments"
cd -
return 1
;;
esac
# DB_URL="$(grep -oPm1 "(?<=<property name=\"hibernate.connection.url\">)[^<]+" ${DB_FILE})"
# DB_USER="$(grep -oPm1 "(?<=<property name=\"hibernate.connection.username\">)[^<]+" ${DB_FILE})"
# DB_PWD="$(grep -oPm1 "(?<=<property name=\"hibernate.connection.password\">)[^<]+" ${DB_FILE})"
DB_URL="$(xmllint --xpath "confluence-configuration/properties/property[@name='hibernate.connection.url']/text()" ${DB_FILE})"
DB_USER="$(xmllint --xpath "confluence-configuration/properties/property[@name='hibernate.connection.username']/text()" ${DB_FILE})"
DB_PWD="$(xmllint --xpath "confluence-configuration/properties/property[@name='hibernate.connection.password']/text()" ${DB_FILE})"
local APP_INST=/opt/atlassian/jira
local CNF_HOME=$(awk -F "=" '/jira.home/ {gsub(/ /, "", $0); print $2}' "${APP_INST}/atlassian-jira/WEB-INF/classes/jira-application.properties")
local DB_FILE="${CNF_HOME}/confluence.cfg.xml"
if [ xmllint --version >/dev/null 2>&1 ]; then
DB_URL="$(xmllint --xpath "confluence-configuration/properties/property[@name='hibernate.connection.url']/text()" ${DB_FILE})"
DB_USER="$(xmllint --xpath "confluence-configuration/properties/property[@name='hibernate.connection.username']/text()" ${DB_FILE})"
DB_PWD="$(xmllint --xpath "confluence-configuration/properties/property[@name='hibernate.connection.password']/text()" ${DB_FILE})"
else
echo "please install xmllint »apt install libxml2-utils«"
DB_URL="$(grep -oPm1 "(?<=<property name=\"hibernate.connection.url\">)[^<]+" ${DB_FILE})"
DB_USER="$(grep -oPm1 "(?<=<property name=\"hibernate.connection.username\">)[^<]+" ${DB_FILE})"
DB_PWD="$(grep -oPm1 "(?<=<property name=\"hibernate.connection.password\">)[^<]+" ${DB_FILE})"
fi
DB_HOST="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*\):\(.*\)/\(.*\)$@\1@')"
DB_PORT="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*\):\(.*\)/\(.*\)$@\2@')"
DB_NAME="$(echo $DB_URL|sed 's@^.*//@@;s@\(^.*\):\(.*\)/\(.*\)$@\3@')"
@ -1163,6 +1123,8 @@ function getdbcreds_cnf () {
#cd -
return 0
}
function connectdb () {
case $1 in
@ -1220,7 +1182,7 @@ gojrahome() {
gojrashome() {
local APP_INST=/opt/atlassian/jira
local JIRA_HOME=$(awk -F "=" '/jira.home/ {gsub(/ /, "", $0); print $2}' "${APP_INST}/atlassian-jira/WEB-INF/classes/jira-application.properties")
[ -e "${JIRA_HOME}/cluster.properties" ] && cd $(awk -F "=" '/jira.shared.home/ {gsub(/ /, "", $0); print $2}' "${JIRA_HOME}/cluster.properties") || echo no shared home configured >&2
local JRA_HOME=$(awk -F "=" '/jira.home/ {gsub(/ /, "", $0); print $2}' "${APP_INST}/atlassian-jira/WEB-INF/classes/jira-application.properties")
[ -e "${JRA_HOME}/cluster.properties" ] && cd $(awk -F "=" '/jira.shared.home/ {gsub(/ /, "", $0); print $2}' "${JRA_HOME}/cluster.properties") || echo no shared home configured >&2
}
#EOF