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

Copy over REPLACE function from update script #148

Merged
merged 2 commits into from
Aug 6, 2019
Merged
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
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