From a42e3a74dc1909efbdf6d29b2c2fd53a11b61958 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Tue, 7 Apr 2026 11:14:10 +0200 Subject: [PATCH 1/4] check for active user management before modifying acl roles --- packages/helpermodules/command.py | 60 ++++++++++++++++++++----------- packages/helpermodules/subdata.py | 7 ++-- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index 21b1b66f7d..d5d32984bd 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -208,7 +208,9 @@ def addIoAction(self, connection_id: str, payload: dict) -> None: Pub().pub(f'openWB/set/io/action/{new_id}/config', device_default) self.max_id_io_action = new_id Pub().pub("openWB/set/command/max_id/io_action", self.max_id_io_action) - add_acl_role("io-action--access", new_id) + # add ACL roles for IO action access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + add_acl_role("io-action--access", new_id) pub_user_message( payload, connection_id, f'Neue IO-Aktion vom Typ \'{" / ".join(payload["data"]["type"])}\' mit ID \'{new_id}\' hinzugefügt.', @@ -217,7 +219,9 @@ def addIoAction(self, connection_id: str, payload: dict) -> None: def removeIoAction(self, connection_id: str, payload: dict) -> None: if self.max_id_io_action >= payload["data"]["id"]: ProcessBrokerBranch(f'io/action/{payload["data"]["id"]}/').remove_topics() - remove_acl_role("io-action--access", payload["data"]["id"]) + # remove ACL roles for IO action access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + remove_acl_role("io-action--access", payload["data"]["id"]) pub_user_message(payload, connection_id, f'IO-Aktion mit ID \'{payload["data"]["id"]}\' gelöscht.', MessageType.SUCCESS) else: @@ -238,9 +242,11 @@ def addIoDevice(self, connection_id: str, payload: dict) -> None: Pub().pub(f'openWB/set/system/io/{new_id}/config', device_default) self.max_id_io_device = new_id Pub().pub("openWB/set/command/max_id/io_device", self.max_id_io_device) - add_acl_role("io-device--access", new_id) - if device_default["output"]["digital"] or device_default["output"]["analog"]: - add_acl_role("io-device--write-access", new_id) + # add ACL roles for IO device access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + add_acl_role("io-device--access", new_id) + if device_default["output"]["digital"] or device_default["output"]["analog"]: + add_acl_role("io-device--write-access", new_id) pub_user_message( payload, connection_id, f'Neues IO-Gerät vom Typ \'{payload["data"]["type"]}\' mit ID \'{new_id}\' hinzugefügt.', @@ -252,8 +258,10 @@ def removeIoDevice(self, connection_id: str, payload: dict) -> None: if self.max_id_io_device >= payload["data"]["id"]: ProcessBrokerBranch(f'system/io/{payload["data"]["id"]}/').remove_topics() ProcessBrokerBranch(f'io/states/{payload["data"]["id"]}/').remove_topics() - remove_acl_role("io-device--access", payload["data"]["id"]) - remove_acl_role("io-device--write-access", payload["data"]["id"]) + # remove ACL roles for IO device access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + remove_acl_role("io-device--access", payload["data"]["id"]) + remove_acl_role("io-device--write-access", payload["data"]["id"]) pub_user_message(payload, connection_id, f'IO-Gerät mit ID \'{payload["data"]["id"]}\' gelöscht.', MessageType.SUCCESS) else: @@ -279,9 +287,11 @@ def setup_added_chargepoint(): self.addChargepointTemplate("addChargepoint", {}) if self.max_id_vehicle == -1: self.addVehicle("addChargepoint", {}) - add_acl_role("chargepoint--access", new_id) - if chargepoint_config["type"] == "mqtt": - add_acl_role("chargepoint--write-access", new_id) + # add ACL roles for charge point access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + add_acl_role("chargepoint--access", new_id) + if chargepoint_config["type"] == "mqtt": + add_acl_role("chargepoint--write-access", new_id) pub_user_message(payload, connection_id, f'Neuer Ladepunkt mit ID \'{new_id}\' wurde erstellt.', MessageType.SUCCESS) new_id = self.max_id_hierarchy + 1 @@ -386,8 +396,10 @@ def removeChargepoint(self, connection_id: str, payload: dict) -> None: break else: remove_display_user(cp_ip) - remove_acl_role("chargepoint--access", cp_id) - remove_acl_role("chargepoint--write-access", cp_id) + # remove ACL roles for charge point access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + remove_acl_role("chargepoint--access", cp_id) + remove_acl_role("chargepoint--write-access", cp_id) ProcessBrokerBranch(f'chargepoint/{cp_id}/').remove_topics() data.data.counter_all_data.hierarchy_remove_item(cp_id, ComponentType.CHARGEPOINT) Pub().pub("openWB/set/counter/get/hierarchy", data.data.counter_all_data.data.get.hierarchy) @@ -679,7 +691,9 @@ def set_default(topic: str, defaults: dict): self.max_id_hierarchy = self.max_id_hierarchy + 1 Pub().pub("openWB/set/command/max_id/hierarchy", self.max_id_hierarchy) - add_acl_role(f"{general_type.value}--access", new_id) + # add ACL roles for component access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + add_acl_role(f"{general_type.value}--access", new_id) pub_user_message( payload, connection_id, f'Neue Komponente vom Typ \'{payload["data"]["type"]}\' mit ID \'{new_id}\' hinzugefügt.', @@ -693,10 +707,12 @@ def removeComponent(self, connection_id: str, payload: dict) -> None: "Die ID ist größer als die maximal vergebene ID.", MessageType.ERROR) branch = f'system/device/{payload["data"]["deviceId"]}/component/{payload["data"]["id"]}/' ProcessBrokerBranch(branch).remove_topics() - remove_acl_role(f"{special_to_general_type_mapping(payload['data']['type']).value}--access", - payload["data"]["id"]) - remove_acl_role(f"{special_to_general_type_mapping(payload['data']['type']).value}--write-access", - payload["data"]["id"]) + # remove ACL roles for component access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + remove_acl_role(f"{special_to_general_type_mapping(payload['data']['type']).value}--access", + payload["data"]["id"]) + remove_acl_role(f"{special_to_general_type_mapping(payload['data']['type']).value}--write-access", + payload["data"]["id"]) pub_user_message( payload, connection_id, f'Komponente mit ID \'{payload["data"]["id"]}\' gelöscht.', MessageType.SUCCESS) @@ -753,7 +769,9 @@ def addVehicle(self, connection_id: str, payload: dict) -> None: self.addChargeTemplate("addVehicle", {}) if self.max_id_ev_template == -1: self.addEvTemplate("addVehicle", {}) - add_acl_role("vehicle--access", new_id) + # add ACL roles for vehicle access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + add_acl_role("vehicle--access", new_id) pub_user_message(payload, connection_id, f'Neues EV mit ID \'{new_id}\' hinzugefügt.', MessageType.SUCCESS) def removeVehicle(self, connection_id: str, payload: dict) -> None: @@ -765,8 +783,10 @@ def removeVehicle(self, connection_id: str, payload: dict) -> None: if payload["data"]["id"] > 0: Pub().pub(f'openWB/vehicle/{payload["data"]["id"]}', "") ProcessBrokerBranch(f'vehicle/{payload["data"]["id"]}/').remove_topics() - remove_acl_role("vehicle--access", payload["data"]["id"]) - remove_acl_role("vehicle--write-access", payload["data"]["id"]) + # remove ACL roles for vehicle access, if user management is active + if data.data.system_data["system"].data["security"]["user_management_active"]: + remove_acl_role("vehicle--access", payload["data"]["id"]) + remove_acl_role("vehicle--write-access", payload["data"]["id"]) pub_user_message( payload, connection_id, f'EV mit ID \'{payload["data"]["id"]}\' gelöscht.', MessageType.SUCCESS) diff --git a/packages/helpermodules/subdata.py b/packages/helpermodules/subdata.py index b40f826d5e..4d3e47c4f2 100644 --- a/packages/helpermodules/subdata.py +++ b/packages/helpermodules/subdata.py @@ -314,8 +314,11 @@ def process_vehicle_topic(self, client: mqtt.Client, var: Dict[str, ev.Ev], msg: var["ev"+index].soc_module = mod.create_vehicle(config, index) client.subscribe(f"openWB/vehicle/{index}/soc_module/calculated_soc_state", 2) client.subscribe(f"openWB/vehicle/{index}/soc_module/general_config", 2) - if config.type == "mqtt": - add_acl_role("vehicle--write-access", int(index)) + if var["system"].data["security"]["user_management_active"]: + if config.type == "mqtt": + add_acl_role("vehicle--write-access", int(index)) + else: + remove_acl_role("vehicle--write-access", int(index)) self.processing_counter.add_task() Pub().pub("openWB/system/subdata_initialized", True) self.event_soc.set() From 898df6a7ba3fc7db4589eb97e198b9c73383ac33 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Tue, 7 Apr 2026 11:15:07 +0200 Subject: [PATCH 2/4] restore: remove duplicate checks and inet dependency --- runs/atreboot.sh | 8 ++------ runs/restore.sh | 52 +++++++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/runs/atreboot.sh b/runs/atreboot.sh index 74b65d4970..8166249e82 100755 --- a/runs/atreboot.sh +++ b/runs/atreboot.sh @@ -228,12 +228,8 @@ chmod 666 "$LOGFILE" echo "pending restore detected" # remove flag to prevent a boot loop on failure rm "${OPENWBBASEDIR}/data/restore/run_on_boot" - if ((hasInet == 1)); then - "${OPENWBBASEDIR}/runs/restore.sh" - # restore.sh will reboot if successful - else - echo "no internet connection, restore not possible, skipping" - fi + "${OPENWBBASEDIR}/runs/restore.sh" + # restore.sh will reboot if successful else echo "no restore pending, normal startup" fi diff --git a/runs/restore.sh b/runs/restore.sh index 2b04e090c6..0cfad9b995 100755 --- a/runs/restore.sh +++ b/runs/restore.sh @@ -10,43 +10,45 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" { echo "$(date +"%Y-%m-%d %H:%M:%S") Restore of backup started..." + # prepare_restore.sh ends with step 5, so we continue with step 6 here echo "****************************************" - echo "Step 1: validating extracted files" - if [[ ! -f "$WORKING_DIR/SHA256SUM" ]] || - [[ ! -f "$WORKING_DIR/GIT_BRANCH" ]] || - [[ ! -f "$WORKING_DIR/GIT_HASH" ]] || - [[ ! -d "$WORKING_DIR/openWB" ]] || - [[ ! -f "$WORKING_DIR/mosquitto/mosquitto.db" ]] || - [[ ! -f "$WORKING_DIR/mosquitto_local/mosquitto.db" ]]; then - echo "this is not a complete archive! aborting restore" - exit 1 - fi - if ! (cd "$WORKING_DIR" && sudo sha256sum --quiet --check "SHA256SUM"); then - echo "some files were modified or removed! aborting restore" - exit 1 - fi - echo "****************************************" - echo "Step 2: stop mosquitto services" + # already done in prepare_restore.sh + # echo "Step 1: validating extracted files" + # if [[ ! -f "$WORKING_DIR/SHA256SUM" ]] || + # [[ ! -f "$WORKING_DIR/GIT_BRANCH" ]] || + # [[ ! -f "$WORKING_DIR/GIT_HASH" ]] || + # [[ ! -d "$WORKING_DIR/openWB" ]] || + # [[ ! -f "$WORKING_DIR/mosquitto/mosquitto.db" ]] || + # [[ ! -f "$WORKING_DIR/mosquitto_local/mosquitto.db" ]]; then + # echo "this is not a complete archive! aborting restore" + # exit 1 + # fi + # if ! (cd "$WORKING_DIR" && sudo sha256sum --quiet --check "SHA256SUM"); then + # echo "some files were modified or removed! aborting restore" + # exit 1 + # fi + # echo "****************************************" + echo "Step 6: stop mosquitto services" # no need to stop openwb2.service as we are in pre start script sudo systemctl stop mosquitto.service mosquitto_local.service # give systemctl some time to finish, may be unnecessary? sleep 2 echo "****************************************" - echo "Step 3: sync with git" + echo "Step 7: checkout matching git branch and tag" BRANCH=$(<"$WORKING_DIR/GIT_BRANCH") TAG=$(<"$WORKING_DIR/GIT_HASH") - echo "Step 3.1: checkout branch: $BRANCH" + echo "Step 7.1: checkout branch: $BRANCH" if ! git -C "$OPENWB_BASE_DIR" checkout --force "$BRANCH"; then echo "checkout of branch \"$BRANCH\" failed! aborting restore" exit 1 fi - echo "Step 3.2: reset to matching version: [$TAG]" + echo "Step 7.2: reset to matching version: [$TAG]" if ! git -C "$OPENWB_BASE_DIR" reset --hard "$TAG"; then echo "reset to version [$TAG] failed! aborting restore" exit 1 fi echo "****************************************" - echo "Step 4: restore contents of backup" + echo "Step 8: restore contents of backup" # we use cp not mv because of not empty directories in destination sudo cp -v -p -r "${WORKING_DIR}/openWB/." "${OPENWB_BASE_DIR}/" if [[ -f "$WORKING_DIR/configuration.json" ]]; then @@ -60,7 +62,7 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" echo "Backup does not contain mosquitto_ctrl. Skipping restore." fi echo "****************************************" - echo "Step 5.1: restore mosquitto db" + echo "Step 8.1: restore mosquitto db" if [[ -f "${WORKING_DIR}/mosquitto/mosquitto.db" ]]; then sudo mv -v -f "${WORKING_DIR}/mosquitto/mosquitto.db" "$MOSQUITTO_DB_DIR/mosquitto.db" sudo chown mosquitto:mosquitto "$MOSQUITTO_DB_DIR/mosquitto.db" @@ -81,7 +83,7 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" echo "Backup does not contain local mosquitto.db. Skipping restore." fi echo "****************************************" - echo "Step 5.2: restore mosquitto configuration" + echo "Step 8.2: restore mosquitto configuration" if [[ -d "${WORKING_DIR}/conf_local.d" ]]; then # remove old configuration sudo rm -v -r "$MOSQUITTO_CONF_DIR/conf_local.d" @@ -92,17 +94,17 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" fi # already done in prepare_restore.sh # echo "****************************************" - # echo "Step 5.3: clean mosquitto configuration, will be recreated on next start" + # echo "Step 8.3: clean mosquitto configuration, will be recreated on next start" # sudo rm -v -f "$MOSQUITTO_CONF_DIR/conf.d/openwb-*.conf" echo "****************************************" - echo "Step 6: restore boot file" + echo "Step 9: restore boot file" if [[ -f "${WORKING_DIR}/boot/config.txt" ]]; then sudo mv -v -f "${WORKING_DIR}/boot/config.txt" "/boot/" else echo "Backup does not contain boot file. Skipping restore." fi echo "****************************************" - echo "Step 7: cleanup after restore" + echo "Step 10: cleanup after restore" sudo rm "$SOURCE_FILE" sudo rm -R "$WORKING_DIR" echo "****************************************" From e80273eb845fd8e7e1c39b7d547c662114f6e226 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Thu, 9 Apr 2026 09:24:45 +0200 Subject: [PATCH 3/4] fix charge point get_values in secure mode --- .../modules/chargepoints/external_openwb/chargepoint_module.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/modules/chargepoints/external_openwb/chargepoint_module.py b/packages/modules/chargepoints/external_openwb/chargepoint_module.py index 5814113e22..c0b162e4c8 100644 --- a/packages/modules/chargepoints/external_openwb/chargepoint_module.py +++ b/packages/modules/chargepoints/external_openwb/chargepoint_module.py @@ -70,7 +70,8 @@ def on_message(client, userdata, message): on_connect, on_message, host=self.config.configuration.ip_address, - port=1883).start_finite_loop() + port=1886 if self.config.configuration.ip_address == "localhost" else 1883 + ).start_finite_loop() if received_topics: log.debug(f"Empfange MQTT Daten für Ladepunkt {self.config.id}: {received_topics}") From 77bed57826c7097153fbead538ab9a5b80095c52 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Thu, 9 Apr 2026 09:55:06 +0200 Subject: [PATCH 4/4] review --- packages/helpermodules/command.py | 20 +++++++------- packages/helpermodules/subdata.py | 2 +- runs/prepare_restore.sh | 6 ++--- runs/restore.sh | 44 ++++++++++--------------------- 4 files changed, 28 insertions(+), 44 deletions(-) diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index d5d32984bd..f03fd86884 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -209,7 +209,7 @@ def addIoAction(self, connection_id: str, payload: dict) -> None: self.max_id_io_action = new_id Pub().pub("openWB/set/command/max_id/io_action", self.max_id_io_action) # add ACL roles for IO action access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: add_acl_role("io-action--access", new_id) pub_user_message( payload, connection_id, @@ -220,7 +220,7 @@ def removeIoAction(self, connection_id: str, payload: dict) -> None: if self.max_id_io_action >= payload["data"]["id"]: ProcessBrokerBranch(f'io/action/{payload["data"]["id"]}/').remove_topics() # remove ACL roles for IO action access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: remove_acl_role("io-action--access", payload["data"]["id"]) pub_user_message(payload, connection_id, f'IO-Aktion mit ID \'{payload["data"]["id"]}\' gelöscht.', MessageType.SUCCESS) @@ -243,7 +243,7 @@ def addIoDevice(self, connection_id: str, payload: dict) -> None: self.max_id_io_device = new_id Pub().pub("openWB/set/command/max_id/io_device", self.max_id_io_device) # add ACL roles for IO device access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: add_acl_role("io-device--access", new_id) if device_default["output"]["digital"] or device_default["output"]["analog"]: add_acl_role("io-device--write-access", new_id) @@ -259,7 +259,7 @@ def removeIoDevice(self, connection_id: str, payload: dict) -> None: ProcessBrokerBranch(f'system/io/{payload["data"]["id"]}/').remove_topics() ProcessBrokerBranch(f'io/states/{payload["data"]["id"]}/').remove_topics() # remove ACL roles for IO device access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: remove_acl_role("io-device--access", payload["data"]["id"]) remove_acl_role("io-device--write-access", payload["data"]["id"]) pub_user_message(payload, connection_id, f'IO-Gerät mit ID \'{payload["data"]["id"]}\' gelöscht.', @@ -288,7 +288,7 @@ def setup_added_chargepoint(): if self.max_id_vehicle == -1: self.addVehicle("addChargepoint", {}) # add ACL roles for charge point access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: add_acl_role("chargepoint--access", new_id) if chargepoint_config["type"] == "mqtt": add_acl_role("chargepoint--write-access", new_id) @@ -397,7 +397,7 @@ def removeChargepoint(self, connection_id: str, payload: dict) -> None: else: remove_display_user(cp_ip) # remove ACL roles for charge point access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: remove_acl_role("chargepoint--access", cp_id) remove_acl_role("chargepoint--write-access", cp_id) ProcessBrokerBranch(f'chargepoint/{cp_id}/').remove_topics() @@ -692,7 +692,7 @@ def set_default(topic: str, defaults: dict): Pub().pub("openWB/set/command/max_id/hierarchy", self.max_id_hierarchy) # add ACL roles for component access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: add_acl_role(f"{general_type.value}--access", new_id) pub_user_message( payload, connection_id, @@ -708,7 +708,7 @@ def removeComponent(self, connection_id: str, payload: dict) -> None: branch = f'system/device/{payload["data"]["deviceId"]}/component/{payload["data"]["id"]}/' ProcessBrokerBranch(branch).remove_topics() # remove ACL roles for component access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: remove_acl_role(f"{special_to_general_type_mapping(payload['data']['type']).value}--access", payload["data"]["id"]) remove_acl_role(f"{special_to_general_type_mapping(payload['data']['type']).value}--write-access", @@ -770,7 +770,7 @@ def addVehicle(self, connection_id: str, payload: dict) -> None: if self.max_id_ev_template == -1: self.addEvTemplate("addVehicle", {}) # add ACL roles for vehicle access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: add_acl_role("vehicle--access", new_id) pub_user_message(payload, connection_id, f'Neues EV mit ID \'{new_id}\' hinzugefügt.', MessageType.SUCCESS) @@ -784,7 +784,7 @@ def removeVehicle(self, connection_id: str, payload: dict) -> None: Pub().pub(f'openWB/vehicle/{payload["data"]["id"]}', "") ProcessBrokerBranch(f'vehicle/{payload["data"]["id"]}/').remove_topics() # remove ACL roles for vehicle access, if user management is active - if data.data.system_data["system"].data["security"]["user_management_active"]: + if SubData.system_data["system"].data["security"]["user_management_active"]: remove_acl_role("vehicle--access", payload["data"]["id"]) remove_acl_role("vehicle--write-access", payload["data"]["id"]) pub_user_message( diff --git a/packages/helpermodules/subdata.py b/packages/helpermodules/subdata.py index 4d3e47c4f2..38b26d5490 100644 --- a/packages/helpermodules/subdata.py +++ b/packages/helpermodules/subdata.py @@ -314,7 +314,7 @@ def process_vehicle_topic(self, client: mqtt.Client, var: Dict[str, ev.Ev], msg: var["ev"+index].soc_module = mod.create_vehicle(config, index) client.subscribe(f"openWB/vehicle/{index}/soc_module/calculated_soc_state", 2) client.subscribe(f"openWB/vehicle/{index}/soc_module/general_config", 2) - if var["system"].data["security"]["user_management_active"]: + if self.system_data["system"].data["security"]["user_management_active"]: if config.type == "mqtt": add_acl_role("vehicle--write-access", int(index)) else: diff --git a/runs/prepare_restore.sh b/runs/prepare_restore.sh index a4b0e0ac84..184c629dd7 100755 --- a/runs/prepare_restore.sh +++ b/runs/prepare_restore.sh @@ -57,17 +57,17 @@ declare resultStatus GIT_REMOTE="origin" BRANCH=$(<"$WORKING_DIR/GIT_BRANCH") # TAG=$(<"$WORKING_DIR/GIT_HASH") - echo "Step 5.1: fetch info from git" + echo "Step 4.1: fetch info from git" if ! git -C "$OPENWB_BASE_DIR" fetch -v "$GIT_REMOTE"; then resultMessage="Beim Abgleich mit dem openWB Git ist ein Fehler aufgetreten!" resultStatus=1 else - echo "Step 5.2: verify branch \"$BRANCH\" from archive" + echo "Step 4.2: verify branch \"$BRANCH\" from archive" if ! git -C "$OPENWB_BASE_DIR" branch | grep "$BRANCH"; then resultMessage="Der Entwicklungszweig \"$BRANCH\" des Archivs ist ungültig." resultStatus=1 else - echo "Step 5.3: clean mosquitto configuration, will be recreated on next boot" + echo "Step 4.3: clean mosquitto configuration, will be recreated on next boot" sudo rm -v -f /etc/mosquitto/conf.d/openwb-*.conf sudo rm -v -f "/var/lib/mosquitto/dynamic-security.json" rm -v -f "/home/openwb/.config/mosquitto_ctrl" diff --git a/runs/restore.sh b/runs/restore.sh index 0cfad9b995..e928e19115 100755 --- a/runs/restore.sh +++ b/runs/restore.sh @@ -10,45 +10,33 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" { echo "$(date +"%Y-%m-%d %H:%M:%S") Restore of backup started..." - # prepare_restore.sh ends with step 5, so we continue with step 6 here echo "****************************************" - # already done in prepare_restore.sh - # echo "Step 1: validating extracted files" - # if [[ ! -f "$WORKING_DIR/SHA256SUM" ]] || - # [[ ! -f "$WORKING_DIR/GIT_BRANCH" ]] || - # [[ ! -f "$WORKING_DIR/GIT_HASH" ]] || - # [[ ! -d "$WORKING_DIR/openWB" ]] || - # [[ ! -f "$WORKING_DIR/mosquitto/mosquitto.db" ]] || - # [[ ! -f "$WORKING_DIR/mosquitto_local/mosquitto.db" ]]; then - # echo "this is not a complete archive! aborting restore" - # exit 1 - # fi - # if ! (cd "$WORKING_DIR" && sudo sha256sum --quiet --check "SHA256SUM"); then - # echo "some files were modified or removed! aborting restore" - # exit 1 - # fi - # echo "****************************************" - echo "Step 6: stop mosquitto services" + # already done in prepare_restore.sh: + # Step 1: creating working directory + # Step 2: extract archive to working directory + # Step 3: validating extracted files + # Step 4: sync with git + echo "Step 5: stop mosquitto services" # no need to stop openwb2.service as we are in pre start script sudo systemctl stop mosquitto.service mosquitto_local.service # give systemctl some time to finish, may be unnecessary? sleep 2 echo "****************************************" - echo "Step 7: checkout matching git branch and tag" + echo "Step 6: checkout matching git branch and tag" BRANCH=$(<"$WORKING_DIR/GIT_BRANCH") TAG=$(<"$WORKING_DIR/GIT_HASH") - echo "Step 7.1: checkout branch: $BRANCH" + echo "Step 6.1: checkout branch: $BRANCH" if ! git -C "$OPENWB_BASE_DIR" checkout --force "$BRANCH"; then echo "checkout of branch \"$BRANCH\" failed! aborting restore" exit 1 fi - echo "Step 7.2: reset to matching version: [$TAG]" + echo "Step 6.2: reset to matching version: [$TAG]" if ! git -C "$OPENWB_BASE_DIR" reset --hard "$TAG"; then echo "reset to version [$TAG] failed! aborting restore" exit 1 fi echo "****************************************" - echo "Step 8: restore contents of backup" + echo "Step 7: restore contents of backup" # we use cp not mv because of not empty directories in destination sudo cp -v -p -r "${WORKING_DIR}/openWB/." "${OPENWB_BASE_DIR}/" if [[ -f "$WORKING_DIR/configuration.json" ]]; then @@ -62,7 +50,7 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" echo "Backup does not contain mosquitto_ctrl. Skipping restore." fi echo "****************************************" - echo "Step 8.1: restore mosquitto db" + echo "Step 7.1: restore mosquitto db" if [[ -f "${WORKING_DIR}/mosquitto/mosquitto.db" ]]; then sudo mv -v -f "${WORKING_DIR}/mosquitto/mosquitto.db" "$MOSQUITTO_DB_DIR/mosquitto.db" sudo chown mosquitto:mosquitto "$MOSQUITTO_DB_DIR/mosquitto.db" @@ -83,7 +71,7 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" echo "Backup does not contain local mosquitto.db. Skipping restore." fi echo "****************************************" - echo "Step 8.2: restore mosquitto configuration" + echo "Step 7.2: restore mosquitto configuration" if [[ -d "${WORKING_DIR}/conf_local.d" ]]; then # remove old configuration sudo rm -v -r "$MOSQUITTO_CONF_DIR/conf_local.d" @@ -92,19 +80,15 @@ LOG_FILE="$OPENWB_BASE_DIR/data/log/restore.log" else echo "Backup does not contain mosquitto configuration. Skipping restore." fi - # already done in prepare_restore.sh - # echo "****************************************" - # echo "Step 8.3: clean mosquitto configuration, will be recreated on next start" - # sudo rm -v -f "$MOSQUITTO_CONF_DIR/conf.d/openwb-*.conf" echo "****************************************" - echo "Step 9: restore boot file" + echo "Step 8: restore boot file" if [[ -f "${WORKING_DIR}/boot/config.txt" ]]; then sudo mv -v -f "${WORKING_DIR}/boot/config.txt" "/boot/" else echo "Backup does not contain boot file. Skipping restore." fi echo "****************************************" - echo "Step 10: cleanup after restore" + echo "Step 9: cleanup after restore" sudo rm "$SOURCE_FILE" sudo rm -R "$WORKING_DIR" echo "****************************************"