update.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #/bash/sh
  2. echo "start upgrading to the latest version"
  3. if [ $1 == "latest" ]
  4. then
  5. version=`wget -qO- -t1 -T2 "https://api.github.com/repos/cnlh/nps/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'`
  6. else
  7. version=$1
  8. fi
  9. echo "the current latest version is "$version""
  10. download_base_url=https://github.com/cnlh/nps/releases/download/$version/
  11. if [ $4 ]
  12. then
  13. filename=""$2"_"$3"_v"$4"_"server".tar.gz"
  14. else
  15. filename=""$2"_"$3"_"server".tar.gz"
  16. fi
  17. complete_download_url=""$download_base_url""$filename""
  18. echo "start download file from "$complete_download_url""
  19. dir_name=`echo $RANDOM`
  20. mkdir $dir_name && cd $dir_name
  21. wget $complete_download_url >/dev/null 2>&1
  22. if [ ! -f "$filename" ]; then
  23. echo "download file failed!"
  24. rm -rf $dir_name
  25. exit
  26. fi
  27. echo "start extracting files"
  28. mkdir nps
  29. tar -xvf $filename -C ./nps >/dev/null 2>&1
  30. cd nps
  31. if [ -f "../../nps" ]; then
  32. echo "replace "../../nps"!"
  33. cp -rf nps ../../
  34. fi
  35. usr_dir=`which nps`
  36. if [ -f "$usr_dir" ]; then
  37. echo "replace "$usr_dir"!"
  38. cp -rf nps $usr_dir
  39. fi
  40. cd ../../ && rm -rf $dir_name
  41. echo "update complete!"
  42. echo -e "\033[32m please restart nps \033[0m"