已合并
[msprof]msprof的run包增加--uninstall参数 #84
yuliangbin创建于 2月26日
[msprof]msprof的run包增加--uninstall参数 #84
已合并
共 8 个文件变更+261-154
| @@ -134,10 +134,11 @@ msProf工具run包的编译命令可配置如下参数。 | |||
| 134 | 134 | ||
| 135 | msProf工具run包的安装命令可配置如下参数。 | 135 | msProf工具run包的安装命令可配置如下参数。 |
| 136 | 136 | ||
| 137 | | 参数 | 可选/必选 | 说明 | | 137 | | 参数 | 可选/必选 | 说明 | |
| 138 | | --------| ------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------| | 138 | | --------| ------- |------------------------------------------------------------------------------------------------------------------------------------------------| |
| 139 | | --install | 必选 | 安装软件包。可配置--install-path参数指定软件的安装路径;不配置--install-path参数时,则直接安装到默认路径下。 | | 139 | | --install | 可选 | 安装软件包。可配置--install-path参数指定软件的安装路径;不配置--install-path参数时,则直接安装到默认路径下。 | |
| 140 | | --uninstall | 可选 | 卸载软件包。可配置--install-path参数指定软件安装时的路径;不配置--install-path参数时,则直接卸载默认路径下的msprof。 | | ||
| 140 | | --install-path | 可选 | 安装路径。路径须指定到cann目录,如果用户未指定安装路径,则软件会安装到默认路径下,默认安装路径如下:<br>- root用户:`/usr/local/Ascend/cann`<br>- 非root用户:`${HOME}/Ascend/cann`,${HOME}为当前用户的家目录。 | | 141 | | --install-path | 可选 | 安装路径。路径须指定到cann目录,如果用户未指定安装路径,则软件会安装到默认路径下,默认安装路径如下:<br>- root用户:`/usr/local/Ascend/cann`<br>- 非root用户:`${HOME}/Ascend/cann`,${HOME}为当前用户的家目录。 | |
| 141 | | --install-for-all | 可选 | 安装时,允许其他用户具有安装用户组的权限。当安装携带该参数时,支持其他用户使用msProf运行业务,但该参数存在安全风险,请谨慎使用。 | | 142 | | --install-for-all | 可选 | 安装时,允许其他用户具有安装用户组的权限。当安装携带该参数时,支持其他用户使用msProf运行业务,但该参数存在安全风险,请谨慎使用。 | |
| 142 | 143 | ||
| 143 | 安装run包还可指定其他参数,具体可通过./xxx.run --help命令查看。 | 144 | 安装run包还可指定其他参数,具体可通过./xxx.run --help命令查看。 |
| @@ -25,6 +25,7 @@ RUN_SCRIPT_DIR=${TOP_DIR}/scripts/run_script | |||
| 25 | FILTER_PARAM_SCRIPT=${RUN_SCRIPT_DIR}/help.conf | 25 | FILTER_PARAM_SCRIPT=${RUN_SCRIPT_DIR}/help.conf |
| 26 | MAIN_SCRIPT=main.sh | 26 | MAIN_SCRIPT=main.sh |
| 27 | INSTALL_SCRIPT=install.sh | 27 | INSTALL_SCRIPT=install.sh |
| 28 | UN_INSTALL_SCRIPT=uninstall.sh | ||
| 28 | UTILS_SCRIPT=utils.sh | 29 | UTILS_SCRIPT=utils.sh |
| 29 | 30 | ||
| 30 | MSPROF_RUN_NAME="mindstudio-profiler" | 31 | MSPROF_RUN_NAME="mindstudio-profiler" |
| @@ -100,6 +101,7 @@ function create_temp_dir() { | |||
| 100 | 101 | ||
| 101 | copy_script ${MAIN_SCRIPT} ${temp_dir} | 102 | copy_script ${MAIN_SCRIPT} ${temp_dir} |
| 102 | copy_script ${INSTALL_SCRIPT} ${temp_dir} | 103 | copy_script ${INSTALL_SCRIPT} ${temp_dir} |
| 104 | copy_script ${UN_INSTALL_SCRIPT} ${temp_dir} | ||
| 103 | copy_script ${UTILS_SCRIPT} ${temp_dir} | 105 | copy_script ${UTILS_SCRIPT} ${temp_dir} |
| 104 | } | 106 | } |
| 105 | 107 | ||
| @@ -215,6 +217,7 @@ function check_file_exist() { | |||
| 215 | 217 | ||
| 216 | check_package ${temp_dir}/${MAIN_SCRIPT} | 218 | check_package ${temp_dir}/${MAIN_SCRIPT} |
| 217 | check_package ${temp_dir}/${INSTALL_SCRIPT} ${PKG_LIMIT_SIZE} | 219 | check_package ${temp_dir}/${INSTALL_SCRIPT} ${PKG_LIMIT_SIZE} |
| 220 | check_package ${temp_dir}/${UN_INSTALL_SCRIPT} ${PKG_LIMIT_SIZE} | ||
| 218 | check_package ${temp_dir}/${UTILS_SCRIPT} ${PKG_LIMIT_SIZE} | 221 | check_package ${temp_dir}/${UTILS_SCRIPT} ${PKG_LIMIT_SIZE} |
| 219 | } | 222 | } |
| 220 | 223 | ||
| @@ -1,3 +1,5 @@ | |||
| 1 | --install Install | 1 | --install Install |
| 2 | --install-path=<path> Install to the specified path | 2 | --install-path=<path> Install to the specified path |
| 3 | --install-for-all Install for all users | 3 | --install-for-all Install for all users |
| 4 | --uninstall Uninstall | ||
| 5 | --install-path=<path> Uninstall from the specified path | ||
| @@ -39,7 +39,10 @@ function implement_install() { | |||
| 39 | create_directory ${install_path}/${arch_name}/include/acl ${right} | 39 | create_directory ${install_path}/${arch_name}/include/acl ${right} |
| 40 | create_directory ${install_path}/${arch_name}/include/ge ${right} | 40 | create_directory ${install_path}/${arch_name}/include/ge ${right} |
| 41 | create_directory ${install_path}/${ANALYSIS_PATH} ${right} | 41 | create_directory ${install_path}/${ANALYSIS_PATH} ${right} |
| 42 | # 1. install collector | 42 | create_directory ${install_path}/${SHARE_INFO_DIR}/${MSPROF} ${right} |
| 43 | # 1. uninstall.sh | ||
| 44 | copy_file ${UNINSTALL_SCRIPT} ${install_path}/${SHARE_INFO_DIR}/${MSPROF}/${UNINSTALL_SCRIPT} | ||
| 45 | # 2. install collector | ||
| 43 | # msprof bin | 46 | # msprof bin |
| 44 | copy_file ${MSPROF} ${install_path}/${MSPROF_PATH}/${MSPROF} | 47 | copy_file ${MSPROF} ${install_path}/${MSPROF_PATH}/${MSPROF} |
| 45 | # libmsprofiler.so | 48 | # libmsprofiler.so |
| @@ -53,7 +56,7 @@ function implement_install() { | |||
| 53 | # ge_prof.h | 56 | # ge_prof.h |
| 54 | copy_file ${GE_PROF_H} ${install_path}/${arch_name}/include/ge/${GE_PROF_H} | 57 | copy_file ${GE_PROF_H} ${install_path}/${arch_name}/include/ge/${GE_PROF_H} |
| 55 | 58 | ||
| 56 | # 2. install analyse | 59 | # 3. install analyse |
| 57 | copy_file ${ANALYSIS} ${install_path}/${ANALYSIS_PATH}/${ANALYSIS} | 60 | copy_file ${ANALYSIS} ${install_path}/${ANALYSIS_PATH}/${ANALYSIS} |
| 58 | msprof_analyse_whl=${install_path}/${ANALYSIS_PATH}/${MSPROF_ANALYSIS_WHL} | 61 | msprof_analyse_whl=${install_path}/${ANALYSIS_PATH}/${MSPROF_ANALYSIS_WHL} |
| 59 | copy_file ${MSPROF_ANALYSIS_WHL} $msprof_analyse_whl | 62 | copy_file ${MSPROF_ANALYSIS_WHL} $msprof_analyse_whl |
| @@ -134,11 +137,32 @@ function chmod_libmsprofiler() { | |||
| 134 | fi | 137 | fi |
| 135 | } | 138 | } |
| 136 | 139 | ||
| 140 | function register_uninstall() { | ||
| 141 | if [ ! -f "${install_path}/${SHARE_INFO_DIR}/${MSPROF}/${UNINSTALL_SCRIPT}" ]; then | ||
| 142 | print "ERROR" "No such file: ${install_path}/${SHARE_INFO_DIR}/${MSPROF}/${UNINSTALL_SCRIPT}" | ||
| 143 | fi | ||
| 144 | if [ ! -x "${install_path}/${SHARE_INFO_DIR}/${MSPROF}/${UNINSTALL_SCRIPT}" ]; then | ||
| 145 | print "ERROR" "The file ${install_path}/${SHARE_INFO_DIR}/${MSPROF}/${UNINSTALL_SCRIPT} is not executable." | ||
| 146 | return 1 | ||
| 147 | fi | ||
| 148 | if [ ! -f "${install_path}/${CANN_UNINSTALL_SCRIPT}" ]; then | ||
| 149 | print "ERROR" "Failed to register uninstall script, no such file: ${install_path}/${CANN_UNINSTALL_SCRIPT}" | ||
| 150 | return 1 | ||
| 151 | fi | ||
| 152 | local script_right=$(stat -c '%a' "${install_path}/${CANN_UNINSTALL_SCRIPT}") | ||
| 153 | chmod u+w "${install_path}/${CANN_UNINSTALL_SCRIPT}" | ||
| 154 | sed -i "/^exit /i uninstall_package \"share\/info\/msprof\"" "${install_path}/${CANN_UNINSTALL_SCRIPT}" | ||
| 155 | chmod ${script_right} "${install_path}/${CANN_UNINSTALL_SCRIPT}" | ||
| 156 | } | ||
| 157 | |||
| 137 | source utils.sh | 158 | source utils.sh |
| 138 | 159 | ||
| 139 | right=${user_right} | 160 | right=${user_right} |
| 140 | arch_name="${package_arch}-linux" | 161 | arch_name="${package_arch}-linux" |
| 141 | implement_install | 162 | implement_install |
| 163 | if [ $? -eq 0 ]; then | ||
| 164 | register_uninstall | ||
| 165 | fi | ||
| 142 | chmod_ini_file | 166 | chmod_ini_file |
| 143 | set_libmsprofiler_right | 167 | set_libmsprofiler_right |
| 144 | chmod_libmsprofiler | 168 | chmod_libmsprofiler |
| @@ -3,6 +3,7 @@ | |||
| 3 | install_args_num=0 | 3 | install_args_num=0 |
| 4 | install_path_num=0 | 4 | install_path_num=0 |
| 5 | 5 | ||
| 6 | uninstall_flag=0 | ||
| 6 | install_for_all_flag=0 | 7 | install_for_all_flag=0 |
| 7 | 8 | ||
| 8 | function parse_script_args() { | 9 | function parse_script_args() { |
| @@ -29,6 +30,11 @@ function parse_script_args() { | |||
| 29 | shift | 30 | shift |
| 30 | continue | 31 | continue |
| 31 | ;; | 32 | ;; |
| 33 | --uninstall) | ||
| 34 | uninstall_flag=1 | ||
| 35 | shift | ||
| 36 | continue | ||
| 37 | ;; | ||
| 32 | --install-for-all) | 38 | --install-for-all) |
| 33 | install_for_all_flag=1 | 39 | install_for_all_flag=1 |
| 34 | shift | 40 | shift |
| @@ -43,11 +49,14 @@ function parse_script_args() { | |||
| 43 | } | 49 | } |
| 44 | 50 | ||
| 45 | function check_args() { | 51 | function check_args() { |
| 46 | if [ ${install_args_num} -eq 0 ]; then | 52 | if [ ${install_args_num} -ne 0 ] && [ ${uninstall_flag} -eq 1 ]; then |
| 47 | print "ERROR" "Input option is invalid. Please try --help." | 53 | print "ERROR" "Input option is invalid. Please try --help." |
| 48 | exit 1 | 54 | exit 1 |
| 49 | fi | 55 | fi |
| 50 | 56 | if [ ${install_args_num} -eq 0 ] && [ ${uninstall_flag} -eq 0 ]; then | |
| 57 | print "ERROR" "Input option is invalid. Please try --help." | ||
| 58 | exit 1 | ||
| 59 | fi | ||
| 51 | if [ ${install_path_num} -gt 1 ]; then | 60 | if [ ${install_path_num} -gt 1 ]; then |
| 52 | print "ERROR" "Do not input --install-path many times. Please try --help." | 61 | print "ERROR" "Do not input --install-path many times. Please try --help." |
| 53 | exit 1 | 62 | exit 1 |
| @@ -55,7 +64,21 @@ function check_args() { | |||
| 55 | } | 64 | } |
| 56 | 65 | ||
| 57 | function execute_run() { | 66 | function execute_run() { |
| 58 | bash install.sh ${install_path} ${package_arch} ${install_for_all_flag} | 67 | if [ ${uninstall_flag} -eq 1 ]; then |
| 68 | bash uninstall.sh ${install_path} | ||
| 69 | if [ $? -ne 0 ]; then | ||
| 70 | print "ERROR" "${MSPROF_RUN_NAME} package uninstall failed." | ||
| 71 | exit 1 | ||
| 72 | fi | ||
| 73 | print "INFO" "${MSPROF_RUN_NAME} package uninstall success." | ||
| 74 | elif [ ${install_args_num} -gt 0 ]; then | ||
| 75 | bash install.sh ${install_path} ${install_for_all_flag} | ||
| 76 | if [ $? -ne 0 ]; then | ||
| 77 | print "ERROR" "${MSPROF_RUN_NAME} package install failed." | ||
| 78 | exit 1 | ||
| 79 | fi | ||
| 80 | print "INFO" "${MSPROF_RUN_NAME} package install success, the path is: '${install_path}'." | ||
| 81 | fi | ||
| 59 | } | 82 | } |
| 60 | 83 | ||
| 61 | function get_default_install_path() { | 84 | function get_default_install_path() { |
| @@ -72,5 +95,4 @@ install_path=$(get_default_install_path) | |||
| 72 | #0, this footnote path;1, path for executing run;2, parents' dir for run package;3, run params | 95 | #0, this footnote path;1, path for executing run;2, parents' dir for run package;3, run params |
| 73 | parse_script_args $* | 96 | parse_script_args $* |
| 74 | check_args | 97 | check_args |
| 75 | execute_run | 98 | execute_run |
| 76 | print "INFO" "${MSPROF_RUN_NAME} package install success, the path is: '${install_path}'." | ||
| @@ -1,146 +1,39 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | 2 | # uninstall constant | |
| 3 | function unregist_uninstall() { | 3 | # ------------------------------------------------------------------------- |
| 4 | if [ -f "${install_path}/cann_uninstall.sh" ]; then | 4 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 5 | chmod u+w ${install_path}/cann_uninstall.sh | 5 | # This file is part of the MindStudio project. |
| 6 | remove_uninstall_package "${install_path}/cann_uninstall.sh" | 6 | # |
| 7 | if [ -f "${install_path}/cann_uninstall.sh" ]; then | 7 | # MindStudio is licensed under Mulan PSL v2. |
| 8 | chmod u-w ${install_path}/cann_uninstall.sh | 8 | # You can use this software according to the terms and conditions of the Mulan PSL v2. |
| 9 | fi | 9 | # You may obtain a copy of Mulan PSL v2 at: |
| 10 | fi | 10 | # |
| 11 | } | 11 | # http://license.coscl.org.cn/MulanPSL2 |
| 12 | 12 | # | |
| 13 | function remove_uninstall_package() { | 13 | # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, |
| 14 | local uninstall_file=$1 | 14 | # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, |
| 15 | if [ -f "${uninstall_file}" ]; then | 15 | # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. |
| 16 | sed -i "/uninstall_package \"${MSPROF_RUN_NAME}\/script\"/d" "${uninstall_file}" | 16 | # See the Mulan PSL v2 for more details. |
| 17 | if [ $? -ne 0 ]; then | 17 | # ------------------------------------------------------------------------- |
| 18 | print "ERROR" "remove ${uninstall_file} uninstall_package command failed!" | 18 | CUR_DIR=$(dirname $(readlink -f $0)) |
| 19 | exit 1 | 19 | CANN_INSTALL_PATH=${CUR_DIR}/../../../.. |
| 20 | fi | 20 | if [ -z "${1}" ]; then |
| 21 | fi | 21 | install_path=${CANN_INSTALL_PATH} |
| 22 | num=$(grep "^uninstall_package " ${uninstall_file} | wc -l) | 22 | else |
| 23 | if [ ${num} -eq 0 ]; then | 23 | install_path=${1} |
| 24 | rm -f "${uninstall_file}" > /dev/null 2>&1 | ||
| 25 | if [ $? -ne 0 ]; then | ||
| 26 | print "ERROR" "delete file: ${uninstall_file}failed, please delete it by yourself." | ||
| 27 | fi | ||
| 28 | fi | ||
| 29 | } | ||
| 30 | |||
| 31 | function uninstall_product() { | ||
| 32 | delete_product ${install_path}/${ANALYSIS_PATH}/${ANALYSIS} | ||
| 33 | delete_mindstudio_msprof | ||
| 34 | delete_parent_dir | ||
| 35 | } | ||
| 36 | |||
| 37 | function delete_product() { | ||
| 38 | local target_path=${1} | ||
| 39 | |||
| 40 | if [ ! -f "$target_path" ] && [ ! -d "$target_path" ]; then | ||
| 41 | return | ||
| 42 | fi | ||
| 43 | |||
| 44 | local parent_dir=$(dirname ${target_path}) | ||
| 45 | local right=$(stat -c '%a' ${parent_dir}) | ||
| 46 | |||
| 47 | chmod u+w ${parent_dir} | ||
| 48 | |||
| 49 | chmod -R u+w ${target_path} | ||
| 50 | rm -rf ${target_path} | ||
| 51 | |||
| 52 | chmod ${right} ${parent_dir} | ||
| 53 | } | ||
| 54 | |||
| 55 | function delete_mindstudio_msprof() { | ||
| 56 | if [ ! -d "${install_path}/${MSPROF_RUN_NAME}" ]; then | ||
| 57 | return | ||
| 58 | fi | ||
| 59 | |||
| 60 | chmod -R u+w ${install_path}/${MSPROF_RUN_NAME} | ||
| 61 | rm -rf ${install_path}/${MSPROF_RUN_NAME} | ||
| 62 | } | ||
| 63 | |||
| 64 | function delete_parent_dir(){ | ||
| 65 | # must from in to out | ||
| 66 | remove_dir_by_order ${install_path}/tools/profiler/profiler_tool | ||
| 67 | remove_dir_by_order ${install_path}/tools/profiler | ||
| 68 | remove_dir_by_order ${install_path}/tools | ||
| 69 | remove_dir_by_order ${install_path} | ||
| 70 | } | ||
| 71 | |||
| 72 | function remove_dir_by_order() { | ||
| 73 | local dir_name=${1} | ||
| 74 | |||
| 75 | if [ ! -d "${dir_name}" ]; then | ||
| 76 | return | ||
| 77 | fi | ||
| 78 | |||
| 79 | local parent_dir=$(dirname ${dir_name}) | ||
| 80 | local parent_dir_right=$(stat -c '%a' ${parent_dir}) | ||
| 81 | |||
| 82 | chmod u+w ${parent_dir} | ||
| 83 | remove_empty_dir ${dir_name} | ||
| 84 | chmod ${parent_dir_right} ${parent_dir} | ||
| 85 | } | ||
| 86 | |||
| 87 | function uninstall_latest() { | ||
| 88 | local arch_name="${package_arch}-linux" | ||
| 89 | if [ -L "${latest_path}/${arch_name}/bin/${MSPROF}" ]; then | ||
| 90 | chmod u+w "${latest_path}/${arch_name}" | ||
| 91 | chmod u+w "${latest_path}/${arch_name}/bin" | ||
| 92 | rm_file_safe "${latest_path}/${arch_name}/bin/${MSPROF}" | ||
| 93 | remove_empty_dir "${latest_path}/${arch_name}/bin" | ||
| 94 | if [ -d "${latest_path}/${arch_name}/bin" ]; then | ||
| 95 | chmod u-w "${latest_path}/${arch_name}/bin" | ||
| 96 | fi | ||
| 97 | chmod u-w "${latest_path}/${arch_name}" | ||
| 98 | fi | ||
| 99 | |||
| 100 | # runtime has been uninstall | ||
| 101 | local leader_package="runtime" | ||
| 102 | |||
| 103 | if [ -L "${latest_path}/${MSPROF_RUN_NAME}" ]; then | ||
| 104 | rm_file_safe ${latest_path}/${MSPROF_RUN_NAME} | ||
| 105 | fi | ||
| 106 | |||
| 107 | # single version or multi version old | ||
| 108 | if [ ! -L "${latest_path}/${leader_package}" ] || [ ! -d "${latest_path}/${leader_package}/../${MSPROF_RUN_NAME}" ]; then | ||
| 109 | return | ||
| 110 | fi | ||
| 111 | |||
| 112 | # multi version new | ||
| 113 | local mindstudio_msprof_abs_path=$(dirname $(readlink -f ${latest_path}/${leader_package}/../${MSPROF_RUN_NAME})) | ||
| 114 | local version_name=$(basename ${mindstudio_msprof_abs_path}) | ||
| 115 | ln -sf ../${version_name}/${MSPROF_RUN_NAME} ${latest_path}/${MSPROF_RUN_NAME} | ||
| 116 | } | ||
| 117 | |||
| 118 | # must use readlink, or can not bash by latest | ||
| 119 | uninstall_location=$(readlink -f ${0}) | ||
| 120 | |||
| 121 | source $(dirname ${uninstall_location})/utils.sh | ||
| 122 | |||
| 123 | # get path | ||
| 124 | install_path=$(dirname ${uninstall_location})/../../ | ||
| 125 | if [ ! -d "${install_path}" ]; then | ||
| 126 | print "ERROR" "Can not find install path." | ||
| 127 | exit 1 | ||
| 128 | fi | 24 | fi |
| 129 | install_path="$( | ||
| 130 | cd ${install_path} | ||
| 131 | pwd | ||
| 132 | )" | ||
| 133 | 25 | ||
| 134 | latest_path=$(dirname ${uninstall_location})/../../../latest | 26 | function delete_register_uninstall() { |
| 135 | if [ ! -d "${latest_path}" ]; then | 27 | if [ ! -f "${install_path}/${CANN_UNINSTALL_SCRIPT}" ]; then |
| 136 | print "ERROR" "Can not find latest path." | 28 | print ${LEVEL_ERROR} "Failed to delete_register_uninstall, no such file: ${install_path}/${CANN_UNINSTALL_SCRIPT}" |
| 137 | exit 1 | 29 | return 1 |
| 138 | fi | 30 | fi |
| 139 | latest_path="$( | 31 | local script_right=$(stat -c '%a' "${install_path}/${CANN_UNINSTALL_SCRIPT}") |
| 140 | cd ${latest_path} | 32 | chmod u+w "${install_path}/${CANN_UNINSTALL_SCRIPT}" |
| 141 | pwd | 33 | sed -i "/uninstall_package \"share\/info\/msprof\/script\"/d" "${install_path}/${CANN_UNINSTALL_SCRIPT}" |
| 142 | )" | 34 | chmod ${script_right} "${install_path}/${CANN_UNINSTALL_SCRIPT}" |
| 35 | } | ||
| 143 | 36 | ||
| 144 | unregist_uninstall | 37 | source utils.sh |
| 145 | uninstall_product | 38 | remove ${install_path}/${ANALYSIS_PATH} |
| 146 | uninstall_latest | 39 | delete_register_uninstall |
| @@ -0,0 +1,146 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | function unregist_uninstall() { | ||
| 4 | if [ -f "${install_path}/cann_uninstall.sh" ]; then | ||
| 5 | chmod u+w ${install_path}/cann_uninstall.sh | ||
| 6 | remove_uninstall_package "${install_path}/cann_uninstall.sh" | ||
| 7 | if [ -f "${install_path}/cann_uninstall.sh" ]; then | ||
| 8 | chmod u-w ${install_path}/cann_uninstall.sh | ||
| 9 | fi | ||
| 10 | fi | ||
| 11 | } | ||
| 12 | |||
| 13 | function remove_uninstall_package() { | ||
| 14 | local uninstall_file=$1 | ||
| 15 | if [ -f "${uninstall_file}" ]; then | ||
| 16 | sed -i "/uninstall_package \"${MSPROF_RUN_NAME}\/script\"/d" "${uninstall_file}" | ||
| 17 | if [ $? -ne 0 ]; then | ||
| 18 | print "ERROR" "remove ${uninstall_file} uninstall_package command failed!" | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | fi | ||
| 22 | num=$(grep "^uninstall_package " ${uninstall_file} | wc -l) | ||
| 23 | if [ ${num} -eq 0 ]; then | ||
| 24 | rm -f "${uninstall_file}" > /dev/null 2>&1 | ||
| 25 | if [ $? -ne 0 ]; then | ||
| 26 | print "ERROR" "delete file: ${uninstall_file}failed, please delete it by yourself." | ||
| 27 | fi | ||
| 28 | fi | ||
| 29 | } | ||
| 30 | |||
| 31 | function uninstall_product() { | ||
| 32 | delete_product ${install_path}/${ANALYSIS_PATH}/${ANALYSIS} | ||
| 33 | delete_mindstudio_msprof | ||
| 34 | delete_parent_dir | ||
| 35 | } | ||
| 36 | |||
| 37 | function delete_product() { | ||
| 38 | local target_path=${1} | ||
| 39 | |||
| 40 | if [ ! -f "$target_path" ] && [ ! -d "$target_path" ]; then | ||
| 41 | return | ||
| 42 | fi | ||
| 43 | |||
| 44 | local parent_dir=$(dirname ${target_path}) | ||
| 45 | local right=$(stat -c '%a' ${parent_dir}) | ||
| 46 | |||
| 47 | chmod u+w ${parent_dir} | ||
| 48 | |||
| 49 | chmod -R u+w ${target_path} | ||
| 50 | rm -rf ${target_path} | ||
| 51 | |||
| 52 | chmod ${right} ${parent_dir} | ||
| 53 | } | ||
| 54 | |||
| 55 | function delete_mindstudio_msprof() { | ||
| 56 | if [ ! -d "${install_path}/${MSPROF_RUN_NAME}" ]; then | ||
| 57 | return | ||
| 58 | fi | ||
| 59 | |||
| 60 | chmod -R u+w ${install_path}/${MSPROF_RUN_NAME} | ||
| 61 | rm -rf ${install_path}/${MSPROF_RUN_NAME} | ||
| 62 | } | ||
| 63 | |||
| 64 | function delete_parent_dir(){ | ||
| 65 | # must from in to out | ||
| 66 | remove_dir_by_order ${install_path}/tools/profiler/profiler_tool | ||
| 67 | remove_dir_by_order ${install_path}/tools/profiler | ||
| 68 | remove_dir_by_order ${install_path}/tools | ||
| 69 | remove_dir_by_order ${install_path} | ||
| 70 | } | ||
| 71 | |||
| 72 | function remove_dir_by_order() { | ||
| 73 | local dir_name=${1} | ||
| 74 | |||
| 75 | if [ ! -d "${dir_name}" ]; then | ||
| 76 | return | ||
| 77 | fi | ||
| 78 | |||
| 79 | local parent_dir=$(dirname ${dir_name}) | ||
| 80 | local parent_dir_right=$(stat -c '%a' ${parent_dir}) | ||
| 81 | |||
| 82 | chmod u+w ${parent_dir} | ||
| 83 | remove_empty_dir ${dir_name} | ||
| 84 | chmod ${parent_dir_right} ${parent_dir} | ||
| 85 | } | ||
| 86 | |||
| 87 | function uninstall_latest() { | ||
| 88 | local arch_name="${package_arch}-linux" | ||
| 89 | if [ -L "${latest_path}/${arch_name}/bin/${MSPROF}" ]; then | ||
| 90 | chmod u+w "${latest_path}/${arch_name}" | ||
| 91 | chmod u+w "${latest_path}/${arch_name}/bin" | ||
| 92 | rm_file_safe "${latest_path}/${arch_name}/bin/${MSPROF}" | ||
| 93 | remove_empty_dir "${latest_path}/${arch_name}/bin" | ||
| 94 | if [ -d "${latest_path}/${arch_name}/bin" ]; then | ||
| 95 | chmod u-w "${latest_path}/${arch_name}/bin" | ||
| 96 | fi | ||
| 97 | chmod u-w "${latest_path}/${arch_name}" | ||
| 98 | fi | ||
| 99 | |||
| 100 | # runtime has been uninstall | ||
| 101 | local leader_package="runtime" | ||
| 102 | |||
| 103 | if [ -L "${latest_path}/${MSPROF_RUN_NAME}" ]; then | ||
| 104 | rm_file_safe ${latest_path}/${MSPROF_RUN_NAME} | ||
| 105 | fi | ||
| 106 | |||
| 107 | # single version or multi version old | ||
| 108 | if [ ! -L "${latest_path}/${leader_package}" ] || [ ! -d "${latest_path}/${leader_package}/../${MSPROF_RUN_NAME}" ]; then | ||
| 109 | return | ||
| 110 | fi | ||
| 111 | |||
| 112 | # multi version new | ||
| 113 | local mindstudio_msprof_abs_path=$(dirname $(readlink -f ${latest_path}/${leader_package}/../${MSPROF_RUN_NAME})) | ||
| 114 | local version_name=$(basename ${mindstudio_msprof_abs_path}) | ||
| 115 | ln -sf ../${version_name}/${MSPROF_RUN_NAME} ${latest_path}/${MSPROF_RUN_NAME} | ||
| 116 | } | ||
| 117 | |||
| 118 | # must use readlink, or can not bash by latest | ||
| 119 | uninstall_location=$(readlink -f ${0}) | ||
| 120 | |||
| 121 | source $(dirname ${uninstall_location})/utils.sh | ||
| 122 | |||
| 123 | # get path | ||
| 124 | install_path=$(dirname ${uninstall_location})/../../ | ||
| 125 | if [ ! -d "${install_path}" ]; then | ||
| 126 | print "ERROR" "Can not find install path." | ||
| 127 | exit 1 | ||
| 128 | fi | ||
| 129 | install_path="$( | ||
| 130 | cd ${install_path} | ||
| 131 | pwd | ||
| 132 | )" | ||
| 133 | |||
| 134 | latest_path=$(dirname ${uninstall_location})/../../../latest | ||
| 135 | if [ ! -d "${latest_path}" ]; then | ||
| 136 | print "ERROR" "Can not find latest path." | ||
| 137 | exit 1 | ||
| 138 | fi | ||
| 139 | latest_path="$( | ||
| 140 | cd ${latest_path} | ||
| 141 | pwd | ||
| 142 | )" | ||
| 143 | |||
| 144 | unregist_uninstall | ||
| 145 | uninstall_product | ||
| 146 | uninstall_latest | ||
| @@ -29,6 +29,9 @@ MSPROF="msprof" | |||
| 29 | 29 | ||
| 30 | ANALYSIS_PATH="tools/profiler/profiler_tool" | 30 | ANALYSIS_PATH="tools/profiler/profiler_tool" |
| 31 | MSPROF_PATH="tools/profiler/bin" | 31 | MSPROF_PATH="tools/profiler/bin" |
| 32 | SHARE_INFO_DIR="share/info" | ||
| 33 | UNINSTALL_SCRIPT="uninstall.sh" | ||
| 34 | CANN_UNINSTALL_SCRIPT="cann_uninstall.sh" | ||
| 32 | 35 | ||
| 33 | # msprof analysis whl | 36 | # msprof analysis whl |
| 34 | MSPROF_ANALYSIS_WHL="msprof-0.0.1-py3-none-any.whl" | 37 | MSPROF_ANALYSIS_WHL="msprof-0.0.1-py3-none-any.whl" |
| @@ -41,6 +44,19 @@ function print() { | |||
| 41 | fi | 44 | fi |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 47 | function remove() { | ||
| 48 | local target_path=${1} | ||
| 49 | if [ ! -d "${target_path}" ] && [ ! -f "${target_path}" ]; then | ||
| 50 | return | ||
| 51 | fi | ||
| 52 | local parent_dir=$(dirname ${target_path}) | ||
| 53 | local parent_right=$(stat -c '%a' ${parent_dir}) | ||
| 54 | chmod u+wx ${parent_dir} | ||
| 55 | chmod -R u+wx ${target_path} | ||
| 56 | rm -rf ${target_path} | ||
| 57 | chmod ${parent_right} ${parent_dir} | ||
| 58 | } | ||
| 59 | |||
| 44 | function get_log_file() { | 60 | function get_log_file() { |
| 45 | local log_dir | 61 | local log_dir |
| 46 | if [ "$UID" = "0" ]; then | 62 | if [ "$UID" = "0" ]; then |