install.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # Use environment variable VERSION if set, otherwise use default
  3. VERSION=${VERSION:-0.0.1}
  4. # Detect OS and architecture
  5. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  6. ARCH=$(uname -m)
  7. # Convert architecture naming
  8. if [ "$ARCH" = "x86_64" ]; then
  9. ARCH="amd64"
  10. elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
  11. ARCH="arm64"
  12. else
  13. echo "Unsupported architecture: $ARCH"
  14. exit 1
  15. fi
  16. # Only allow macOS and Linux
  17. if [ "$OS" != "darwin" ] && [ "$OS" != "linux" ]; then
  18. echo "Unsupported operating system: $OS"
  19. exit 1
  20. fi
  21. # Define download URL and binary name
  22. BINARY_NAME="dify-plugin-$OS-$ARCH"
  23. DOWNLOAD_URL="https://github.com/langgenius/dify-plugin-daemon/releases/download/$VERSION/$BINARY_NAME"
  24. # Set installation directory based on OS
  25. if [ "$OS" = "darwin" ]; then
  26. INSTALL_DIR="$HOME/.local/bin"
  27. mkdir -p "$INSTALL_DIR"
  28. NEED_SUDO=false
  29. else
  30. INSTALL_DIR="/usr/local/bin"
  31. # Check if we have write permission to /usr/local/bin
  32. if [ -w "$INSTALL_DIR" ]; then
  33. NEED_SUDO=false
  34. else
  35. NEED_SUDO=true
  36. fi
  37. fi
  38. # Create temporary directory for download
  39. TMP_DIR=$(mktemp -d)
  40. cd "$TMP_DIR" || exit 1
  41. # Download the binary
  42. echo "Downloading $BINARY_NAME..."
  43. if command -v curl >/dev/null 2>&1; then
  44. curl -L -o "dify-plugin-daemon" "$DOWNLOAD_URL"
  45. elif command -v wget >/dev/null 2>&1; then
  46. wget -O "dify-plugin-daemon" "$DOWNLOAD_URL"
  47. else
  48. echo "Error: Neither curl nor wget is installed"
  49. rm -rf "$TMP_DIR"
  50. exit 1
  51. fi
  52. # Make binary executable
  53. chmod +x "dify-plugin-daemon"
  54. # Install the binary with the new name
  55. if [ "$NEED_SUDO" = true ]; then
  56. echo "Installing to $INSTALL_DIR (requires sudo)..."
  57. sudo mv "dify-plugin-daemon" "$INSTALL_DIR/dify-plugin"
  58. else
  59. echo "Installing to $INSTALL_DIR..."
  60. mv "dify-plugin-daemon" "$INSTALL_DIR/dify-plugin"
  61. fi
  62. # Clean up
  63. rm -rf "$TMP_DIR"
  64. # For macOS, ensure ~/.local/bin is in PATH
  65. if [ "$OS" = "darwin" ]; then
  66. if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
  67. SHELL_CONFIG=""
  68. if [ -f "$HOME/.zshrc" ]; then
  69. SHELL_CONFIG="$HOME/.zshrc"
  70. elif [ -f "$HOME/.bashrc" ]; then
  71. SHELL_CONFIG="$HOME/.bashrc"
  72. elif [ -f "$HOME/.bash_profile" ]; then
  73. SHELL_CONFIG="$HOME/.bash_profile"
  74. fi
  75. if [ -n "$SHELL_CONFIG" ]; then
  76. echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$SHELL_CONFIG"
  77. echo "Added $INSTALL_DIR to PATH in $SHELL_CONFIG"
  78. echo "Please run: source $SHELL_CONFIG"
  79. else
  80. echo "Please add the following line to your shell configuration file:"
  81. echo "export PATH=\"\$PATH:$INSTALL_DIR\""
  82. fi
  83. fi
  84. fi
  85. echo "Installation completed! The dify plugin daemon has been installed to $INSTALL_DIR/dify-plugin"