Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hbase-site.xml properties #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions base/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/bin/bash

function addProperty() {
function setProperty() {
# Sets/unsets property value in an XML configuration file
# Usage:
# * Append/update: `setProperty filePath propName propValue`
# * Delete: `setProperty filePath propName`
local path=$1
local name=$2
local value=$3

local entry="<property><name>$name</name><value>${value}</value></property>"
local escapedEntry=$(echo $entry | sed 's/\//\\\//g')
sed -i "/<\/configuration>/ s/.*/${escapedEntry}\n&/" $path
local wrappedName="<name>$name</name>"
local escapedName=${wrappedName//\//\\/} # https://stackoverflow.com/a/27788661
if [ -z "$value" ]; then
sed -i "/${escapedName}/d" $path
else
local entry="<property>$wrappedName<value>$value</value></property>"
local escapedEntry=${entry//\//\\/}
# https://superuser.com/a/590666
grep -q "${wrappedName}" $path && sed -i "/${escapedName}/c ${escapedEntry}" $path || sed -i "/<\/configuration>/ s/.*/${escapedEntry}\n&/" $path
fi
}

function configure() {
Expand All @@ -24,7 +35,7 @@ function configure() {
var="${envPrefix}_${c}"
value=${!var}
echo " - Setting $name=$value"
addProperty /etc/hbase/$module-site.xml $name "$value"
setProperty /etc/hbase/$module-site.xml $name "$value"
done
}

Expand Down