mirror of
https://github.com/AuxXxilium/arc-addons.git
synced 2024-11-23 21:50:52 +07:00
ledcontrol: rework
Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
parent
a9de2c22b5
commit
6afc8da676
@ -424,6 +424,7 @@ if [ "${1}" = "patches" ]; then
|
||||
|
||||
echo "BOOTDISK=${BOOTDISK}"
|
||||
echo "BOOTDISK_PHYSDEVPATH=${BOOTDISK_PHYSDEVPATH}"
|
||||
echo "${BOOTDISK}" >/usr/addons/bootdisk
|
||||
|
||||
checkSynoboot
|
||||
|
||||
@ -464,4 +465,6 @@ elif [ "${1}" = "late" ]; then
|
||||
SUPPORT_M2_POOL=$(_get_conf_kv support_m2_pool)
|
||||
_set_conf_kv hd "supportnvme" "${SUPPORTNVME}"
|
||||
_set_conf_kv hd "support_m2_pool" "${SUPPORT_M2_POOL}"
|
||||
# export Bootdisk for Ledcontrol
|
||||
cp -vf /usr/addons/bootdisk /tmpRoot/usr/addons/bootdisk
|
||||
fi
|
5
ledcontrol/all/addons/led.conf
Normal file
5
ledcontrol/all/addons/led.conf
Normal file
@ -0,0 +1,5 @@
|
||||
[brightness]
|
||||
night_start=22:00
|
||||
night_end=07:00
|
||||
day_brightness=255
|
||||
night_brightness=64
|
@ -6,14 +6,141 @@
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
UGREEN_LEDS_CLI="/usr/bin/ugreen_leds_cli"
|
||||
SMARTCTL="/usr/bin/smartctl"
|
||||
HDPARM="/usr/bin/hdparm"
|
||||
CONFIG_FILE="/usr/arc/addons/led.conf"
|
||||
|
||||
|
||||
# Funktion, um den SMART-Status einer Festplatte zu überprüfen
|
||||
function check_smart_status() {
|
||||
local device=$1
|
||||
smartctl -H -n standby $device | grep -q "PASSED"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Funktion, um den Power-Status einer Festplatte zu überprüfen, ohne sie aufzuwecken
|
||||
function check_power_status() {
|
||||
local device=$1
|
||||
local status=$(hdparm -C $device | grep -oP '(?<=drive state is: ).*')
|
||||
echo $status
|
||||
}
|
||||
|
||||
# Funktion, um den Load Average-Wert zu ermitteln
|
||||
function get_load_average() {
|
||||
load_average=$(uptime | awk -F'[a-z]:' '{print $2}' | awk -F',' '{print $1}' | tr -d '[:space:]')
|
||||
echo $load_average
|
||||
}
|
||||
|
||||
# Funktion, um zu überprüfen, ob ein Netzwerkinterface verbunden ist
|
||||
function check_network_interface() {
|
||||
local interface=$1
|
||||
ip link show dev $interface | grep -q "state UP"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Funktion, um die aktuelle Helligkeit basierend auf der Konfigurationsdatei zu ermitteln
|
||||
function get_brightness() {
|
||||
local current_time=$(date +%H:%M)
|
||||
local night_start=$(grep -Po '(?<=night_start=).*' $CONFIG_FILE)
|
||||
local night_end=$(grep -Po '(?<=night_end=).*' $CONFIG_FILE)
|
||||
local day_brightness=$(grep -Po '(?<=day_brightness=).*' $CONFIG_FILE)
|
||||
local night_brightness=$(grep -Po '(?<=night_brightness=).*' $CONFIG_FILE)
|
||||
|
||||
if [[ "$current_time" > "$night_start" || "$current_time" < "$night_end" ]]; then
|
||||
echo $night_brightness
|
||||
else
|
||||
echo $day_brightness
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "${1}" = "on" ]; then
|
||||
echo "Enable Ugreen LED"
|
||||
ugreen_leds_cli all -on -color 255 255 255 -brightness 65
|
||||
$UGREEN_LEDS_CLI all -on -color 255 255 255 -brightness 65
|
||||
elif [ "${1}" = "off" ]; then
|
||||
echo "Disable Ugreen LED"
|
||||
ugreen_leds_cli all -off
|
||||
elif [ "${1}" = "blink" ]; then
|
||||
echo "Blink Ugreen LED"
|
||||
ugreen_leds_cli all -blink -color 255 255 255 -brightness 65
|
||||
$UGREEN_LEDS_CLI all -off
|
||||
elif [ "${1}" = "nic" ]; then
|
||||
echo "NIC Ugreen LED"
|
||||
# Get Brightness
|
||||
brightness=$(get_brightness)
|
||||
# NIC Status
|
||||
interface_up=0
|
||||
interfaces=$(ls /sys/class/net/ 2>/dev/null | grep eth)
|
||||
|
||||
for interface in "${interfaces[@]}"; do
|
||||
if check_network_interface $interface; then
|
||||
interface_up=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $interface_up -eq 1 ]]; then
|
||||
$UGREEN_LEDS_CLI netdev -on -color 0 255 0 -brightness $brightness > /dev/null 2>&1
|
||||
else
|
||||
$UGREEN_LEDS_CLI netdev -blink 400 400 -color 255 0 255 -brightness $brightness > /dev/null 2>&1
|
||||
fi
|
||||
elif [ "${1}" = "disk" ]; then
|
||||
# Get Disks
|
||||
devices=$(ls -d /dev/sd[a-z] 2>/dev/null)
|
||||
bootdisk=$(cat /usr/addons/bootdisk)
|
||||
# Disks Smart Check
|
||||
for i in "${!devices[@]}"; do
|
||||
[ "${devices[$i]}" = "/dev/${bootdisk}" ] && continue
|
||||
device=${devices[$i]}
|
||||
disk_number=$((i + 1)) # Disknummer für die LED-Steuerung (disk1, disk2, etc.)
|
||||
color="0 255 0" # Standardfarbe grün
|
||||
|
||||
if check_smart_status $device; then
|
||||
color="0 255 0" # Grün
|
||||
else
|
||||
color="255 0 0" # Rot
|
||||
fi
|
||||
|
||||
power_status=$(check_power_status $device)
|
||||
|
||||
case $power_status in
|
||||
"unknown")
|
||||
$UGREEN_LEDS_CLI disk$disk_number -on -color $color -brightness $brightness > /dev/null 2>&1
|
||||
;;
|
||||
"active/idle")
|
||||
$UGREEN_LEDS_CLI disk$disk_number -blink 500 500 -color $color -brightness $brightness > /dev/null 2>&1
|
||||
;;
|
||||
"standby")
|
||||
$UGREEN_LEDS_CLI disk$disk_number -breath 1000 1000 -color $color -brightness $brightness > /dev/null 2>&1
|
||||
;;
|
||||
*)
|
||||
$UGREEN_LEDS_CLI disk$disk_number -on -color $color -brightness $brightness > /dev/null 2>&1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
elif [ "${1}" = "cpu" ]; then
|
||||
# CPU Load Average
|
||||
if awk "BEGIN {exit !($load_average < 1.0)}"; then
|
||||
blink_on=2000
|
||||
blink_off=2000
|
||||
color="0 255 0" # Grün
|
||||
elif awk "BEGIN {exit !($load_average < 2.0)}"; then
|
||||
blink_on=1500
|
||||
blink_off=1500
|
||||
color="127 255 0" # Gelbgrün
|
||||
elif awk "BEGIN {exit !($load_average < 3.0)}"; then
|
||||
blink_on=1000
|
||||
blink_off=1000
|
||||
color="255 255 0" # Gelb
|
||||
elif awk "BEGIN {exit !($load_average < 4.0)}"; then
|
||||
blink_on=750
|
||||
blink_off=750
|
||||
color="255 127 0" # Orange
|
||||
elif awk "BEGIN {exit !($load_average < 5.0)}"; then
|
||||
blink_on=500
|
||||
blink_off=500
|
||||
color="255 0 0" # Rot
|
||||
else
|
||||
blink_on=250
|
||||
blink_off=250
|
||||
color="255 0 0" # Rot (schnelleres Blinken)
|
||||
fi
|
||||
$UGREEN_LEDS_CLI power -blink $blink_on $blink_off -color $color -brightness $brightness > /dev/null 2>&1
|
||||
fi
|
||||
exit 0
|
@ -11,40 +11,125 @@ if [ "${1}" = "late" ]; then
|
||||
mkdir -p "/tmpRoot/usr/arc/addons/"
|
||||
cp -vf "${0}" "/tmpRoot/usr/arc/addons/"
|
||||
|
||||
cp -vf /usr/lib/modules/i2c* /tmpRoot/usr/lib/modules/
|
||||
cp -vf /usr/bin/ledcontrol.sh /tmpRoot/usr/bin/ledcontrol.sh
|
||||
cp -vf /usr/bin/ugreen_leds_cli /tmpRoot/usr/bin/ugreen_leds_cli
|
||||
modprobe i2c-algo-bit
|
||||
cp -vf /usr/arc/addons/led.conf /tmpRoot/usr/arc/addons/led.conf
|
||||
modprobe i2c-smbus
|
||||
modprobe i2c-i801
|
||||
|
||||
mkdir -p "/tmpRoot/usr/lib/systemd/system"
|
||||
# NIC
|
||||
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol.service"
|
||||
cat > ${DEST} <<EOF
|
||||
[Unit]
|
||||
Description=Adds Ledcontrol for Ugreen
|
||||
Description=NIC Ledcontrol for Ugreen
|
||||
DefaultDependencies=no
|
||||
IgnoreOnIsolate=true
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
Type=oneshot
|
||||
Restart=no
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/bin/ledcontrol.sh on
|
||||
ExecStart=/usr/bin/ledcontrol.sh nic
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants
|
||||
ln -vsf /usr/lib/systemd/system/ledcontrol.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol.service
|
||||
ln -vsf /usr/lib/systemd/system/ledcontrol_disk.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol_disk.service
|
||||
# Disk
|
||||
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol_disk.service"
|
||||
cat > ${DEST} <<EOF
|
||||
[Unit]
|
||||
Description=Disk Ledcontrol for Ugreen
|
||||
DefaultDependencies=no
|
||||
IgnoreOnIsolate=true
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Type=onshot
|
||||
Restart=no
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/bin/ledcontrol.sh disk
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants
|
||||
ln -vsf /usr/lib/systemd/system/ledcontrol_disk.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol_disk.service
|
||||
|
||||
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol_cpu.service"
|
||||
cat > ${DEST} <<EOF
|
||||
[Unit]
|
||||
Description=CPU Ledcontrol for Ugreen
|
||||
DefaultDependencies=no
|
||||
IgnoreOnIsolate=true
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Type=oneshot
|
||||
Restart=no
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/bin/ledcontrol.sh cpu
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants
|
||||
ln -vsf /usr/lib/systemd/system/ledcontrol_cpu.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol_cpu.service
|
||||
# Timer for Disk
|
||||
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol_disk.timer"
|
||||
cat > ${DEST} <<EOF
|
||||
[Unit]
|
||||
Description=Disk Ledcontrol Timer for Ugreen
|
||||
|
||||
[Timer]
|
||||
OnBootSec=5m
|
||||
OnUnitInactiveSec=5m
|
||||
Persistent=true
|
||||
User=root
|
||||
Unit=ledcontrol_disk.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
EOF
|
||||
mkdir -vp /tmpRoot/usr/lib/systemd/system/timers.target.wants
|
||||
ln -vsf /usr/lib/systemd/system/ledcontrol_disk.timer /tmpRoot/usr/lib/systemd/system/timers.target.wants/ledcontrol_disk.timer
|
||||
# Timer for CPU
|
||||
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol_cpu.timer"
|
||||
cat > ${DEST} <<EOF
|
||||
[Unit]
|
||||
Description=CPU Ledcontrol Timer for Ugreen
|
||||
|
||||
[Timer]
|
||||
OnBootSec=5s
|
||||
OnUnitInactiveSec=0.2s
|
||||
Persistent=true
|
||||
User=root
|
||||
Unit=ledcontrol_cpu.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
EOF
|
||||
mkdir -vp /tmpRoot/usr/lib/systemd/system/timers.target.wants
|
||||
ln -vsf /usr/lib/systemd/system/ledcontrol_cpu.timer /tmpRoot/usr/lib/systemd/system/timers.target.wants/ledcontrol_cpu.timer
|
||||
elif [ "${1}" = "uninstall" ]; then
|
||||
echo "Installing addon ledcontrol - ${1}"
|
||||
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol.service"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/ledcontrol.service"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol_disk.service"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/ledcontrol_disk.service"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/multi-user.target.wants/ledcontrol_cpu.service"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/ledcontrol_cpu.service"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/timers.target.wants/ledcontrol_disk.timer"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/ledcontrol_disk.timer"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/timers.target.wants/ledcontrol_cpu.timer"
|
||||
rm -f "/tmpRoot/usr/lib/systemd/system/ledcontrol_cpu.timer"
|
||||
|
||||
[ ! -f "/tmpRoot/usr/arc/revert.sh" ] && echo '#!/usr/bin/env bash' >/tmpRoot/usr/arc/revert.sh && chmod +x /tmpRoot/usr/arc/revert.sh
|
||||
echo "/usr/bin/ledcontrol.sh" >>/tmpRoot/usr/arc/revert.sh
|
||||
|
Loading…
Reference in New Issue
Block a user