install.sh: explicit build targets and auto-fix PATH

- Build g3 and studio explicitly with -p flags
- Detect shell and rc file (zsh/bash/fish)
- Auto-add PATH to rc file with user confirmation
- Handle case where PATH is in rc but not loaded
This commit is contained in:
Dhanji R. Prasanna
2026-01-26 12:26:40 +11:00
parent 83f68dae17
commit 712eca1904

View File

@@ -9,7 +9,7 @@ INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
echo "Building g3 and studio (release)..."
cargo build --release
cargo build --release -p g3 -p studio
echo "Installing to $INSTALL_DIR..."
cp target/release/g3 "$INSTALL_DIR/"
@@ -34,10 +34,52 @@ echo " $INSTALL_DIR/g3"
echo " $INSTALL_DIR/g3-studio"
echo " $INSTALL_DIR/studio -> g3-studio"
# Check if ~/.local/bin is in PATH
# Check if ~/.local/bin is in PATH and fix if needed
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo ""
echo "⚠️ $INSTALL_DIR is not in your PATH"
echo " Add this to your shell rc file:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
# Detect shell config file
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
zsh) RC_FILE="$HOME/.zshrc" ;;
bash)
# macOS uses .bash_profile, Linux uses .bashrc
if [[ "$OSTYPE" == "darwin"* ]]; then
RC_FILE="$HOME/.bash_profile"
else
RC_FILE="$HOME/.bashrc"
fi
;;
fish) RC_FILE="$HOME/.config/fish/config.fish" ;;
*) RC_FILE="" ;;
esac
if [ -n "$RC_FILE" ]; then
# Check if it's already in the rc file (just not loaded in current session)
if grep -q '\.local/bin' "$RC_FILE" 2>/dev/null; then
echo " (Already in $RC_FILE, just not loaded in this session)"
echo " Run: source $RC_FILE"
else
echo ""
read -p " Add to $RC_FILE? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
echo '' >> "$RC_FILE"
if [[ "$SHELL_NAME" == "fish" ]]; then
echo 'set -gx PATH $HOME/.local/bin $PATH' >> "$RC_FILE"
else
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$RC_FILE"
fi
echo " ✅ Added to $RC_FILE"
echo " Run: source $RC_FILE"
else
echo " Skipped. Add manually:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
fi
else
echo " Unknown shell ($SHELL_NAME). Add this to your shell rc file:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
fi