ledcontrol: update again

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-07-16 21:23:11 +02:00
parent aa4a2f3f93
commit 34243b6b13
2 changed files with 22 additions and 75 deletions

View File

@ -28,7 +28,7 @@ function check_power_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:]')
load_average=$(uptime | awk -F'[a-z]:' '{print $2}' | awk -F',' '{print $1}' | tr -d '[:space:]' | awk -F'.' '{print $1}')
echo $load_average
}
@ -77,12 +77,10 @@ elif [ "${1}" = "nic" ]; then
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)
devices=$(ls -d /dev/sata[1-9] 2>/dev/null)
# bootdisk=$(cat /usr/addons/bootdisk)
# Disks Smart Check
for i in "${!devices[@]}"; do
@ -116,31 +114,20 @@ elif [ "${1}" = "disk" ]; then
done
elif [ "${1}" = "cpu" ]; then
# CPU Load Average
if awk "BEGIN {exit !($load_average < 1.0)}"; then
blink_on=2000
blink_off=2000
load_average=$(get_load_average)
if [ $load_average -lt 1 ]; then
color="0 255 0" # Grün
elif awk "BEGIN {exit !($load_average < 2.0)}"; then
blink_on=1500
blink_off=1500
elif [ $load_average -lt 2 ]; then
color="127 255 0" # Gelbgrün
elif awk "BEGIN {exit !($load_average < 3.0)}"; then
blink_on=1000
blink_off=1000
elif [ $load_average -lt 3 ]; then
color="255 255 0" # Gelb
elif awk "BEGIN {exit !($load_average < 4.0)}"; then
blink_on=750
blink_off=750
elif [ $load_average -lt 4 ]; then
color="255 127 0" # Orange
elif awk "BEGIN {exit !($load_average < 5.0)}"; then
blink_on=500
blink_off=500
elif [ $load_average -lt 5 ]; then
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
$UGREEN_LEDS_CLI power -color $color -brightness $brightness > /dev/null 2>&1
fi
exit 0

View File

@ -22,7 +22,7 @@ if [ "${1}" = "late" ]; then
mkdir -p "/tmpRoot/usr/lib/systemd/system"
# NIC
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol.service"
cat > ${DEST} <<EOF
cat > ${DEST} <<'EOF'
[Unit]
Description=NIC Ledcontrol for Ugreen
DefaultDependencies=no
@ -31,9 +31,9 @@ After=multi-user.target
[Service]
User=root
Type=oneshot
Restart=no
RemainAfterExit=yes
Type=simple
Restart=always
RestartSec=10s
ExecStart=/usr/bin/ledcontrol.sh nic
[Install]
@ -43,7 +43,7 @@ EOF
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
cat > ${DEST} <<'EOF'
[Unit]
Description=Disk Ledcontrol for Ugreen
DefaultDependencies=no
@ -52,9 +52,9 @@ After=multi-user.target
[Service]
User=root
Type=onshot
Restart=no
RemainAfterExit=yes
Type=simple
Restart=always
RestartSec=5min
ExecStart=/usr/bin/ledcontrol.sh disk
[Install]
@ -62,9 +62,9 @@ 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
# CPU
DEST="/tmpRoot/usr/lib/systemd/system/ledcontrol_cpu.service"
cat > ${DEST} <<EOF
cat > ${DEST} <<'EOF'
[Unit]
Description=CPU Ledcontrol for Ugreen
DefaultDependencies=no
@ -73,9 +73,9 @@ After=multi-user.target
[Service]
User=root
Type=oneshot
Restart=no
RemainAfterExit=yes
Type=simple
Restart=always
RestartSec=200ms
ExecStart=/usr/bin/ledcontrol.sh cpu
[Install]
@ -83,42 +83,6 @@ 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}"
@ -128,10 +92,6 @@ elif [ "${1}" = "uninstall" ]; then
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