Compare commits

..

5 Commits

Author SHA1 Message Date
515e2d29a0 README.md 2024-10-20 13:59:46 +02:00
43b5087530 lf-updr tool 2024-10-20 13:59:37 +02:00
84a5f5c3e5 Cron file for lf-updr 2024-10-20 13:58:58 +02:00
7ad681fdd5 Uninstaller for ld-updr 2024-10-20 13:58:27 +02:00
681d4620c5 Installer for ld-updr 2024-10-20 13:58:17 +02:00
5 changed files with 224 additions and 0 deletions

32
README.md Normal file
View File

@ -0,0 +1,32 @@
`lf-updr` - Update drivers from Linux-Firmware automatically
## How to install:
```
git clone https://git.q3aql.dev/q3aql/lf-updr
cd lf-updr
sudo ./install.sh
```
## How to uninstall:
```
git clone https://git.q3aql.dev/q3aql/lf-updr
cd lf-updr
sudo ./uninstall.sh
```
## Update manually:
```
sudo lf-updr
```
**Note:** Automatically, the cron service will execute periodically the update.
## Dependencies
* bash
* git
* cron
* update-initramfs

95
install.sh Executable file
View File

@ -0,0 +1,95 @@
#!/bin/bash
##############################################
# lf-updr - Linux Firmware Updater Installer #
# 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
# Install linux-firmware
if [ -d ${dir_repo} ] ; then
echo "* Moving ${dir_repo} to ${dir_repo}.old"
rm -rf ${dir_repo}.old
mv ${dir_repo} ${dir_repo}.old
fi
echo "* Cloning linux-firmware to ${dir_repo}"
git clone ${repo_firmware} ${dir_repo}
error_cloning=$?
if [ ${error_cloning} -ne 0 ] ; then
echo "* Error: Fail cloning linux-firmware"
echo "* Rolling back ${dir_repo}.old"
mv ${dir_repo}.old ${dir_repo}
exit 1
fi
# Install script and cron
if [ -f "$(dirname $0)/lf-updr.sh" ] ; then
echo "* Installing /usr/bin/lf-updr"
cp -rf $(dirname $0)/lf-updr.sh /usr/bin/lf-updr
chmod +x /usr/bin/lf-updr
else
echo "* Error installing /usr/bin/lf-updr"
echo "* File $(dirname $0)/lf-updr.sh not found"
exit 1
fi
if [ -f "$(dirname $0)/lf-updr" ] ; then
echo "* Installing /etc/cron.d/lf-updr"
cp -rf $(dirname $0)/lf-updr /etc/cron.d/lf-updr
chmod 644 /etc/cron.d/lf-updr
else
echo "* Error installing /etc/crond./lf-updr"
echo "* File $(dirname $0)/lf-updr not found"
exit 1
fi
# Run update-initramfs
echo "* Running update-initramfs"
if [ -x /usr/sbin/update-initramfs ]; then
/usr/sbin/update-initramfs -u -k all
fi

4
lf-updr Normal file
View File

@ -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

66
lf-updr.sh Executable file
View File

@ -0,0 +1,66 @@
#!/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="/usr/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

27
uninstall.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
################################################
# lf-updr - Linux Firmware Updater Uninstaller #
# Author: q3aql@duck.com #
# License: GPLv2.0 #
################################################
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
# Remove files
echo "* Removing /usr/bin/lf-updr"
rm -rf /usr/bin/lf-updr
echo "* Removing /etc/cron.d/lf-updr"
rm -rf /etc/cron.d/lf-updr
echo "* Done"