Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arnesacnussem/fb76560a988bb405b52277df953a6320 to your computer and use it in GitHub Desktop.
Save arnesacnussem/fb76560a988bb405b52277df953a6320 to your computer and use it in GitHub Desktop.
UGREEN dx4600 pro led driver install script for TrueNAS Scale

UGREEN led driver installer for TrueNAS Scale

  1. find url to raw file from pre-built binary branch
  2. run following command and replace the <replace some url here> with the url you find
URL_TO_KO_FILE=<replace some url here>
curl -sSLo- "https://gist.github.com/arnesacnussem/fb76560a988bb405b52277df953a6320/raw/install.sh" | bash - "$URL_TO_KO_FILE" enp3s0

I've tested this on my dx4600 pro with truenas scale 24.04.2 and 24.10.0


This script is for install a pre-built led-ugreen.ko file and config it on TrueNAS Scale

driver source from miskcoo/ugreen_dx4600_leds_controller

script is inspired by comment from sgreiner

pre-built binary from gh-action branch of source repo

as pointed by sgreiner, you can put a startup script to make power led not blinking

echo 0 > /sys/class/leds/power/brightness
#!/bin/sh
set -eou pipefail
# find system version
TRUENAS_VERSION=$(cat /etc/version)
echo "Current TrueNAS version is ${TRUENAS_VERSION}"
if [ "$#" -ne 2 ]; then
echo 'Usage: bash install.sh KO_FILE_URL eth0,eth1'
exit 1 # Return 1 for failure due to missing arguments
fi
nic_str="$2"
IFS=','
read -r -a nic_list <<< "$nic_str"
echo "NIC to monitor: $nic_list"
# check if prebuild version exists
KO_URL="$1"
status_code=$(curl -o /dev/null -s -w "%{http_code}" "$KO_URL")
echo "Check if a prebuild .ko file exists..."
if [ "$status_code" -ge 400 ]; then
echo "Prebuild .ko file not found in git repo, go check it: https://github.com/miskcoo/ugreen_dx4600_leds_controller/tree/gh-actions/build-scripts/truenas/build/TrueNAS-SCALE-Dragonfish"
exit 1
fi
function dl() {
URL="$1"
FILE="$2"
# Check if both URL and FILE are provided
if [ -z "$URL" ] || [ -z "$FILE" ]; then
echo "Usage: dl <URL> <output_file>"
exit 1 # Return 1 for failure due to missing arguments
fi
status_code=$(curl -o "$FILE" -s -w "%{http_code}" "$URL" -L)
# Check if the download was successful
if [ $? -eq 0 ]; then
SHA1=$(sha1sum $FILE)
echo "File downloaded successfully, http status code is ${status_code}, file sha1 checksum is ${SHA1}"
return 0 # Return 0 for success
else
echo "File download failed."
exit 2 # Return 2 for failure due to bad status code
fi
}
KO_FILE="led-ugreen.ko"
dl "${KO_URL}" "${KO_FILE}"
# install .ko file
echo "Installing kernel module."
echo "Remount filesystem"
mount -o remount,rw "boot-pool/ROOT/${TRUENAS_VERSION}/usr"
mount -o remount,rw "boot-pool/ROOT/${TRUENAS_VERSION}/etc"
echo "ReMount ok"
KERNEL_NAME=$(uname -r)
kmod_path=$(ls -d /lib/modules/*-production+truenas/extra)
echo "Copy file: ${KO_FILE} -> ${kmod_path}"
cp "$KO_FILE" "/lib/modules/${KERNEL_NAME}/extra"
echo "populate /etc/modules-load.d/ugreen-led.conf"
cat << EOF > /etc/modules-load.d/ugreen-led.conf
i2c-dev
led-ugreen
ledtrig-oneshot
ledtrig-netdev
EOF
echo "RUN depmod"
depmod
echo "depmod return $?"
echo "RUN modprobe"
modprobe -a i2c-dev led-ugreen ledtrig-oneshot ledtrig-netdev
echo "modprebe return $?"
echo "setup systemd"
echo "download scripts from github"
SCRIPT_DIR_BASE="/tmp/ugled-scripts"
git init $SCRIPT_DIR_BASE
cd $SCRIPT_DIR_BASE
git remote add origin https://github.com/miskcoo/ugreen_dx4600_leds_controller.git
git sparse-checkout init --cone
git sparse-checkout set scripts
git pull origin master
echo "download ok, update config ..."
SCRIPT_DIR="$SCRIPT_DIR_BASE/scripts"
CONFIG_FILE="${SCRIPT_DIR}/ugreen-leds.conf"
function cfg() {
NAME=$1
VALUE=$2
new_line="$NAME=\"$VALUE\""
sed -i "s/^${NAME}/${new_line}/" "$CONFIG_FILE"
}
echo "copy /etc/ugreen-leds.conf"
cp "$SCRIPT_DIR/ugreen-leds.conf" "/etc/ugreen-leds.conf"
scripts=(ugreen-diskiomon ugreen-netdevmon ugreen-probe-leds)
for f in ${scripts[@]}; do
script_file="$SCRIPT_DIR/$f"
chmod +x "$script_file"
cp "$script_file" /usr/bin
done
cp "$SCRIPT_DIR"/*.service /etc/systemd/system/
echo "reload systemctl daemon"
systemctl daemon-reload
echo "starting services: ugreen-diskiomon.service"
systemctl enable --now ugreen-diskiomon.service
for nic in "${nic_list[@]}"; do
echo "starting service: ugreen-netdevmon@$nic"
systemctl enable --now "ugreen-netdevmon@$nic"
done
echo "cleanup script dir"
rm -rf $SCRIPT_DIR_BASE
echo "script ok, try reboot to see if it work or not"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment