Skip to content

Commit

Permalink
v6.29 (#3397)
Browse files Browse the repository at this point in the history
+ DietPi-LED_control | Major rework: Chosen LED triggers are now applied as udev rules so that this script does not need to be executed on boot. Reset options have been added to remove udev rules. Location has been moved to parent, since now it is for interactive execution only. A shell alias has been added for quick access via "dietpi-led_control".
+ DietPi-Patch | Convert old DietPi-LED_control settings to udev rules and remove script from old location
+ DietPi-PreBoot | Remove DietPi-LED_control call, since LED triggers are now applied via udev rules
+ DietPi-PreBoot | Do not use G_THREAD, since DietPi-Set_CPU is the only larger call being done, hence no benefit of concurrency
+ DietPi-PreBoot | Do not load DietPi-Globals, since checking for RPi is the only left reason, which can be done much simpler
+ DietPi-PreBoot | Obtain hardware info only if resulting file is missing, and on RPi to allow SDcard swapping. For non-RPi models, the result can only change after DietPi updates, and DietPi-Patch forces a hardware info reload on every execution.
+ DietPi-Config | DietPi-LED_control script has been moved to parent dir
+ DietPi-Login | Since PROMPT_COMMAND() is called from regular interactive shell with bashrc sourced, assure that "rm /tmp/dietpi-process.pid" is non-interactive and silent, regardless of applied "rm" interactive or verbose aliases.
+ DietPi-Obtain_HW_model | In any unexpected hardware identifier case, revert to "Generic Device" (ID: 22) to assure that our scripts cannot do wrong assumptions, e.g. assume RPi because of missing identifier file only (( $G_HW_MODEL < 10 )).
+ DietPi-Obtain_HW_model | Remove $IMAGE_ADDITIONAL_CREDITS, since this doubles with .prep_info. If no .prep_info is present (very old images), convert old $IMAGE_ADDITIONAL_CREDITS entry via pre-patches instead
+ DietPi-Banner | Remove $image_additional_credits line in favour of pre-image line which basically double each other
+ DietPi-Banner | Add Joulinar to DietPi Team line, deserves credit for outstanding support on GitHub and Forums
+ DietPi-Pre-patch | Convert .hw_model additional credits line to .prep_info pre-image. This must be done as pre-patch, since DietPi-Patch calls DietPi-Obtain_HW_model, which clears the line
+ DietPi-Globals | Use hardware ID 22 (Generic Device) as general fallback to assure that it is never falsely identified as RPi by (( $G_HW_MODEL < 10 )).
  • Loading branch information
MichaIng authored Feb 27, 2020
1 parent 9939ef9 commit 4b302e1
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 258 deletions.
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

0 comments on commit 4b302e1

Please sign in to comment.