I recently installed an update for the above package via apt. I get the following error:
Preparing to unpack .../intel-oneapi-runtime-opencl_2025.1.0-973_amd64.deb ...
dpkg: warning: old intel-oneapi-runtime-opencl package pre-removal script subprocess returned error exit status 2
dpkg: trying script from the new package instead ...
dpkg: error processing archive /var/cache/apt/archives/intel-oneapi-runtime-opencl_2025.1.0-973_amd64.deb (--unpack):
new intel-oneapi-runtime-opencl package pre-removal script subprocess returned error exit status 2
openCL has already registered, skipping update-alternatives ...
update-alternatives: warning: forcing reinstallation of alternative /opt/intel/oneapi/redist because link group opencl-intel-runtime is broken
Errors were encountered while processing:
/var/cache/apt/archives/intel-oneapi-runtime-opencl_2025.1.0-973_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
it seem maybe the package fails to unpack
Now apt is broken and I can't update anything n the system.
My system is running Mint Linux 21.1 (which is based on Ubuntu 22.04)
How do I fix this?
For anyone else struggling with this, replace the script mentioned in the previous post with something like the following and you will be able to fix your installation. I also comment out the dangerous "rmdir /etc" to avoid that possibility.
#!/bin/bash
# Copyright Intel Corporation.
#
# This software and the related documents are Intel copyrighted materials,
# and your use of them is governed by the express license under which they
# were provided to you ("License"). Unless the License provides otherwise,
# you may not use, modify, copy, publish, distribute, disclose or transmit
# this software or the related documents without Intel's prior written
# permission.
#
# This software and the related documents are provided as is, with no express
# or implied warranties, other than those that are expressly stated in the
# License.
INSTALL_DIR=/opt/intel/oneapi/redist
#
# If post-install script failed to install alternative, uninstalling package also fails, because
# 'update-alternatives' cannot remove non-existing alternative. Let us check the alternative
# exists before removing it.
#
#remove_alternative() {
# update-alternatives --display "$1" &>/dev/null
# if [ $? = 0 ]; then
# update-alternatives --remove "$1" "$2"
# else
# echo "Alternative for $1 is not found, skipping ..."
# fi
#}
remove_alternative() {
if update-alternatives --display "$1" &>/dev/null; then
update-alternatives --remove "$1" "$2"
else
echo "Alternative for $1 is not found, skipping ..."
fi
}
set -e
LIB_OPENCL_SO=`find "${INSTALL_DIR}" -name "libOpenCL.so"`
if [ "${LIB_OPENCL_SO}" ]; then
remove_alternative opencl-libOpenCL.so "${LIB_OPENCL_SO}"
fi
LIB_INSTALL_DIR="${INSTALL_DIR}"
remove_alternative opencl-intel-runtime "${LIB_INSTALL_DIR}"
if [ -e "/etc/OpenCL/vendors" ] ; then
rmdir --ignore-fail-on-non-empty "/etc/OpenCL/vendors" 2>/dev/null
rmdir --ignore-fail-on-non-empty "/etc/OpenCL" 2>/dev/null
if [ -z "$(ls -A /etc)" ] ; then
# rmdir "/etc" 2>/dev/null
fi
fi
exit 0
連結已複製
The root cause of the problem is the pre-removal script which contains a silly error, and some crazy stuff which I hope is removed in the new version.
I mean this script
/var/lib/dpkg/info/intel-oneapi-runtime-opencl.prerm
the script fails because it sets set -e in the body, but also contains the following function at the top
remove_alternative() {
update-alternatives --display "$1" &>/dev/null
if [ $? = 0 ]; then
update-alternatives --remove "$1" "$2"
else
echo "Alternative for $1 is not found, skipping ..."
fi
}
when the following command in this function returns a non-zero exit code the script exits and returns that exit code:
update-alternatives --display "$1" &>/dev/null
Now, as for the crazy stuff, there's also the following snippet:
if [ -e "/etc/OpenCL/vendors" ] ; then
rmdir --ignore-fail-on-non-empty "/etc/OpenCL/vendors" 2>/dev/null
rmdir --ignore-fail-on-non-empty "/etc/OpenCL" 2>/dev/null
if [ -z "$(ls -A /etc)" ] ; then
rmdir "/etc" 2>/dev/null
fi
fi
So there's some possibility this script will decide to just go delete /etc !!!! WTF?
For anyone else struggling with this, replace the script mentioned in the previous post with something like the following and you will be able to fix your installation. I also comment out the dangerous "rmdir /etc" to avoid that possibility.
#!/bin/bash
# Copyright Intel Corporation.
#
# This software and the related documents are Intel copyrighted materials,
# and your use of them is governed by the express license under which they
# were provided to you ("License"). Unless the License provides otherwise,
# you may not use, modify, copy, publish, distribute, disclose or transmit
# this software or the related documents without Intel's prior written
# permission.
#
# This software and the related documents are provided as is, with no express
# or implied warranties, other than those that are expressly stated in the
# License.
INSTALL_DIR=/opt/intel/oneapi/redist
#
# If post-install script failed to install alternative, uninstalling package also fails, because
# 'update-alternatives' cannot remove non-existing alternative. Let us check the alternative
# exists before removing it.
#
#remove_alternative() {
# update-alternatives --display "$1" &>/dev/null
# if [ $? = 0 ]; then
# update-alternatives --remove "$1" "$2"
# else
# echo "Alternative for $1 is not found, skipping ..."
# fi
#}
remove_alternative() {
if update-alternatives --display "$1" &>/dev/null; then
update-alternatives --remove "$1" "$2"
else
echo "Alternative for $1 is not found, skipping ..."
fi
}
set -e
LIB_OPENCL_SO=`find "${INSTALL_DIR}" -name "libOpenCL.so"`
if [ "${LIB_OPENCL_SO}" ]; then
remove_alternative opencl-libOpenCL.so "${LIB_OPENCL_SO}"
fi
LIB_INSTALL_DIR="${INSTALL_DIR}"
remove_alternative opencl-intel-runtime "${LIB_INSTALL_DIR}"
if [ -e "/etc/OpenCL/vendors" ] ; then
rmdir --ignore-fail-on-non-empty "/etc/OpenCL/vendors" 2>/dev/null
rmdir --ignore-fail-on-non-empty "/etc/OpenCL" 2>/dev/null
if [ -z "$(ls -A /etc)" ] ; then
# rmdir "/etc" 2>/dev/null
fi
fi
exit 0
consider changing....
if [ -e "/etc/OpenCL/vendors" ] ; then
rmdir --ignore-fail-on-non-empty "/etc/OpenCL/vendors" 2>/dev/null
rmdir --ignore-fail-on-non-empty "/etc/OpenCL" 2>/dev/null
if [ -z "$(ls -A /etc)" ] ; then
# rmdir "/etc" 2>/dev/null
fi
fi
to...
if [ -e "/etc/OpenCL/vendors" ] ; then
rmdir --ignore-fail-on-non-empty "/etc/OpenCL/vendors" 2>/dev/null
rmdir --ignore-fail-on-non-empty "/etc/OpenCL" 2>/dev/null
# if [ -z "$(ls -A /etc)" ] ; then
# rmdir "/etc" 2>/dev/null
# fi
fi
just bc some shell's might get cranky
Thanks, here's the full updated script for my own reference and others:
#!/bin/bash
# Copyright Intel Corporation.
#
# This software and the related documents are Intel copyrighted materials,
# and your use of them is governed by the express license under which they
# were provided to you ("License"). Unless the License provides otherwise,
# you may not use, modify, copy, publish, distribute, disclose or transmit
# this software or the related documents without Intel's prior written
# permission.
#
# This software and the related documents are provided as is, with no express
# or implied warranties, other than those that are expressly stated in the
# License.
INSTALL_DIR=/opt/intel/oneapi/redist
#
# If post-install script failed to install alternative, uninstalling package also fails, because
# 'update-alternatives' cannot remove non-existing alternative. Let us check the alternative
# exists before removing it.
#
#remove_alternative() {
# update-alternatives --display "$1" &>/dev/null
# if [ $? = 0 ]; then
# update-alternatives --remove "$1" "$2"
# else
# echo "Alternative for $1 is not found, skipping ..."
# fi
#}
remove_alternative() {
if update-alternatives --display "$1" &>/dev/null; then
update-alternatives --remove "$1" "$2"
else
echo "Alternative for $1 is not found, skipping ..."
fi
}
set -e
LIB_OPENCL_SO=`find "${INSTALL_DIR}" -name "libOpenCL.so"`
if [ "${LIB_OPENCL_SO}" ]; then
remove_alternative opencl-libOpenCL.so "${LIB_OPENCL_SO}"
fi
LIB_INSTALL_DIR="${INSTALL_DIR}"
remove_alternative opencl-intel-runtime "${LIB_INSTALL_DIR}"
if [ -e "/etc/OpenCL/vendors" ] ; then
rmdir --ignore-fail-on-non-empty "/etc/OpenCL/vendors" 2>/dev/null
rmdir --ignore-fail-on-non-empty "/etc/OpenCL" 2>/dev/null
# if [ -z "$(ls -A /etc)" ] ; then
# rmdir "/etc" 2>/dev/null
# fi
fi
exit 0
Hi Richard, we hope you are doing great!
Could you kindly confirm whether your issue has been resolved, or if you require further assistance from Intel®? This will enable us to investigate further or direct your request to the higher team for additional assistance.
Have a great day ahead!
