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

DietPi-LED_control | Major rework #3397

Merged
merged 16 commits into from
Feb 27, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes / Improvements / Optimisations:
- Pine H64 | Initial hardware identifier (ID: 45) and support for this device has been added to DietPi. Many thanks to @unixino for doing this request: https://github.com/MichaIng/DietPi/issues/3286
- ROCK Pi S | Initial hardware identifier (ID: 73) and support for this device has been added to DietPi. Many thanks to @lwqcz for doing this request: https://github.com/MichaIng/DietPi/issues/3365
- Sparky SBC | Updated kernel drivers and SBC-specific service and config files
- DietPi-LED_control | LED trigger choices are now applied via udev rules, existing settings are migrated on DietPi-Update. This allows to skip running this script at boot and simplify the preboot script, which both reduces boot time a bid. Additionally, applied LED triggers can now be reset to system defaults, which removes related udev rules. Since the script is now for interactive usage only, it has been moved to /DietPi/dietpi/dietpi-led_control and an alias has been added to call it from console via "dietpi-led_control" command.
- DietPi-Cron | Allows now to set the cron job output mail recipient. Cron mails are disabled by default since no MTA is preconfigured on DietPi. Additionally the execution times are now shown more clearly in 24h format.
- DietPi-Drive_Manager | GlusterFS fstab entries are now preserved. Many thanks to @Sudrien for implementing this addition: https://github.com/MichaIng/DietPi/issues/3374
- DietPi-Software | phpBB: Updated to v3.3.0 which has PHP7.3 support, hence can be installed on all hardware models and distro versions.
Expand Down
4 changes: 2 additions & 2 deletions dietpi/dietpi-config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#////////////////////////////////////
#
# Info:
# - Filename: /{DietPi,boot}/dietpi/dietpi-config
# - Location: /{DietPi,boot}/dietpi/dietpi-config
#
# Usage:
# dietpi-config iMENUINDEX iEXITONBACK
Expand Down Expand Up @@ -616,7 +616,7 @@ A long (or insufficiently manufactured) cable may required a higher boost settin

elif (( $G_WHIP_RETURNED_VALUE == 14 )); then

/DietPi/dietpi/func/dietpi-led_control
/DietPi/dietpi/dietpi-led_control

elif (( $G_WHIP_RETURNED_VALUE == 16 )); then

