xref: /openbmc/phosphor-hwmon/start_hwmon.sh.in (revision 670d92a775a14148b582c479f1f5705e94167c8f)
124b8b4beSWilly Tu#!/bin/bash
224b8b4beSWilly Tu
324b8b4beSWilly Tuaction=$1
424b8b4beSWilly Tudevpath=$2
524b8b4beSWilly Tuof_fullname=$3
624b8b4beSWilly Tu
724b8b4beSWilly Tu#Use of_fullname if it's there, otherwise use devpath.
824b8b4beSWilly Tufunction use_devpath(){
924b8b4beSWilly Tu    path=$devpath
1024b8b4beSWilly Tu
1124b8b4beSWilly Tu    if [[ "$path" =~ (.*)/hwmon/hwmon[0-9]+$ ]];
1224b8b4beSWilly Tu    then
1324b8b4beSWilly Tu        path=${BASH_REMATCH[1]}
1424b8b4beSWilly Tu    fi
1524b8b4beSWilly Tu    echo "${path}"
1624b8b4beSWilly Tu}
1724b8b4beSWilly Tu
1824b8b4beSWilly Tupath=$of_fullname
19*670d92a7SMatt Spinlerif [ -z "${path}" ]@FORCE_DEVPATH@
2024b8b4beSWilly Tuthen
2124b8b4beSWilly Tu    path="$(use_devpath)"
2224b8b4beSWilly Tuelse
2324b8b4beSWilly Tu    override_with_devpath=(@OVERRIDE_WITH_DEVPATH@)
2424b8b4beSWilly Tu    if [[ "$path" =~ .*/(.*)$ ]];
2524b8b4beSWilly Tu    then
2624b8b4beSWilly Tu        of_name="${BASH_REMATCH[1]}"
2724b8b4beSWilly Tu        for i in ${!override_with_devpath[@]}; do
2824b8b4beSWilly Tu            if [[ "${override_with_devpath[$i]}" == "${of_name}" ]];
2924b8b4beSWilly Tu            then
3024b8b4beSWilly Tu                path="$(use_devpath)"
3124b8b4beSWilly Tu                break
3224b8b4beSWilly Tu            fi
3324b8b4beSWilly Tu        done
3424b8b4beSWilly Tu    fi
3524b8b4beSWilly Tufi
3624b8b4beSWilly Tu
3724b8b4beSWilly Tu# Needed to re-do escaping used to avoid bitbake separator conflicts
3824b8b4beSWilly Tupath="${path//:/--}"
3924b8b4beSWilly Tu# Needed to escape prior to being used as a unit argument
4024b8b4beSWilly Tupath="$(systemd-escape "$path")"
4124b8b4beSWilly Tusystemctl --no-block "$action" "xyz.openbmc_project.Hwmon@$path.service"
42