-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·86 lines (74 loc) · 2.08 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·86 lines (74 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}Installing Ralphy...${NC}"
# Check if Go is installed
if ! command -v go &> /dev/null; then
echo -e "${RED}Error: Go is not installed.${NC}"
echo "Install Go from https://go.dev/dl/ and try again."
exit 1
fi
GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
echo -e "Found Go ${GO_VERSION}"
# Get script directory (where the source code is)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Build
echo -e "Building..."
go build -o ralphy .
# Determine install method
INSTALL_DIR=""
NEED_PATH_UPDATE=false
if [[ -d "/usr/local/bin" ]] && [[ -w "/usr/local/bin" ]]; then
INSTALL_DIR="/usr/local/bin"
elif [[ -d "$HOME/.local/bin" ]]; then
INSTALL_DIR="$HOME/.local/bin"
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
NEED_PATH_UPDATE=true
fi
else
# Use go install
INSTALL_DIR="$HOME/go/bin"
mkdir -p "$INSTALL_DIR"
if [[ ":$PATH:" != *":$HOME/go/bin:"* ]]; then
NEED_PATH_UPDATE=true
fi
fi
# Install
echo -e "Installing to ${INSTALL_DIR}..."
if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ ! -w "/usr/local/bin" ]]; then
sudo cp ralphy "$INSTALL_DIR/"
else
cp ralphy "$INSTALL_DIR/"
fi
# Clean up local binary
rm -f ralphy
# Check PATH
if $NEED_PATH_UPDATE; then
echo ""
echo -e "${YELLOW}Warning: ${INSTALL_DIR} is not in your PATH.${NC}"
echo ""
echo "Add this to your ~/.bashrc or ~/.zshrc:"
echo ""
echo -e " ${GREEN}export PATH=\"\$PATH:${INSTALL_DIR}\"${NC}"
echo ""
echo "Then run: source ~/.bashrc (or ~/.zshrc)"
echo ""
fi
# Verify installation
if command -v ralphy &> /dev/null; then
echo -e "${GREEN}✓ Ralphy installed successfully!${NC}"
echo ""
echo "Usage:"
echo " cd /path/to/your/project"
echo " ralphy"
else
echo -e "${GREEN}✓ Ralphy installed to ${INSTALL_DIR}/ralphy${NC}"
if $NEED_PATH_UPDATE; then
echo -e "${YELLOW}Update your PATH to use it globally.${NC}"
fi
fi