#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2018 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### led_exists() { local led="${1}" assert isset led file_exists "/sys/class/leds/${led}" } led_get_supported_triggers() { local led="${1}" if ! led_exists "${led}"; then error "LED ${led} does not exist" return ${EXIT_ERROR} fi local triggers="$(fread "/sys/class/leds/${led}/trigger")" # Filter markers for active trigger print "${triggers//[\[\]]/}" } led_set_trigger() { local led="${1}" local trigger="${2}" assert isset led assert isset trigger local supported_triggers="$(led_get_supported_triggers "${led}")" if ! list_match "${trigger}" ${supported_triggers}; then log DEBUG "Trigger ${trigger} is not supported by LED ${led}" return ${EXIT_ERROR} fi log DEBUG "Setting LED trigger ${trigger} for ${led}" fwrite "/sys/class/leds/${led}/trigger" "${trigger}" }