From 4474dcff2c3097c998fa4758d13d1f6ee4e1f718 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Mon, 13 May 2024 14:05:54 -0500 Subject: [PATCH] Add preinstall script for build_hsa.sh This is to fix the situation where libhsa-runtime exists in /usr/lib. The preinstall script will check for this and ask the user if they want to delete the old version, or else abandon install. Change-Id: I0976b6ec95b9752c95031f1a73fc49a150b02b23 Signed-off-by: Chris Freehill --- CMakeLists.txt | 7 +++++-- DEBIAN/preinst | 23 +++++++++++++++++++++++ RPM/preinst | 23 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 DEBIAN/preinst create mode 100644 RPM/preinst diff --git a/CMakeLists.txt b/CMakeLists.txt index d5de377dad..360ecc0447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,8 +176,8 @@ set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/RadeonOpenCompute/ROCR-Run ## Process the Debian install/remove scripts to update the CPACK variables configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/Binary/postinst.in DEBIAN/Binary/postinst @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/Binary/prerm.in DEBIAN/Binary/prerm @ONLY) -set(CPACK_DEBIAN_BINARY_PACKAGE_CONTROL_EXTRA "DEBIAN/Binary/postinst;DEBIAN/Binary/prerm") - +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/preinst DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/DEBIAN) +set (CPACK_DEBIAN_BINARY_PACKAGE_CONTROL_EXTRA "DEBIAN/preinst;DEBIAN/Binary/postinst;DEBIAN/Binary/prerm") # Needed since some packages still say they need hsakmt-roct set(CPACK_DEBIAN_PACKAGE_REPLACES "hsakmt-roct,hsa-ext-rocr-dev,hsa-runtime64") set(CPACK_DEBIAN_PACKAGE_PROVIDES "hsakmt-roct,hsa-runtime64") @@ -235,6 +235,9 @@ set(CPACK_RPM_PACKAGE_LICENSE "NCSA") ## Process the Rpm install/remove scripts to update the CPACK variables configure_file("${CMAKE_CURRENT_SOURCE_DIR}/RPM/Binary/post.in" RPM/Binary/post @ONLY) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/RPM/Binary/postun.in" RPM/Binary/postun @ONLY) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/RPM/preinst DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/RPM) +set (CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/preinst") + set(CPACK_RPM_BINARY_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/Binary/post") set(CPACK_RPM_BINARY_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/Binary/postun") diff --git a/DEBIAN/preinst b/DEBIAN/preinst new file mode 100644 index 0000000000..abff051c3b --- /dev/null +++ b/DEBIAN/preinst @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "Pre-install check for ROCr." + +# Check for old installations... +if ls /usr/lib/libhsa-runtime* 1> /dev/null 2>&1; then + echo "An old version of libhsa-runtime was found in /usr/lib." + echo "This must be uninstalled before proceeding with the installation" + echo "to avoid potential incompatibilities." + + read -r -p "Do you want to uninstall the old version? [y/N] " response + if [ "$response" = "y" ]; then + if ! rm -rf /usr/lib/libhsa-runtime*; then + echo "Failed to remove /usr/lib/libhsa-runtime* files." + echo "Try to uninstall these files manually." + exit 1 + fi + echo "Old version uninstalled." + else + echo "The old and new versions of ROCm are incompatible. Installation aborted." + exit 1 + fi +fi diff --git a/RPM/preinst b/RPM/preinst new file mode 100644 index 0000000000..abff051c3b --- /dev/null +++ b/RPM/preinst @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "Pre-install check for ROCr." + +# Check for old installations... +if ls /usr/lib/libhsa-runtime* 1> /dev/null 2>&1; then + echo "An old version of libhsa-runtime was found in /usr/lib." + echo "This must be uninstalled before proceeding with the installation" + echo "to avoid potential incompatibilities." + + read -r -p "Do you want to uninstall the old version? [y/N] " response + if [ "$response" = "y" ]; then + if ! rm -rf /usr/lib/libhsa-runtime*; then + echo "Failed to remove /usr/lib/libhsa-runtime* files." + echo "Try to uninstall these files manually." + exit 1 + fi + echo "Old version uninstalled." + else + echo "The old and new versions of ROCm are incompatible. Installation aborted." + exit 1 + fi +fi