diff --git a/scripts/falco-driver-loader b/scripts/falco-driver-loader index 465cb3d1..ed278da9 100755 --- a/scripts/falco-driver-loader +++ b/scripts/falco-driver-loader @@ -219,18 +219,26 @@ load_kernel_module_download() { fi } +print_clean_termination() { + echo + echo "* [SUCCESS] Cleaning phase correctly terminated." + echo + echo "================ Cleaning phase ================" + echo +} + clean_kernel_module() { echo echo "================ Cleaning phase ================" echo if ! hash lsmod > /dev/null 2>&1; then - >&2 echo "* Error: This program requires lsmod." + >&2 echo "* [ERROR]: This program requires lsmod." exit 1 fi if ! hash rmmod > /dev/null 2>&1; then - >&2 echo "* Error: This program requires rmmod." + >&2 echo "* [ERROR]: This program requires rmmod." exit 1 fi @@ -252,56 +260,41 @@ clean_kernel_module() { echo "- OK! Unloading '${KMOD_NAME}' module succeeded." echo else - 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 "- Sleep 5 seconds..." - echo + 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 "- Sleep 5 seconds..." + echo ((--MAX_RMMOD_WAIT)) - sleep 5 + sleep 5 fi done if [ ${MAX_RMMOD_WAIT} -eq 0 ]; then echo "* [WARNING] '${KMOD_NAME}' module is still loaded, you could have incompatibility issues." - return + echo fi 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 fi - echo "* 2. Check kernel module '${KMOD_NAME}' in dkms:" - - # Remove all versions of this module from dkms. - DRIVER_VERSIONS=$(dkms status -m "${KMOD_NAME}" | cut -d',' -f2 | sed -e 's/^[[:space:]]*//') - if [ -z "${DRIVER_VERSIONS}" ]; then - echo "- OK! There is no '${KMOD_NAME}' module in dkms-" - return + # Remove the module version from dkms. + echo "* 2. Check kernel module '${KMOD_NAME}' with version '${DRIVER_VERSION}' in dkms:" + if [ "$(dkms status -m $KMOD_NAME -v $DRIVER_VERSION)" ]; then + echo "- Removing version '${DRIVER_VERSION}' from dkms..." + if dkms remove -m $KMOD_NAME -v $DRIVER_VERSION --all; then + echo + echo "- OK! Removing '${DRIVER_VERSION}' succeeded." + else + echo "* [WARNING] Removing '${KMOD_NAME}' version '${DRIVER_VERSION}' failed." + fi 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 + echo "- OK! There is no '${KMOD_NAME}' module in dkms." 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 - else - echo "- Removing '${KMOD_NAME}' version '${CURRENT_VER}' failed" - return - fi - done - - echo "* [SUCCESS] Cleaning phase correctly terminated." - echo - echo "================ Cleaning phase ================" - echo + print_clean_termination } load_kernel_module() {