Files
rocm-systems/projects/amdsmi/RPM/preun.in
T
Galantsev, Dmitrii 8535f6993d Don't crash [un]install scripts on python failure
Change-Id: Icfbcc647bda94dd2ff2f65016de5c80af5d1ec79
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>


[ROCm/amdsmi commit: 08268ba1c1]
2023-11-02 15:15:27 -04:00

63 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
rm_pyc() {
# remove pyc files generated by python
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/__pycache__
rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi/__pycache__
}
rm_logFolder() {
rm -rf /var/log/amd_smi_lib
}
return_logrotateToOrigConfig() {
local logrotateConfFile=/etc/logrotate.d/amd_smi.conf
if [ -f $logrotateConfFile ]; then
rm -rf "$logrotateConfFile"
fi
if [ -f /etc/cron.hourly/logrotate ]; then
mv /etc/cron.hourly/logrotate /etc/cron.daily/logrotate
fi
if [ -f /lib/systemd/system/logrotate.timer.backup ]; then
cp /lib/systemd/system/logrotate.timer.backup /lib/systemd/system/logrotate.timer
rm -rf /lib/systemd/system/logrotate.timer.backup
systemctl reenable --now logrotate.timer
fi
}
rm_python_lib() {
# get python version
local python3_minor_version
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
if [ $? -ne 0 ]; then
echo "[WARNING] Could not determine python version. "\
"AMD-SMI python library will not be uninstalled."
return
fi
# check if python version is supported
if [ "$python3_minor_version" -lt 6 ]; then
echo "[WARNING] AMD-SMI python library is not supported on python version 3.$python3_minor_version. "\
"AMD-SMI python library will not be uninstalled."
return
fi
python3 -m pip uninstall amdsmi --yes
python3 -m pip show amdsmi
if [ $? -ne 1 ]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed. "\
"Check post install to ensure version is correct"
return
fi
}
if [ "$1" -le 1 ]; then
# perform the below actions for rpm remove($1=0) or upgrade($1=1) operations
# remove old gpuv-smi symlink
rm -f @CPACK_PACKAGING_INSTALL_PREFIX@/bin/gpuv-smi &> /dev/null
rm_python_lib || return 0
rm_pyc
rm_logFolder
return_logrotateToOrigConfig
fi