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