Skip to content

Commit

Permalink
fix: improve replace properties function
Browse files Browse the repository at this point in the history
Signed-off-by: GridexX <[email protected]>
  • Loading branch information
GridexX committed Jul 14, 2023
1 parent d16b38d commit e947b49
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 24 deletions.
19 changes: 15 additions & 4 deletions 14/mariadb-tomcat/xwiki/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ function other_starts() {
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1"
function xwiki_replace_or_add() {
local file_path="$1"
local setting="$2"
local new_value="$3"

# Check if the setting exists in the file
if grep -Eq "^ *#? *$setting=" "$file_path"; then
# If the setting exists, replace the occurrence with the new value
sed -i 's|^\( *#\? *\)'"$setting"'=.*$|'"$setting"'='"$new_value"'|g' "$file_path"
else
# If the setting doesn't exist, add it at the end of the file
echo "$setting=$new_value" >> "$file_path"
fi
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}

# usage: file_env VAR [DEFAULT]
Expand Down
19 changes: 15 additions & 4 deletions 14/mysql-tomcat/xwiki/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ function other_starts() {
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1"
function xwiki_replace_or_add() {
local file_path="$1"
local setting="$2"
local new_value="$3"

# Check if the setting exists in the file
if grep -Eq "^ *#? *$setting=" "$file_path"; then
# If the setting exists, replace the occurrence with the new value
sed -i 's|^\( *#\? *\)'"$setting"'=.*$|'"$setting"'='"$new_value"'|g' "$file_path"
else
# If the setting doesn't exist, add it at the end of the file
echo "$setting=$new_value" >> "$file_path"
fi
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}

# usage: file_env VAR [DEFAULT]
Expand Down
19 changes: 15 additions & 4 deletions 14/postgres-tomcat/xwiki/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ function other_starts() {
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1"
function xwiki_replace_or_add() {
local file_path="$1"
local setting="$2"
local new_value="$3"

# Check if the setting exists in the file
if grep -Eq "^ *#? *$setting=" "$file_path"; then
# If the setting exists, replace the occurrence with the new value
sed -i 's|^\( *#\? *\)'"$setting"'=.*$|'"$setting"'='"$new_value"'|g' "$file_path"
else
# If the setting doesn't exist, add it at the end of the file
echo "$setting=$new_value" >> "$file_path"
fi
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}

# usage: file_env VAR [DEFAULT]
Expand Down
19 changes: 15 additions & 4 deletions 15/mariadb-tomcat/xwiki/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ function other_starts() {
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1"
function xwiki_replace_or_add() {
local file_path="$1"
local setting="$2"
local new_value="$3"

# Check if the setting exists in the file
if grep -Eq "^ *#? *$setting=" "$file_path"; then
# If the setting exists, replace the occurrence with the new value
sed -i 's|^\( *#\? *\)'"$setting"'=.*$|'"$setting"'='"$new_value"'|g' "$file_path"
else
# If the setting doesn't exist, add it at the end of the file
echo "$setting=$new_value" >> "$file_path"
fi
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}

# usage: file_env VAR [DEFAULT]
Expand Down
19 changes: 15 additions & 4 deletions 15/mysql-tomcat/xwiki/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ function other_starts() {
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1"
function xwiki_replace_or_add() {
local file_path="$1"
local setting="$2"
local new_value="$3"

# Check if the setting exists in the file
if grep -Eq "^ *#? *$setting=" "$file_path"; then
# If the setting exists, replace the occurrence with the new value
sed -i 's|^\( *#\? *\)'"$setting"'=.*$|'"$setting"'='"$new_value"'|g' "$file_path"
else
# If the setting doesn't exist, add it at the end of the file
echo "$setting=$new_value" >> "$file_path"
fi
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}

# usage: file_env VAR [DEFAULT]
Expand Down
19 changes: 15 additions & 4 deletions 15/postgres-tomcat/xwiki/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ function other_starts() {
# $1 - the path to xwiki.[cfg|properties]
# $2 - the setting/property to set
# $3 - the new value
function xwiki_replace() {
sed -i s~"\#\? \?$2 \?=.*"~"$2=$3"~g "$1"
function xwiki_replace_or_add() {
local file_path="$1"
local setting="$2"
local new_value="$3"

# Check if the setting exists in the file
if grep -Eq "^ *#? *$setting=" "$file_path"; then
# If the setting exists, replace the occurrence with the new value
sed -i 's|^\( *#\? *\)'"$setting"'=.*$|'"$setting"'='"$new_value"'|g' "$file_path"
else
# If the setting doesn't exist, add it at the end of the file
echo "$setting=$new_value" >> "$file_path"
fi
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_cfg() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.cfg "$1" "$2"
}

# $1 - the setting/property to set
# $2 - the new value
function xwiki_set_properties() {
xwiki_replace /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
xwiki_replace_or_add /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/xwiki.properties "$1" "$2"
}

# usage: file_env VAR [DEFAULT]
Expand Down

0 comments on commit e947b49

Please sign in to comment.