I have the following file:
<?xml version="1.0" encoding="UTF-8"?>
<confluence-configuration>
<setupStep>complete</setupStep>
<setupType>custom</setupType>
<buildNumber>8506</buildNumber>
<properties>
<property name="attachments.dir">${confluenceHome}/attachments</property>
<property name="confluence.setup.server.id">BN4J-RBSE-6ZPZ-GB4G</property>
<property name="confluence.webapp.context.path"></property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/confluence</property>
<property name="hibernate.database.lower_non_ascii_supported">true</property>
<property name="hibernate.dialect">com.atlassian.confluence.impl.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.setup">true</property>
<property name="lucene.index.dir">${localHome}/index</property>
<property name="synchrony.encryption.disabled">true</property>
<property name="synchrony.proxy.enabled">true</property>
<property name="webwork.multipart.saveDir">${localHome}/temp</property>
</properties>
</confluence-configuration>
What is the best method to add key / value pairs like shown below?
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">60</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">20</property>
<property name="hibernate.c3p0.timeout">30</property>
<property name="hibernate.c3p0.validate">true</property>
I'm hoping to do so with xmlstarlet.
EDIT 1: I tried:
xmlstarlet edit --update "/confluence-configuration/properties/property[@name='hibernate.c3p0.acquire_increment']/@name" --value "1" confluence.cfg.xml
But that messes my xml file up
EDIT 2: apparently that had to do with
<property name="confluence.webapp.context.path"></property>
I have now a working update command:
xmlstarlet ed --update "/confluence-configuration/properties/property[@name='hibernate.c3p0.acquire_increment']" --value "5" confluence.cfg.xml
But how about inserting?
Thank you!
Probably not the nicest way but i resolved it like this;
declare -A xmlArray
xmlArray[hibernate.c3p0.acquire_increment]=1
xmlArray[hibernate.c3p0.idle_test_period]=100
xmlArray[hibernate.c3p0.max_size]=${CONFLUENCE_MAX_DB_CONNECTIONS}
xmlArray[hibernate.c3p0.max_statements]=0
xmlArray[hibernate.c3p0.min_size]=20
xmlArray[hibernate.c3p0.timeout]=30
xmlArray[hibernate.c3p0.validate]=true
xmlArray[hibernate.connection.driver_class]=org.postgresql.Driver
xmlArray[hibernate.connection.isolation]=2
xmlArray[hibernate.connection.password]=${CONFLUENCE_DATABASE_PASSWORD}
xmlArray[hibernate.connection.url]=${CONFLUENCE_DATABASE_URL}
xmlArray[hibernate.connection.username]=${CONFLUENCE_DATABASE_USERNAME}
xmlstarlet ed --inplace -d "/confluence-configuration/properties/property[@name='hibernate.connection.datasource']" ${CONFLUENCE_HOME}/confluence.cfg.xml
for KEY in "${!xmlArray[@]}"; do
if [ -n "$(xmlstarlet sel -T -t -v "/confluence-configuration/properties/property[@name='$KEY']/@name" ${CONFLUENCE_HOME}/confluence.cfg.xml)" ]; then
xmlstarlet ed --inplace --update "/confluence-configuration/properties/property[@name='$KEY']" --value "${xmlArray[$KEY]}" ${CONFLUENCE_HOME}/confluence.cfg.xml;
else
xmlstarlet edit -L --subnode "/confluence-configuration/properties" --type elem -n property --value "${xmlArray[$KEY]}" --insert "/confluence-configuration/properties/property[last()]" --type attr -n name --value "$KEY" ${CONFLUENCE_HOME}/confluence.cfg.xml;
fi
done