install.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/sh
  2. set -eo pipefail
  3. # Reset
  4. Color_Off=''
  5. # Regular Colors
  6. Red=''
  7. Green=''
  8. Dim='' # White
  9. # Bold
  10. Bold_White=''
  11. Bold_Green=''
  12. if [[ -t 1 ]]; then
  13. # Reset
  14. Color_Off='\033[0m' # Text Reset
  15. # Regular Colors
  16. Red='\033[0;31m' # Red
  17. Green='\033[0;32m' # Green
  18. Dim='\033[0;2m' # White
  19. # Bold
  20. Bold_Green='\033[1;32m' # Bold Green
  21. Bold_White='\033[1m' # Bold White
  22. fi
  23. error() {
  24. echo -e "${Red}error${Color_Off}:" "$@" >&2
  25. exit 1
  26. }
  27. info() {
  28. echo -e "${Dim}$@ ${Color_Off}"
  29. }
  30. info_bold() {
  31. echo -e "${Bold_White}$@ ${Color_Off}"
  32. }
  33. success() {
  34. echo -e "${Green}$@ ${Color_Off}"
  35. }
  36. command -v unzip >/dev/null ||
  37. error 'unzip is required to install dx'
  38. if [[ $# -gt 1 ]]; then
  39. error 'Too many arguments, only 1 are allowed. The first can be a specific tag of dx to install. (e.g. "dx-v0.7.1")'
  40. fi
  41. if [ "$OS" = "Windows_NT" ]; then
  42. target="x86_64-pc-windows-msvc"
  43. else
  44. case $(uname -sm) in
  45. "Darwin x86_64") target="x86_64-apple-darwin" ;;
  46. "Darwin arm64") target="aarch64-apple-darwin" ;;
  47. "Linux aarch64") target="aarch64-unknown-linux-gnu" ;;
  48. *) target="x86_64-unknown-linux-gnu" ;;
  49. esac
  50. fi
  51. GITHUB=${GITHUB-"https://github.com"}
  52. github_repo="$GITHUB/dioxuslabs/dioxus"
  53. exe_name=dx
  54. if [[ $# = 0 ]]; then
  55. dx_uri=$github_repo/releases/latest/download/dx-$target.zip
  56. else
  57. dx_uri=$github_repo/releases/download/$1/dx-$target.zip
  58. fi
  59. dx_install="${DX_INSTALL:-$HOME/.dx}"
  60. bin_dir="$dx_install/bin"
  61. exe="$bin_dir/dx"
  62. cargo_bin_dir="$HOME/.cargo/bin"
  63. cargo_bin_exe="$cargo_bin_dir/dx"
  64. if [ ! -d "$bin_dir" ]; then
  65. mkdir -p "$bin_dir"
  66. fi
  67. curl --fail --location --progress-bar --output "$exe.zip" "$dx_uri"
  68. if command -v unzip >/dev/null; then
  69. unzip -d "$bin_dir" -o "$exe.zip"
  70. else
  71. 7z x -o"$bin_dir" -y "$exe.zip"
  72. fi
  73. chmod +x "$exe"
  74. cp "$exe" "$cargo_bin_exe" || error "Failed to copy dx to $cargo_bin_dir"
  75. rm "$exe.zip"
  76. echo " installed: $cargo_bin_exe"
  77. echo
  78. echo "dx was installed successfully! 💫"
  79. echo
  80. if command -v dx >/dev/null; then
  81. echo "Run 'dx --help' to get started"
  82. else
  83. echo "Run '$exe --help' to get started"
  84. fi