github.com/nxtrace/NTrace-core@v1.3.1-0.20240513132635-39169291e8c9/nt_install.sh (about)

     1  #!/bin/bash
     2  
     3  if [ "$1" = "http" ]; then
     4      protocol="http"
     5  else
     6      protocol="https"
     7  fi
     8  
     9  
    10  Green_font="\033[32m"
    11  Yellow_font="\033[33m"
    12  Red_font="\033[31m"
    13  Font_suffix="\033[0m"
    14  Info="${Green_font}[Info]${Font_suffix}"
    15  Error="${Red_font}[Error]${Font_suffix}"
    16  Tips="${Green_font}[Tips]${Font_suffix}"
    17  Temp_path="/var/tmp/nexttrace"
    18  
    19  checkRootPermit() {
    20      [[ $EUID -ne 0 ]] && echo -e "${Error} 请使用sudo/root权限运行本脚本" && exit 1
    21  }
    22  
    23  checkSystemArch() {
    24      arch=$(uname -m)
    25      if [[ $arch == "x86_64" ]]; then
    26      archParam="amd64"
    27      elif [[ $arch == "i386" ]]; then
    28      archParam="386"
    29      elif [[ $arch == "i686" ]]; then
    30      archParam="386"
    31      elif [[ $arch == "aarch64" ]]; then
    32      archParam="arm64"
    33      elif [[ $arch == "armv7l" ]] || [[ $arch == "armv7ml" ]]; then
    34      archParam="armv7"
    35      elif [[ $arch == "mips" ]]; then
    36      archParam="mips"
    37      fi
    38  }
    39  
    40  checkSystemDistribution() {
    41      case "$OSTYPE" in
    42      linux*)
    43      osDistribution="linux"
    44  
    45      if [ ! -d "/usr/local" ];
    46      then
    47      downPath="/usr/bin/nexttrace"
    48      else
    49      downPath="/usr/local/bin/nexttrace"
    50      fi
    51  
    52      ;;
    53      *)
    54      echo "unknown: $OSTYPE"
    55      exit 1
    56      ;;
    57      esac
    58  }
    59  
    60  downloadBinrayFile() {
    61      echo -e "${Info} 获取最新版的 NextTrace 发行版文件信息"
    62      for i in {1..3}; do
    63          downloadUrls=$(curl -sL ${protocol}://www.nxtrace.org/api/dist/core/nexttrace_${osDistribution}_${archParam} --connect-timeout 1.5)
    64          if [ $? -eq 0 ]; then
    65              break
    66          fi
    67      done
    68      if [ $? -eq 0 ]; then
    69          primaryUrl=$(echo ${downloadUrls} | awk -F '|' '{print $1}')
    70          backupUrl=$(echo ${downloadUrls} | awk -F '|' '{print $2}')
    71          echo -e "${Info} 正在尝试从 Primary 节点下载 NextTrace"
    72          for i in {1..3}; do
    73              curl -sL ${primaryUrl} -o ${Temp_path} --connect-timeout 1.5
    74              if [ $? -eq 0 ]; then
    75                  changeMode
    76                  mv ${Temp_path} ${downPath}
    77                  echo -e "${Info} NextTrace 现在已经在您的系统中可用"
    78                  return
    79              fi
    80          done
    81          if [ -z ${backupUrl} ]; then
    82              echo -e "${Error} 从 Primary 节点下载失败,且 Backup 节点为空,无法下载 NextTrace"
    83              exit 1
    84          fi
    85          echo -e "${Error} 从 Primary 节点下载失败,正在尝试从 Backup 节点下载 NextTrace"
    86          for i in {1..3}; do
    87              curl -sL ${backupUrl} -o ${Temp_path} --connect-timeout 1.5
    88              if [ $? -eq 0 ]; then
    89                  changeMode
    90                  mv ${Temp_path} ${downPath}
    91                  echo -e "${Info} NextTrace 现在已经在您的系统中可用"
    92                  return
    93              fi
    94          done
    95          echo -e "${Error} NextTrace 下载失败,请检查您的网络是否正常"
    96          exit 1
    97      else
    98          echo -e "${Error} 获取下载地址失败,请检查您的网络是否正常"
    99          exit 1
   100      fi
   101  }
   102  
   103  changeMode() {
   104      chmod +x ${Temp_path} &> /dev/null
   105  }
   106  
   107  runBinrayFileHelp() {
   108      if [ -e ${downPath} ]; then
   109      ${downPath} --version
   110      echo -e "${Tips} 一切准备就绪!使用命令 nexttrace 1.1.1.1 开始您的第一次路由测试吧~ 更多进阶命令玩法可以用 nexttrace -h 查看哦\n       关于软件卸载,因为nexttrace是绿色版单文件,卸载只需输入命令 rm ${downPath} 即可"
   111      fi
   112  }
   113  
   114  # Check Procedure
   115  checkRootPermit
   116  checkSystemDistribution
   117  checkSystemArch
   118  
   119  # Download Procedure
   120  downloadBinrayFile
   121  
   122  # Run Procedure
   123  runBinrayFileHelp
   124