From 89dfe48604c9b31650d5284aa3022a6f9a9ef7ec Mon Sep 17 00:00:00 2001 From: q3aql Date: Sun, 27 Oct 2024 10:38:55 +0100 Subject: [PATCH] Daemon for lf-updr --- lf-updr | 70 +++++++++++++++++++++++++++++++++++++++++++++++++--- lf-updr.cron | 4 +++ lf-updr.sh | 66 ------------------------------------------------- lf-updrd | 35 ++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 70 deletions(-) mode change 100644 => 100755 lf-updr create mode 100644 lf-updr.cron delete mode 100755 lf-updr.sh create mode 100755 lf-updrd diff --git a/lf-updr b/lf-updr old mode 100644 new mode 100755 index d5c3739..8a359bf --- a/lf-updr +++ b/lf-updr @@ -1,4 +1,66 @@ -@reboot root /usr/bin/lf-updr -0 8 * * * root /usr/bin/lf-updr -0 16 * * * root /usr/bin/lf-updr -0 0 * * * root /usr/bin/lf-updr +#!/bin/bash + +#################################### +# lf-updr - Linux Firmware Updater # +# Author: q3aql@duck.com # +# License: GPLv2.0 # +#################################### + +# Repo Linux Firmware +repo_firmware="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git" +branch="main" +dir_repo="/lib/firmware" + +echo "** lf-updr - Linux Firmware Updater **" +echo "" + +# Check if process have root permissions +mkdir -p /etc/root &> /dev/null +administrador=$? +if [ ${administrador} -eq 0 ] ; then + rm -rf /etc/root +else + echo "* Root permissions are required" + exit +fi + +# Check dependencies +path_check="/usr/bin /usr/sbin/ /bin /sbin/ /usr/local/bin $HOME/.local/bin $(brew --prefix 2> /dev/null)/bin" +dependencies="git update-initramfs" +dependencies_found="" +dependencies_not_found="" +for checkPath in $path_check ; do + for checkDependencies in $dependencies ; do + if [ -f $checkPath/$checkDependencies ] ; then + dependencies_found="$dependencies_found $checkDependencies" + fi + done +done +for notFound in $dependencies ; do + check_found_one=$(echo $dependencies_found | grep " $notFound") + check_found_two=$(echo $dependencies_found | grep "$notFound ") + if_not_found="$check_found_one$check_found_two" + if [ -z "$if_not_found" ] ; then + dependencies_not_found="$dependencies_not_found $notFound" + fi +done +# Show if all tools are installed +if [ -z "$dependencies_not_found" ] ; then + echo > /dev/null +else + echo "* Some required tools are not installed:$dependencies_not_found" + exit 1 +fi + +# Update linux-firmware +echo "* Updating linux-firmware" +if [ -d ${dir_repo} ] ; then + cd ${dir_repo} + git pull origin ${branch} +fi + +# Run update-initramfs +echo "* Running update-initramfs" +if [ -x /usr/sbin/update-initramfs ]; then + /usr/sbin/update-initramfs -u -k all +fi diff --git a/lf-updr.cron b/lf-updr.cron new file mode 100644 index 0000000..d5c3739 --- /dev/null +++ b/lf-updr.cron @@ -0,0 +1,4 @@ +@reboot root /usr/bin/lf-updr +0 8 * * * root /usr/bin/lf-updr +0 16 * * * root /usr/bin/lf-updr +0 0 * * * root /usr/bin/lf-updr diff --git a/lf-updr.sh b/lf-updr.sh deleted file mode 100755 index 8a359bf..0000000 --- a/lf-updr.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -#################################### -# lf-updr - Linux Firmware Updater # -# Author: q3aql@duck.com # -# License: GPLv2.0 # -#################################### - -# Repo Linux Firmware -repo_firmware="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git" -branch="main" -dir_repo="/lib/firmware" - -echo "** lf-updr - Linux Firmware Updater **" -echo "" - -# Check if process have root permissions -mkdir -p /etc/root &> /dev/null -administrador=$? -if [ ${administrador} -eq 0 ] ; then - rm -rf /etc/root -else - echo "* Root permissions are required" - exit -fi - -# Check dependencies -path_check="/usr/bin /usr/sbin/ /bin /sbin/ /usr/local/bin $HOME/.local/bin $(brew --prefix 2> /dev/null)/bin" -dependencies="git update-initramfs" -dependencies_found="" -dependencies_not_found="" -for checkPath in $path_check ; do - for checkDependencies in $dependencies ; do - if [ -f $checkPath/$checkDependencies ] ; then - dependencies_found="$dependencies_found $checkDependencies" - fi - done -done -for notFound in $dependencies ; do - check_found_one=$(echo $dependencies_found | grep " $notFound") - check_found_two=$(echo $dependencies_found | grep "$notFound ") - if_not_found="$check_found_one$check_found_two" - if [ -z "$if_not_found" ] ; then - dependencies_not_found="$dependencies_not_found $notFound" - fi -done -# Show if all tools are installed -if [ -z "$dependencies_not_found" ] ; then - echo > /dev/null -else - echo "* Some required tools are not installed:$dependencies_not_found" - exit 1 -fi - -# Update linux-firmware -echo "* Updating linux-firmware" -if [ -d ${dir_repo} ] ; then - cd ${dir_repo} - git pull origin ${branch} -fi - -# Run update-initramfs -echo "* Running update-initramfs" -if [ -x /usr/sbin/update-initramfs ]; then - /usr/sbin/update-initramfs -u -k all -fi diff --git a/lf-updrd b/lf-updrd new file mode 100755 index 0000000..47387e6 --- /dev/null +++ b/lf-updrd @@ -0,0 +1,35 @@ +#!/bin/bash + +############################################ +# lf-updrd - Linux Firmware Updater Daemon # +# Author: q3aql@duck.com # +# License: GPLv2.0 # +############################################ + +run_wait=30 # 30s +interval=28800 # 8h + +# Check if process have root permissions +mkdir -p /etc/root &> /dev/null +administrador=$? +if [ ${administrador} -eq 0 ] ; then + rm -rf /etc/root +else + echo "* Root permissions are required" + exit +fi + +# Run daemon +daemon=0 +if [ -f /usr/bin/lf-updr ] ; then + echo "* Starting lf-updrd daemon" + sleep ${run_wait} + while [ ${daemon} -eq 0 ] ; do + /usr/bin/lf-updr + sleep ${interval} + done +else + echo "* Error: /usr/bin/lf-updr not found" + exit 1 +fi +