Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

armbian-led-state: avoid binary parameters, other minor cleanups #7337

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Unit]
Description=Armbian leds state
After=timers.target
After=sysinit.target
Conflicts=shutdown.target
DefaultDependencies=no

Expand Down
17 changes: 11 additions & 6 deletions packages/bsp/common/usr/lib/armbian/armbian-led-state-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ function store_led() {

# In case the trigger is any of the kbd-*, don't store any other parameter
# This avoids num/scroll/capslock from being restored at startup
# In case trigger is representing link-state for any network, don't store its previous state
# This avoids ghost wan/lan/etc (led up while cable unplugged)
[[ "$TRIGGER_VALUE" =~ kbd-* || "$TRIGGER_VALUE" == *":link" ]] && return
[[ "$TRIGGER_VALUE" =~ kbd-* ]] && return

COMMAND_PARAMS="$CMD_FIND $PATH/ -maxdepth 1 -type f ! -iname uevent ! -iname trigger -perm /u+w -printf %f\\n"
PARAMS=$($COMMAND_PARAMS)

# In case trigger is representing link-state for any network, use
# bash substitution to remove the brightness parameter and avoid
# ghost wan/lan/etc (led up while cable unplugged)
[[ "$TRIGGER_VALUE" == *":link" ]] && PARAMS=${PARAMS//"brightness"/}

for PARAM in $PARAMS; do

PARAM_PATH="$PATH/$PARAM"
VALUE=$(<$PARAM_PATH)

# If the variable contains non-printable characters
# suppose it contains binary and skip it
[[ "$VALUE" =~ [[:cntrl:]] ]] && continue

echo "$PARAM=$VALUE" >> $DESTINATION

done
Expand All @@ -60,9 +67,7 @@ for LED in /sys/class/leds/*; do
[[ -d "$LED" ]] || continue

# Skip saving state for directories starting with enP e.g. enP1p1s0-0::lan enP2p1s0-2::lan etc. etc.
if [[ "$(/usr/bin/basename "$LED")" == enP* ]]; then
continue
fi
[[ "$(/usr/bin/basename "$LED")" == enP* ]] && continue

store_led $LED $STATE_PATH
echo >> $STATE_PATH
Expand Down