Expand Down
167 changes: 167 additions & 0 deletions dietpi/dietpi-led_control
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/bin/bash
{
#////////////////////////////////////
# DietPi LED control Script
#
#////////////////////////////////////
# Created by Daniel Knight / [email protected] / dietpi.com
#
#////////////////////////////////////
#
# Info:
# - Location: /{DietPi,boot}/dietpi/dietpi-led_control
# - Whiptail menu to select LED triggers for all available /sys/class/leds/ entries
# - Applies choices immediately and creates udev rules to apply on every boot
#
#////////////////////////////////////

# Import DietPi-Globals --------------------------------------------------------------
. /DietPi/dietpi/func/dietpi-globals
G_PROGRAM_NAME='DietPi-LED_Control'
G_CHECK_ROOT_USER
G_CHECK_ROOTFS_RW
G_INIT
# Import DietPi-Globals --------------------------------------------------------------

#/////////////////////////////////////////////////////////////////////////////////////
# Variables and Funktions
#/////////////////////////////////////////////////////////////////////////////////////
FP_UDEV_RULES='/etc/udev/rules.d/dietpi-led_control.rules'
aNAME=()
aTRIGGERS_AVAILABLE=()
aTRIGGER_CURRENT=()
aTRIGGER_SELECTED=()

Init(){

local fp i=0
for fp in /sys/class/leds/*
do

[[ -e $fp ]] || continue
((i++))
aNAME[$i]=${fp##*/}
aTRIGGERS_AVAILABLE[$i]=$(<$fp/trigger)
aTRIGGER_CURRENT[$i]=${aTRIGGERS_AVAILABLE[$i]##*[}
aTRIGGER_CURRENT[$i]=${aTRIGGER_CURRENT[$i]%%]*}
aTRIGGERS_AVAILABLE[$i]=${aTRIGGERS_AVAILABLE[$i]//[][]}
if [[ -f $FP_UDEV_RULES && $(<$FP_UDEV_RULES) == *KERNEL==\"${aNAME[$i]}\"* ]]; then

aTRIGGER_SELECTED[$i]=$(sed -n "/KERNEL==\"${aNAME[$i]}\"/{s/^.*ATTR{trigger}=\"//;s/\".*$//p;q}" $FP_UDEV_RULES)

fi

done

if (( $i == 0 )); then

G_DIETPI-NOTIFY 1 'No LED devices found in /sys/class/leds/. Exiting...'
TARGETMENUID=-1 # Exit

fi

}

#/////////////////////////////////////////////////////////////////////////////////////
# Menu System
#/////////////////////////////////////////////////////////////////////////////////////
TARGETMENUID=0
SELECTED_LED=0

# TARGETMENUID=0
Menu_Main(){

G_WHIP_MENU_ARRAY=('Reset' 'Reset all LED triggers')

local i
for i in ${!aNAME[@]}
do

G_WHIP_MENU_ARRAY+=($i ": ${aNAME[$i]} [${aTRIGGER_CURRENT[$i]}]")

done

G_WHIP_BUTTON_CANCEL_TEXT='Exit'
if ! G_WHIP_MENU 'Please select an LED to configure its trigger:'; then

TARGETMENUID=-1 # Exit

elif [[ $G_WHIP_RETURNED_VALUE == 'Reset' ]]; then

[[ ! -f $FP_UDEV_RULES ]] || G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD rm $FP_UDEV_RULES || return 1
aTRIGGER_SELECTED=()
G_WHIP_MSG 'All LED triggers have been reset to system defaults.\n\nThis will become active from next reboot.'

else

SELECTED_LED=$G_WHIP_RETURNED_VALUE
TARGETMENUID=1 # Menu_LED

fi

}

# TARGETMENUID=1
Menu_LED(){

TARGETMENUID=0 # Menu_Main

G_WHIP_MENU_ARRAY=('Reset' "Reset ${aNAME[$SELECTED_LED]} trigger")

local i
for i in ${aTRIGGERS_AVAILABLE[$SELECTED_LED]}
do

G_WHIP_MENU_ARRAY+=($i '')

done

G_WHIP_DEFAULT_ITEM=${aTRIGGER_CURRENT[$SELECTED_LED]}
if ! G_WHIP_MENU "Please select a trigger for ${aNAME[$SELECTED_LED]}:"; then

return

elif [[ $G_WHIP_RETURNED_VALUE == 'Reset' ]]; then

G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD sed -i "/KERNEL==\"${aNAME[$SELECTED_LED]}\"/d" $FP_UDEV_RULES || return 1
unset aTRIGGER_SELECTED[$SELECTED_LED]
G_WHIP_MSG "LED trigger for ${aNAME[$SELECTED_LED]} has been reset to system defaults.\n\nThis will become active from next reboot."
[[ ${aTRIGGER_SELECTED[@]} || ! -f $FP_UDEV_RULES ]] || G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD rm $FP_UDEV_RULES || return 1

else

G_DIETPI-NOTIFY 2 "Applying trigger \e[33m$G_WHIP_RETURNED_VALUE\e[90m to LED \e[33m${aNAME[$SELECTED_LED]}"
echo "$G_WHIP_RETURNED_VALUE" > "/sys/class/leds/${aNAME[$SELECTED_LED]}/trigger" || return 1
aTRIGGER_CURRENT[$SELECTED_LED]=$G_WHIP_RETURNED_VALUE
[[ -f $FP_UDEV_RULES ]] || G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD touch $FP_UDEV_RULES || return 1
G_CONFIG_INJECT "SUBSYSTEM==\"leds\", KERNEL==\"${aNAME[$SELECTED_LED]}\"" "SUBSYSTEM==\"leds\", KERNEL==\"${aNAME[$SELECTED_LED]}\", ACTION==\"add\", ATTR{trigger}=\"${aTRIGGER_CURRENT[$SELECTED_LED]}\"" $FP_UDEV_RULES
aTRIGGER_SELECTED[$SELECTED_LED]=aTRIGGER_CURRENT[$SELECTED_LED]

fi

}

#/////////////////////////////////////////////////////////////////////////////////////
# Main Loop
#/////////////////////////////////////////////////////////////////////////////////////
#-----------------------------------------------------------------------------------
Init
#-----------------------------------------------------------------------------------
while (( $TARGETMENUID >= 0 ))
do

if (( $TARGETMENUID == 1 )); then

Menu_LED

else

Menu_Main

fi

done
#-----------------------------------------------------------------------------------
exit
#-----------------------------------------------------------------------------------
}
7 changes: 2 additions & 5 deletions dietpi/func/dietpi-banner
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#////////////////////////////////////
#
# Info:
# - Filename: /{DietPi,boot}/dietpi/func/dietpi-banner
# - Location: /{DietPi,boot}/dietpi/func/dietpi-banner
# - Checks /DietPi/dietpi/.update_available
#
# Usage:
Expand Down Expand Up @@ -154,17 +154,14 @@ $GREEN_LINE"

Print_Credits(){

echo -e " ${aCOLOUR[2]}DietPi Team : MichaIng (lead), Daniel Knight (founder)"
echo -e " ${aCOLOUR[2]}DietPi Team : MichaIng (lead), Daniel Knight (founder), Joulinar (support)"

[[ -f '/DietPi/dietpi/.prep_info' ]] && mawk 'NR==1 {sub(/^0$/,"DietPi Core Team");a=$0} NR==2 {print " Image : "a" (pre-image: "$0")"}' /DietPi/dietpi/.prep_info

echo ' Web : https://dietpi.com | https://twitter.com/dietpi_
Patreon Legends : Bryce
Donate : https://dietpi.com/#donate'

local image_additional_credits=$(mawk 'NR==8' /DietPi/dietpi/.hw_model 2>&1)
[[ $image_additional_credits ]] && echo " Device image possible thanks to: $image_additional_credits"

echo -e " DietPi Hosting : Powered by https://myvirtualserver.com$COLOUR_RESET\n"

# Update available?
Expand Down
6 changes: 3 additions & 3 deletions dietpi/func/dietpi-globals
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ _EOF_
# Device details
# NB: https://github.com/MichaIng/DietPi/blob/dev/dietpi/func/dietpi-obtain_hw_model
# - Declare
G_HW_MODEL=${G_HW_MODEL:--1}
G_HW_MODEL_DESCRIPTION=${G_HW_MODEL_DESCRIPTION:-NULL}
G_HW_MODEL=${G_HW_MODEL:-22}
G_HW_MODEL_DESCRIPTION=${G_HW_MODEL_DESCRIPTION:-Generic Device}
G_HW_ARCH=${G_HW_ARCH:-0}
G_HW_ARCH_DESCRIPTION=$(uname -m)
G_HW_CPUID=${G_HW_CPUID:-0}
Expand Down Expand Up @@ -505,7 +505,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i '[d]ietpi')"; then
alias dietpi-explorer='/DietPi/dietpi/dietpi-explorer'
alias dietpi-banner='/DietPi/dietpi/func/dietpi-banner 2'
alias dietpi-justboom='/DietPi/dietpi/misc/dietpi-justboom'

alias dietpi-led_control='/DietPi/dietpi/dietpi-led_control'
alias cpu='/DietPi/dietpi/dietpi-cpuinfo'

# - 1337 moments ;)
Expand Down
Loading