Run a script after running apt-get update on a Debian or Ubuntu Linux
Run a script after running apt-get update on a Debian or Ubuntu Linux
If you want to run a script for example, after apt update
on Debian, you can use the apt
hook system. This is useful if you want to perform some other action after the update. In my case, I need to run a script and re-install the Vulkan driver on Raspberry Pi, because apt update
break it and the system can't open the Desktop environment.
To do this, create a script in an accesible directory. I'm going to use /home/ulysess
.
#!/bin/bash
function reinstall_vulkan_driver() {
readonly BUILD_MESA_VULKAN_DRIVER_DIR="/home/ulysess/mesa_vulkan/build"
if [[ ! -d $BUILD_MESA_VULKAN_DRIVER_DIR ]]; then
echo "Vulkan driver not found. Exiting..."
exit 1
fi
cd $BUILD_MESA_VULKAN_DRIVER_DIR || exit 1
echo "Reinstalling Vulkan driver..."
sudo ninja install
echo "Vulkan driver reinstalled!."
}
reinstall_vulkan_driver
Remember to make the file executable:
sudo chmod +x /home/ulysess/reinstall-vulkan-driver.sh
Create a new file to define the hook. For example: /etc/apt/apt.conf.d/99reinstall-vulkan-driver-hook
:
DPkg::Post-Invoke {"if [ -x /home/ulysess/reinstall-vulkan-driver.sh ]; then /home/ulysess/reinstall-vulkan-driver.sh; fi";};
Now, whenever you run sudo apt upgrade or update
, the script reinstall-vulkan-driver.sh
will be executed automatically after the upgrade/update process completes.
Please note that this method should work on Debian-based systems.