Skip to content

Commit

Permalink
Copy over REPLACE function from update script (#148)
Browse files Browse the repository at this point in the history
* Copy over REPLACE function from update script

* Replace variables in update.lst

* Make sure snapshot to snapshot updates load the update.lst too

Signed-off-by: Ben Clark <ben@benjyc.uk>
  • Loading branch information
BClark09 authored Aug 6, 2019
1 parent abb98fc commit ba55243
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions resources/control-runtime/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ if [ x"${OH_DOCKER_INSTALLATION}" != x ]; then
exit 0
fi

[ -f /etc/default/openhab2 ] && . /etc/default/openhab2
if [ -r /etc/profile.d/openhab2.sh ]; then
. /etc/profile.d/openhab2.sh
elif [ -r /etc/default/openhab2 ]; then
. /etc/default/openhab2
fi

startOpenHAB() {
if [ -x /bin/systemctl ] ; then
Expand Down Expand Up @@ -112,10 +116,23 @@ getVersionNumber(){
runCommand() {
string="$1"

string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")"
string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")"
string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")"

command="$(echo "$string" | awk -F';' '{print $1}')"
param1="$(echo "$string" | awk -F';' '{print $2}')"
param2="$(echo "$string" | awk -F';' '{print $3}')"
param3="$(echo "$string" | awk -F';' '{print $4}')"

case $command in
'REPLACE')
# Avoid error if file does not exist
if [ -f "$param3" ]; then
echo " Replacing: String $param1 to $param2 in file $param3"
sed -i "s:$param1:$param2:g" "$param3"
fi
;;
'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";;
'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";;
esac
Expand All @@ -128,6 +145,11 @@ scanVersioningList() {
InNewVersion=false
oldVersionNumber=$(getVersionNumber "$oldVersion")

## Snapshots should always use the latest update list.
case $oldVersion in
*"-"* | *"."*"."*"."*) oldVersionNumber=$((oldVersionNumber-1));;
esac

## Read the file line by line.
while IFS= read -r Line
do
Expand All @@ -150,7 +172,7 @@ scanVersioningList() {
if $InSection; then
LineVersion="$(echo "$Line" | awk -F'[][]' '{print $2}')"
LineVersionNumber=$(getVersionNumber "$LineVersion")
if [ "$oldVersionNumber" -le "$LineVersionNumber" ]; then
if [ "$oldVersionNumber" -lt "$LineVersionNumber" ]; then
InNewVersion=true
echo ""
printf "$VersionMessage $LineVersion:\n"
Expand Down Expand Up @@ -217,6 +239,7 @@ case "$1" in
if [ -f ${OLD_VERSION_FILE} ]; then
oldVersion="$(cat ${OLD_VERSION_FILE})"
rm -f ${OLD_VERSION_FILE}
scanVersioningList "POST" "${OPENHAB_TEXT} Performing post-update tasks for version"
scanVersioningList "MSG" "${OPENHAB_TEXT} Listing important changes for version"
fi
echo ""
Expand Down

0 comments on commit ba55243

Please sign in to comment.