github.com/tencent/goom@v1.0.1/tool/permission_denied.sh (about)

     1  #! /bin/bash
     2  
     3  # 此脚本用于解决 permission denied 问题
     4  # 执行脚本替换 sdk/pkg/tool/link 文件
     5  # 在 link 文件中添加更改权限 (max_prot=7) 的脚本
     6  
     7  ############################################################
     8  # Process the input options. Add options as needed.        #
     9  ############################################################
    10  
    11  Help() {
    12    # Display Help
    13    echo "###############################################"
    14    echo "  __  __  __             __  __      ___ __  "
    15    echo " / _\`/  \/  \|\/|   |\/|/  \/  \`|__/|__ |__) "
    16    echo " \__>\__/\__/|  |   |  |\__/\__,|  \|___|  \ "
    17    echo "# 此脚本用于解决 MAC 环境下 permission denied 问题."
    18    echo "# 执行脚本替换 sdk/pkg/tool/link 文件, "
    19    echo "# 在 link 文件中添加更改编译产物执行权限(max_prot=7)的脚本."
    20    echo "使用方法: 选项 [-h|i|u|c]"
    21    echo "选项:"
    22    echo " -h     显示帮助."
    23    echo " -i     安装."
    24    echo " -u     卸载."
    25    echo " -c     查看安装状态."
    26    echo
    27    Check
    28  }
    29  
    30  Check() {
    31    echo `go version`
    32    echo "go root $(go env GOROOT)"
    33  
    34    TOOL_DIR=$(go env GOTOOLDIR)
    35    LINE=$(head -n 1 ${TOOL_DIR}/link)
    36    if [[ "$LINE" == "#!/usr/bin/env python3" ]]; then
    37      echo "当前状态: 已安装"
    38    else
    39      echo "当前状态: 未安装"
    40    fi
    41  }
    42  
    43  Install() {
    44    TOOL_DIR=$(go env GOTOOLDIR)
    45    WORK_DIR=$(cd $(dirname $0); pwd)
    46    LINE=$(head -n 1 ${TOOL_DIR}/link)
    47  
    48    if [[ "$LINE" == "#!/usr/bin/env python3" ]]; then
    49      echo "already installed."
    50      return 0
    51    fi
    52  
    53    if [ -e ${WORK_DIR}/link ]
    54    then
    55        mv ${TOOL_DIR}/link ${TOOL_DIR}/original_link
    56        cp ${WORK_DIR}/link ${TOOL_DIR}/link
    57        echo "replaced ${TOOL_DIR}/link with ${WORK_DIR}/link"
    58        echo "install success."
    59        return 0
    60    else
    61        echo "install fail: file not exists: ${TOOL_DIR}/link"
    62        return 1
    63    fi
    64  }
    65  
    66  Uninstall() {
    67    TOOL_DIR=$(go env GOTOOLDIR)
    68    LINE=$(head -n 1 ${TOOL_DIR}/link)
    69  
    70    if [[ "$LINE" == "#!/usr/bin/env python3" ]]; then
    71      mv ${TOOL_DIR}/original_link ${TOOL_DIR}/link
    72      echo "recovered ${TOOL_DIR}/link success."
    73    else
    74      echo "already recovered."
    75    fi
    76  }
    77  
    78  # Get the options
    79  while getopts ":hiuc" option; do
    80    case $option in
    81    h) # display Help
    82      Help
    83      exit
    84      ;;
    85    i) # install
    86      Install
    87      exit
    88      ;;
    89    u) # uninstall
    90      Uninstall
    91      exit
    92      ;;
    93    c) # check
    94      Check
    95      exit
    96      ;;
    97    \?) # Invalid option
    98      echo "Error: Invalid option. use -h show help"
    99      Help
   100      exit
   101      ;;
   102    esac
   103  done
   104  
   105  Help