From 30d56f4eb9851c398b6ac1461cec815be24cf123 Mon Sep 17 00:00:00 2001 From: yengliong Date: Tue, 15 Oct 2024 11:09:50 +0800 Subject: [PATCH] [NEXMANAGE-872] Fix provision-tc issue in TiberOS The provision-tc cannot run sed command to edit /etc/dispatcher.environment due to RO filesystem. It also cannot add the pmsuser group. This PR fixes both issue. Signed-off-by: yengliong --- inbm/Changelog.md | 3 ++- .../mqtt/template/usr/bin/mqtt-provision-start | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/inbm/Changelog.md b/inbm/Changelog.md index 07715157d..1b58a3cf5 100644 --- a/inbm/Changelog.md +++ b/inbm/Changelog.md @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## NEXT - MMMM-DD-YY - +### Fixed + - (NEXMANAGE-872) Fix provision-tc issue in TiberOS - cannot overwrite /etc/dispatcher.environment ## 4.2.6 - 2024-10-04 ### Added diff --git a/inbm/fpm/mqtt/template/usr/bin/mqtt-provision-start b/inbm/fpm/mqtt/template/usr/bin/mqtt-provision-start index 984d18c6c..8fdab5fb4 100755 --- a/inbm/fpm/mqtt/template/usr/bin/mqtt-provision-start +++ b/inbm/fpm/mqtt/template/usr/bin/mqtt-provision-start @@ -1,7 +1,20 @@ #!/bin/bash set -euxo pipefail + +# Retrieve OS Release ID +if [ -f /etc/os-release ]; then + . /etc/os-release +else + echo "/etc/os-release not found. Exiting." + exit 1 +fi + # Ensure mqtt-broker has required permissions -getent group pmsuser || groupadd pmsuser +if [ "$ID" != "tiber" ]; then + getent group pmsuser || groupadd pmsuser +else + echo "Skipping adding pmsuser group on 'tiber' OS." +fi chgrp mqtt-broker /var/persistent-log/mosquitto chmod g+rwx /var/persistent-log/mosquitto chmod -R g+rw /var/persistent-log/mosquitto @@ -37,7 +50,8 @@ sed -i -e "s/listener .* 127.0.0.1/listener $LOCAL_MQTT_PORT 127.0.0.1/g" /etc/i # If dispatcher.environment exists, patch its port if [ -f /etc/dispatcher.environment ]; then - sed -i -e "s/MQTT_PORT=.*/MQTT_PORT=$LOCAL_MQTT_PORT/g" /etc/dispatcher.environment + temp_file=$(mktemp) + sed "s/MQTT_PORT=.*/MQTT_PORT=$LOCAL_MQTT_PORT/g" /etc/dispatcher.environment > "$temp_file" && cat "$temp_file" > /etc/dispatcher.environment fi