Files
UGREEN-NAS/root/usr/sbin/ugreen-led-init
Cantibra 7e82c23ea2
All checks were successful
UGREEN NAS (Trixie) / UGREEN NAS [amd64] (push) Successful in 17s
Initialize Git Repository: 'UGREEN-NAS'
2026-01-26 06:10:56 +01:00

52 lines
848 B
Bash
Executable File

#!/usr/bin/env bash
###
#
# Options Section
#
###
set -u
set -o pipefail
###
#
# Function Section
#
###
function load_module () {
MODULE="${1}"
if ! /usr/sbin/lsmod | /usr/bin/grep --quiet "${MODULE}"; then
/usr/sbin/modprobe "${MODULE}"
fi
}
###
#
# Runtime Environment
#
###
load_module 'i2c_dev'
load_module 'led_ugreen'
I2C_DEV=$(/usr/sbin/i2cdetect -l | /usr/bin/grep 'SMBus I801 adapter' | grep --perl-regexp --only-matching 'i2c-\d+')
if [[ -n "${I2C_DEV}" ]]; then
DEV_PATH="/sys/bus/i2c/devices/$I2C_DEV/${I2C_DEV/i2c-/}-003a"
if [[ -d "${DEV_PATH}" ]]; then
DEV_NAME=$(/usr/bin/cat "${DEV_PATH}/name")
fi
if [[ ! -d "${DEV_PATH}" ]]; then
/usr/bin/echo 'led-ugreen 0x3a' > "/sys/bus/i2c/devices/${I2C_DEV}/new_device"
elif [[ "${DEV_NAME}" != 'led-ugreen' ]]; then
exit 1
fi
else
exit 1
fi