update(falco_scripts): remove only the current version

Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
This commit is contained in:
Andrea Terzolo 2022-03-21 12:41:51 +01:00 committed by poiana
parent a11d513bff
commit 1ebdb5648f

View File

@ -219,18 +219,26 @@ load_kernel_module_download() {
fi fi
} }
print_clean_termination() {
echo
echo "* [SUCCESS] Cleaning phase correctly terminated."
echo
echo "================ Cleaning phase ================"
echo
}
clean_kernel_module() { clean_kernel_module() {
echo echo
echo "================ Cleaning phase ================" echo "================ Cleaning phase ================"
echo echo
if ! hash lsmod > /dev/null 2>&1; then if ! hash lsmod > /dev/null 2>&1; then
>&2 echo "* Error: This program requires lsmod." >&2 echo "* [ERROR]: This program requires lsmod."
exit 1 exit 1
fi fi
if ! hash rmmod > /dev/null 2>&1; then if ! hash rmmod > /dev/null 2>&1; then
>&2 echo "* Error: This program requires rmmod." >&2 echo "* [ERROR]: This program requires rmmod."
exit 1 exit 1
fi fi
@ -252,56 +260,41 @@ clean_kernel_module() {
echo "- OK! Unloading '${KMOD_NAME}' module succeeded." echo "- OK! Unloading '${KMOD_NAME}' module succeeded."
echo echo
else else
echo "- Nothing to do...'falco-driver-loader' will wait until you remove the kernel module to have a clean termination." echo "- Nothing to do...'falco-driver-loader' will wait until you remove the kernel module to have a clean termination."
echo "- Checkout here what to do (link to documentation)." echo "- Checkout here what to do (link to documentation)."
echo "- Sleep 5 seconds..." echo "- Sleep 5 seconds..."
echo echo
((--MAX_RMMOD_WAIT)) ((--MAX_RMMOD_WAIT))
sleep 5 sleep 5
fi fi
done done
if [ ${MAX_RMMOD_WAIT} -eq 0 ]; then if [ ${MAX_RMMOD_WAIT} -eq 0 ]; then
echo "* [WARNING] '${KMOD_NAME}' module is still loaded, you could have incompatibility issues." echo "* [WARNING] '${KMOD_NAME}' module is still loaded, you could have incompatibility issues."
return echo
fi fi
if ! hash dkms >/dev/null 2>&1; then if ! hash dkms >/dev/null 2>&1; then
echo "* Skipping dkms remove (dkms not found)" echo "- Skipping dkms remove (dkms not found)"
print_clean_termination
return return
fi fi
echo "* 2. Check kernel module '${KMOD_NAME}' in dkms:" # Remove the module version from dkms.
echo "* 2. Check kernel module '${KMOD_NAME}' with version '${DRIVER_VERSION}' in dkms:"
# Remove all versions of this module from dkms. if [ "$(dkms status -m $KMOD_NAME -v $DRIVER_VERSION)" ]; then
DRIVER_VERSIONS=$(dkms status -m "${KMOD_NAME}" | cut -d',' -f2 | sed -e 's/^[[:space:]]*//') echo "- Removing version '${DRIVER_VERSION}' from dkms..."
if [ -z "${DRIVER_VERSIONS}" ]; then if dkms remove -m $KMOD_NAME -v $DRIVER_VERSION --all; then
echo "- OK! There is no '${KMOD_NAME}' module in dkms-"
return
else
echo "- There are some verions of '${KMOD_NAME}' module in dkms."
echo
echo "* 3. Removing all the following versions of '${KMOD_NAME}' module from dkms:"
echo "- ${DRIVER_VERSIONS}"
echo
fi
for CURRENT_VER in ${DRIVER_VERSIONS}; do
echo "- Removing ${CURRENT_VER}..."
if dkms remove -m ${KMOD_NAME} -v "${CURRENT_VER}" --all; then
echo
echo "- OK! Removing '${CURRENT_VER}' succeeded"
echo echo
echo "- OK! Removing '${DRIVER_VERSION}' succeeded."
else else
echo "- Removing '${KMOD_NAME}' version '${CURRENT_VER}' failed" echo "* [WARNING] Removing '${KMOD_NAME}' version '${DRIVER_VERSION}' failed."
return
fi fi
done else
echo "- OK! There is no '${KMOD_NAME}' module in dkms."
fi
echo "* [SUCCESS] Cleaning phase correctly terminated." print_clean_termination
echo
echo "================ Cleaning phase ================"
echo
} }
load_kernel_module() { load_kernel_module() {