下载
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助
昇腾小AI

用户安装/卸载脚本

提供参考安装/卸载脚本如下,用户可拷贝,本地保存为sh脚本(如tk_user.sh):

#!/bin/bash

script=$(readlink -f "$0")
route=$(dirname "$script")

tk_package_name="Ascend_mindxsdk_mxTuningKit"
python_version="python3"
cmd_para="$1"

get_python_version()
{
  $python_version --version &>/dev/null
  if test $? -ne 0; then
    echo "Can not find $python_version, wheel package will not be installed."
    exit
  fi
}

tk_get_install_path()
{
  space_char=' '

  # get tk install path
  tk_install_info=$($python_version -m pip show $tk_package_name | grep 'Location:')
  tk_install_path=$(echo $tk_install_info |sed 's/^Location: //g')

  # get tk bin file path
  tk_bin_info=$(whereis tk)
  tk_bin_path=${tk_bin_info#*$space_char}
  if [[ $tk_bin_path == *$space_char* ]];then
    tk_bin_path=${tk_bin_path%%$space_char*}
  fi
}


tk_chmod_whl()
{
  chd_value=$1
  if [[ -d "$tk_install_path/tk" ]];then
    chmod $chd_value -R $tk_install_path/tk
  fi
  if [[ -f "$tk_bin_path" ]];then
    chmod $chd_value  $tk_bin_path
  fi
}

tk_chmod_log()
{
  chd_value=$1
  log_file=$2
  if [[ -f "$log_file" ]];then
    chmod $chd_value $log_file
  fi
}

tk_check_os_inject()
{
  whl_name=$(basename "$1")
  if [[ ! "$whl_name" =~ ^([a-zA-Z0-9_.-]+)$ ]];then
    echo "Invalid Characters in whl package's name, please check it."
    exit 1
  fi
}


tk_install_whl()
{
  get_python_version

  whl_file_name=$(find $route -maxdepth 1 -type f -name "$tk_package_name*.whl")
  if [[ -f "$whl_file_name" ]];then
    tk_check_os_inject "$whl_file_name"
    echo "Begin to install mxTuningKit wheel package ($whl_file_name)."
    log_file="$HOME/.cache/Huawei/mxTuningKit/log/install-log.log"
    $python_version -m pip install "$whl_file_name" --log-file $log_file
    if test $? -ne 0; then
      echo "Install mxTuningKit wheel package failed."
    else
      tk_get_install_path
      tk_chmod_whl 550
      echo "Install mxTuningKit wheel package successfully."
    fi
  elif [[ "$whl_file_name" == *\n* ]];then
    echo "Only support a single version of whl package, please check it."
  else
    echo "There is no mxTuningKit wheel package to install."
  fi
  tk_chmod_log 640 $log_file
}

tk_uninstall_whl()
{
  tk_get_install_path
  if [ -n "$tk_install_path" ];then
    tk_chmod_whl 750
    log_file="$HOME/.cache/Huawei/mxTuningKit/log/uninstall-log.log"
    $python_version -m pip uninstall $tk_package_name --log-file $log_file
    if test $? -ne 0; then
      echo "Uninstall mxTuningKit wheel package failed."
    fi
  else
    echo "There is no mxTuningKit wheel package to uninstall. Please check if it has been installed."
  fi
  tk_chmod_log 640 $log_file
}

print_error()
{
  echo "command arguments are wrong! Valid arguments are necessary as follows: "
  echo "----1 install cmd:'bash tk_user.sh install'"
  echo "----2 uninstall cmd:'bash tk_user.sh uninstall'"
}

main()
{
  umask 027
  case $cmd_para in
    install)
      tk_install_whl
      ;;
    uninstall)
      tk_uninstall_whl
      ;;
    *)
      print_error
  esac
}

main
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词