| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) Advanced Micro Devices. All rights reserved. |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 7 |
# this software and associated documentation files (the "Software"), to deal in |
| 8 |
# the Software without restriction, including without limitation the rights to |
| 9 |
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 10 |
# the Software, and to permit persons to whom the Software is furnished to do so, |
| 11 |
# subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in all |
| 14 |
# copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 18 |
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 19 |
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 20 |
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 |
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 |
|
| 23 |
# Other prerm actions |
| 24 |
rm_ldconfig() { |
| 25 |
# left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build |
| 26 |
if [ "@ENABLE_LDCONFIG@" == "ON" ]; then |
| 27 |
rm -f /etc/ld.so.conf.d/x86_64-libamd_smi_lib.conf |
| 28 |
ldconfig |
| 29 |
fi |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
rm_leftovers() { |
| 34 |
# remove pyc files generated by python |
| 35 |
rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/__pycache__" |
| 36 |
rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi/__pycache__" |
| 37 |
|
| 38 |
# remove build and egg files |
| 39 |
rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi.egg-info" |
| 40 |
rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/build" |
| 41 |
|
| 42 |
# remove leftover doc files |
| 43 |
if test -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/../doc/amd_smi*"; then |
| 44 |
rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/../doc/amd_smi*" |
| 45 |
fi |
| 46 |
} |
| 47 |
|
| 48 |
rm_logFolder() { |
| 49 |
rm -rf /var/log/amd_smi_lib |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
rm_rocm_tests_dir(){ |
| 54 |
if [ -d "@CPACK_PACKAGING_INSTALL_PREFIX@/share/amd_smi/tests/" ]; then |
| 55 |
rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/share/amd_smi/tests/" |
| 56 |
echo "Removed ROCm tests directory." |
| 57 |
fi |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
return_logrotateToOrigConfig() { |
| 62 |
local logrotateConfFile=/etc/logrotate.d/amd_smi.conf |
| 63 |
if [ -f $logrotateConfFile ]; then |
| 64 |
rm -rf "$logrotateConfFile" |
| 65 |
fi |
| 66 |
if [ -f /etc/cron.hourly/logrotate ]; then |
| 67 |
mv /etc/cron.hourly/logrotate /etc/cron.daily/logrotate |
| 68 |
fi |
| 69 |
if [ -f /lib/systemd/system/logrotate.timer.backup ]; then |
| 70 |
cp /lib/systemd/system/logrotate.timer.backup /lib/systemd/system/logrotate.timer |
| 71 |
rm -rf /lib/systemd/system/logrotate.timer.backup |
| 72 |
systemctl reenable --now logrotate.timer |
| 73 |
fi |
| 74 |
} |
| 75 |
|
| 76 |
rm_python_lib() { |
| 77 |
# get python version |
| 78 |
local python3_minor_version |
| 79 |
python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)') |
| 80 |
if [ $? -ne 0 ]; then |
| 81 |
echo "[WARNING] Could not determine python version. "\ |
| 82 |
"AMD-SMI python library will not be uninstalled." |
| 83 |
return |
| 84 |
fi |
| 85 |
|
| 86 |
# check if python version is supported |
| 87 |
if [ "$python3_minor_version" -lt 6 ]; then |
| 88 |
echo "[WARNING] AMD-SMI python library is not supported on python version 3.$python3_minor_version. "\ |
| 89 |
"AMD-SMI python library will not be uninstalled." |
| 90 |
return |
| 91 |
fi |
| 92 |
|
| 93 |
# Remove old python library |
| 94 |
local pip_list_output |
| 95 |
pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check) |
| 96 |
# check pip list output for amdsmi |
| 97 |
if [[ $pip_list_output == *"amdsmi"* ]]; then |
| 98 |
PIP_ROOT_USER_ACTION=ignore PIP_BREAK_SYSTEM_PACKAGES=1 python3 -m pip uninstall amdsmi --yes --quiet --disable-pip-version-check |
| 99 |
fi |
| 100 |
|
| 101 |
pip_list_output=$(python3 -m pip list --format=columns --disable-pip-version-check) |
| 102 |
# check pip list output for amdsmi |
| 103 |
if [[ $pip_list_output == *"amdsmi"* ]]; then |
| 104 |
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed in pip. "\ |
| 105 |
"Check post install to ensure version is correct" |
| 106 |
else |
| 107 |
echo "Removed AMD-SMI python library (amdsmi)..." |
| 108 |
fi |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
case "$1" in |
| 113 |
( remove | upgrade) |
| 114 |
# remove old gpuv-smi symlink |
| 115 |
rm -f @CPACK_PACKAGING_INSTALL_PREFIX@/bin/gpuv-smi &> /dev/null |
| 116 |
echo "Removing AMDSMI Lib Tests Packages..." |
| 117 |
rm_ldconfig |
| 118 |
echo "ldconfig removed" |
| 119 |
rm_leftovers |
| 120 |
echo "leftovers removed" |
| 121 |
;; |
| 122 |
( purge ) |
| 123 |
;; |
| 124 |
( * ) |
| 125 |
exit 0 |
| 126 |
;; |
| 127 |
esac |