build.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. # Check if Rust is installed
  3. if ! command -v rustc &> /dev/null
  4. then
  5. echo "Rust is not installed. Installing Rust..."
  6. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
  7. # Source cargo environment
  8. export PATH="$HOME/.cargo/bin:$PATH"
  9. source "$HOME/.cargo/env"
  10. cargo update
  11. else
  12. echo "Rust is already installed. Skipping installation."
  13. fi
  14. # Ensure cargo is in PATH
  15. export PATH="$HOME/.cargo/bin:$PATH"
  16. # Continue with build process
  17. # if dev profile, build with dev profile
  18. if [ "$1" = "dev" ]; then
  19. cargo build --profile dev && cargo install --profile dev --path . --root ~/.local
  20. elif [ "$1" = "offline" ]; then
  21. cargo build --profile dev --offline && cargo install --profile dev --offline --path . --root ~/.local
  22. else
  23. cargo build --release && cargo install --path . --root ~/.local
  24. fi
  25. if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
  26. if ! grep -Fxq 'export PATH="$HOME/.local/bin:$PATH"' ~/.bashrc; then
  27. echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
  28. fi
  29. if ! grep -Fxq 'export PATH="$HOME/.local/bin:$PATH"' ~/.zshrc; then
  30. echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
  31. fi
  32. export PATH="$HOME/.local/bin:$PATH"
  33. fi