|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Weasel Installer |
| 5 | +# Downloads and installs weaselup, then runs it to install weasel |
| 6 | + |
| 7 | +WEASEL_DIR="${WEASEL_DIR:-$HOME/.weasel}" |
| 8 | +WEASEL_BIN_DIR="$WEASEL_DIR/bin" |
| 9 | + |
| 10 | +REPO="slvDev/weasel" |
| 11 | +WEASELUP_URL="https://raw.githubusercontent.com/$REPO/main/weaselup/weaselup" |
| 12 | + |
| 13 | +main() { |
| 14 | + echo "Installing weaselup..." |
| 15 | + |
| 16 | + # Create directories |
| 17 | + mkdir -p "$WEASEL_BIN_DIR" |
| 18 | + |
| 19 | + # Download weaselup |
| 20 | + if command -v curl &> /dev/null; then |
| 21 | + curl -fsSL "$WEASELUP_URL" -o "$WEASEL_BIN_DIR/weaselup" |
| 22 | + elif command -v wget &> /dev/null; then |
| 23 | + wget -qO "$WEASEL_BIN_DIR/weaselup" "$WEASELUP_URL" |
| 24 | + else |
| 25 | + echo "Error: curl or wget is required" |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | + |
| 29 | + # Make executable |
| 30 | + chmod +x "$WEASEL_BIN_DIR/weaselup" |
| 31 | + |
| 32 | + # Add to PATH |
| 33 | + add_to_path |
| 34 | + |
| 35 | + echo "" |
| 36 | + echo "weaselup installed to $WEASEL_BIN_DIR" |
| 37 | + echo "" |
| 38 | + |
| 39 | + # Run weaselup to install weasel |
| 40 | + "$WEASEL_BIN_DIR/weaselup" |
| 41 | + |
| 42 | + echo "" |
| 43 | + echo "Done! Run 'weaselup' to update weasel." |
| 44 | +} |
| 45 | + |
| 46 | +add_to_path() { |
| 47 | + local shell_name |
| 48 | + shell_name=$(basename "$SHELL") |
| 49 | + |
| 50 | + case $shell_name in |
| 51 | + zsh) |
| 52 | + add_to_file "$HOME/.zshenv" |
| 53 | + ;; |
| 54 | + bash) |
| 55 | + if [[ -f "$HOME/.bash_profile" ]]; then |
| 56 | + add_to_file "$HOME/.bash_profile" |
| 57 | + else |
| 58 | + add_to_file "$HOME/.bashrc" |
| 59 | + fi |
| 60 | + ;; |
| 61 | + fish) |
| 62 | + add_to_fish |
| 63 | + ;; |
| 64 | + *) |
| 65 | + echo "Note: Add $WEASEL_BIN_DIR to your PATH manually" |
| 66 | + return |
| 67 | + ;; |
| 68 | + esac |
| 69 | + |
| 70 | + echo "Added $WEASEL_BIN_DIR to PATH in your shell config" |
| 71 | + echo "Run 'source ~/.${shell_name}rc' or restart your terminal" |
| 72 | +} |
| 73 | + |
| 74 | +add_to_file() { |
| 75 | + local file="$1" |
| 76 | + local line="export PATH=\"\$PATH:$WEASEL_BIN_DIR\"" |
| 77 | + |
| 78 | + # Check if already added |
| 79 | + if [[ -f "$file" ]] && grep -q "$WEASEL_BIN_DIR" "$file"; then |
| 80 | + return |
| 81 | + fi |
| 82 | + |
| 83 | + echo "" >> "$file" |
| 84 | + echo "# Weasel" >> "$file" |
| 85 | + echo "$line" >> "$file" |
| 86 | +} |
| 87 | + |
| 88 | +add_to_fish() { |
| 89 | + local fish_config="$HOME/.config/fish/config.fish" |
| 90 | + mkdir -p "$(dirname "$fish_config")" |
| 91 | + |
| 92 | + if [[ -f "$fish_config" ]] && grep -q "$WEASEL_BIN_DIR" "$fish_config"; then |
| 93 | + return |
| 94 | + fi |
| 95 | + |
| 96 | + echo "" >> "$fish_config" |
| 97 | + echo "# Weasel" >> "$fish_config" |
| 98 | + echo "fish_add_path $WEASEL_BIN_DIR" >> "$fish_config" |
| 99 | +} |
| 100 | + |
| 101 | +main |
0 commit comments