1#!/bin/bash
2
3action=$1
4devpath=$2
5of_fullname=$3
6
7#Use of_fullname if it's there, otherwise use devpath.
8function use_devpath(){
9    path=$devpath
10
11    if [[ "$path" =~ (.*)/hwmon/hwmon[0-9]+$ ]];
12    then
13        path=${BASH_REMATCH[1]}
14    fi
15    echo "${path}"
16}
17
18path=$of_fullname
19if [ -z "${path}" ]@FORCE_DEVPATH@
20then
21    path="$(use_devpath)"
22else
23    override_with_devpath=(@OVERRIDE_WITH_DEVPATH@)
24    if [[ "$path" =~ .*/(.*)$ ]];
25    then
26        of_name="${BASH_REMATCH[1]}"
27        for i in ${!override_with_devpath[@]}; do
28            if [[ "${override_with_devpath[$i]}" == "${of_name}" ]];
29            then
30                path="$(use_devpath)"
31                break
32            fi
33        done
34    fi
35fi
36
37# Needed to re-do escaping used to avoid bitbake separator conflicts
38path="${path//:/--}"
39# Needed to escape prior to being used as a unit argument
40path="$(systemd-escape "$path")"
41systemctl --no-block "$action" "xyz.openbmc_project.Hwmon@$path.service"
42