lf-updr/install.sh

125 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2024-10-20 13:58:17 +02:00
#!/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
2024-10-27 10:51:43 +01:00
if [ -f "$(dirname $0)/lf-updr" ] ; then
2024-10-20 13:58:17 +02:00
echo "* Installing /usr/bin/lf-updr"
2024-10-27 10:51:43 +01:00
cp -rf $(dirname $0)/lf-updr /usr/bin/lf-updr
2024-10-20 13:58:17 +02:00
chmod +x /usr/bin/lf-updr
else
echo "* Error installing /usr/bin/lf-updr"
2024-10-27 10:51:43 +01:00
echo "* File $(dirname $0)/lf-updr not found"
exit 1
fi
if [ -f "$(dirname $0)/lf-updrd" ] ; then
echo "* Installing /usr/sbin/lf-updrd"
cp -rf $(dirname $0)/lf-updrd /usr/sbin/lf-updrd
chmod +x /usr/sbin/lf-updrd
else
echo "* Error installing /usr/sbin/lf-updrd"
echo "* File $(dirname $0)/lf-updrd not found"
2024-10-20 13:58:17 +02:00
exit 1
fi
2024-10-27 10:51:43 +01:00
if [ -f "$(dirname $0)/lf-updr-install" ] ; then
echo "* Installing /usr/bin/lf-updr-install"
cp -rf $(dirname $0)/lf-updr-install /usr/bin/lf-updr-install
chmod +x /usr/bin/lf-updr-install
else
echo "* Error installing /usr/bin/lf-updr-install"
echo "* File $(dirname $0)/lf-updr-install not found"
exit 1
fi
if [ -f "$(dirname $0)/lf-updr.cron" ] ; then
2024-10-20 13:58:17 +02:00
echo "* Installing /etc/cron.d/lf-updr"
2024-10-27 10:51:43 +01:00
cp -rf $(dirname $0)/lf-updr.cron /etc/cron.d/lf-updr
chmod 644 /etc/cron.d/lf-updr
2024-10-20 13:58:17 +02:00
else
echo "* Error installing /etc/crond./lf-updr"
2024-10-27 10:51:43 +01:00
echo "* File $(dirname $0)/lf-updr.cron not found"
exit 1
fi
if [ -f "$(dirname $0)/lf-updrd.service" ] ; then
echo "* Installing /etc/systemd/system/lf-updrd.service"
cp -rf $(dirname $0)/lf-updrd.service /etc/systemd/system/lf-updrd.service
chmod 644 /etc/systemd/system/lf-updrd.service
else
echo "* Error installing /etc/systemd/system/lf-updrd.service"
echo "* File $(dirname $0)/lf-updrd.service not found"
2024-10-20 13:58:17 +02:00
exit 1
fi
2024-10-27 10:51:43 +01:00
systemctl enable lf-updrd
2024-10-20 13:58:17 +02:00
# Run update-initramfs
echo "* Running update-initramfs"
if [ -x /usr/sbin/update-initramfs ]; then
/usr/sbin/update-initramfs -u -k all
fi
2024-10-27 10:51:43 +01:00
systemctl start lf-updrd