#!/usr/bin/bash ACTION="$1" source /etc/default/cec-control # OVERRIDE WITH DEFAULTS IF NOT SET CEC_TVID=${CEC_TVID:-0} CEC_WAKE=${CEC_WAKE:-true} CEC_SETSOURCE=${CEC_SETSOURCE:-true} CEC_ONPOWEROFF_STANDBY=${CEC_ONPOWEROFF_STANDBY:-true} CEC_ONSLEEP_STANDBY=${CEC_ONSLEEP_STANDBY:-false} CEC_OSD_NAME=${CEC_OSD_NAME:-$(hostname)} args=() args+=( "--single-command" ) args+=( "--log-level 1" ) args+=( "--osd-name $CEC_OSD_NAME" ) # Conditionally apply a port number override if one is set [[ -n "$CEC_PORT_NUMBER" ]] && args+=( "--port $CEC_PORT_NUMBER" ) # Helper functions to send activate and standby messages to the CEC bus # We loop through TVIDs to cover cases where you might have multiple devices # to control (eg: a TV, an audio system, and some sort of tuner device) function perform_standby { for id in $CEC_TVID; do echo "standby $id" | cec-client ${args[@]} done } function perform_activate { for id in $CEC_TVID; do echo "on $id" | cec-client ${args[@]} done if [ "$CEC_SETSOURCE" = true ]; then echo "as" | cec-client ${args[@]} fi } # Run specified actions if [ "${ACTION}" = "onboot" ] && [ "$CEC_WAKE" = true ]; then perform_activate elif [ "${ACTION}" = "onpoweroff" ] && [ "$CEC_ONPOWEROFF_STANDBY" = true ]; then perform_standby elif [ "${ACTION}" = "onsleep" ] && [ "$CEC_ONSLEEP_STANDBY" = true ]; then perform_standby fi