You've already forked UGREEN-NAS
This commit is contained in:
51
root/usr/sbin/ugreen-led-init
Executable file
51
root/usr/sbin/ugreen-led-init
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user