forked from turlockmike/murl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·252 lines (214 loc) · 8.3 KB
/
install.sh
File metadata and controls
executable file
·252 lines (214 loc) · 8.3 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/usr/bin/env bash
#
# Install script for murl
# Usage: curl -sSL https://raw.githubusercontent.com/turlockmike/murl/main/install.sh | bash
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Cleanup function
cleanup() {
if [[ -n "$TEMP_DIR" && -d "$TEMP_DIR" ]]; then
rm -rf "$TEMP_DIR"
fi
}
# Function to detect shell and return appropriate rc file
get_shell_rc_file() {
local rc_file="$HOME/.bashrc"
if [[ -n "$SHELL" ]]; then
case "$SHELL" in
*/zsh)
rc_file="$HOME/.zshrc"
;;
*/bash)
rc_file="$HOME/.bashrc"
;;
*)
# Default to bash if unknown
rc_file="$HOME/.bashrc"
;;
esac
fi
echo "$rc_file"
}
# Set trap to cleanup on exit
trap cleanup EXIT
echo -e "${GREEN}Installing murl...${NC}"
# Check if Python is installed
if ! command -v python3 &> /dev/null && ! command -v python &> /dev/null; then
echo -e "${RED}Error: Python 3 is required but not installed.${NC}"
echo "Please install Python 3.10 or later and try again."
exit 1
fi
# Determine Python command
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
else
PYTHON_CMD="python"
fi
# Check Python version
PYTHON_VERSION=$($PYTHON_CMD -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
PYTHON_MAJOR=$($PYTHON_CMD -c 'import sys; print(sys.version_info.major)')
PYTHON_MINOR=$($PYTHON_CMD -c 'import sys; print(sys.version_info.minor)')
if [[ "$PYTHON_MAJOR" -lt 3 ]] || [[ "$PYTHON_MAJOR" -eq 3 && "$PYTHON_MINOR" -lt 10 ]]; then
echo -e "${RED}Error: Python 3.10 or later is required.${NC}"
echo "Found: Python $PYTHON_VERSION"
exit 1
fi
echo -e "${GREEN}✓ Python $PYTHON_VERSION detected${NC}"
# Check if pip is installed
if ! $PYTHON_CMD -m pip --version &> /dev/null; then
echo -e "${YELLOW}Warning: pip is not installed.${NC}"
echo "Please install pip using your system package manager:"
echo " - Ubuntu/Debian: sudo apt-get install python3-pip"
echo " - Fedora/RHEL: sudo dnf install python3-pip"
echo " - macOS: python3 -m ensurepip --upgrade"
exit 1
fi
# Check if curl is installed
if ! command -v curl &> /dev/null; then
echo -e "${RED}Error: curl is required but not installed.${NC}"
echo "Please install curl using your system package manager:"
echo " - Ubuntu/Debian: sudo apt-get install curl"
echo " - Fedora/RHEL: sudo dnf install curl"
echo " - macOS: curl is pre-installed"
exit 1
fi
echo -e "${GREEN}Downloading murl from GitHub releases...${NC}"
# Get the latest release version using GitHub API
GITHUB_API_URL="https://api.github.com/repos/turlockmike/murl/releases/latest"
RELEASE_JSON=$(curl -fsSL "$GITHUB_API_URL" 2>&1)
CURL_EXIT_CODE=$?
if [[ $CURL_EXIT_CODE -ne 0 ]]; then
echo -e "${RED}Error: Failed to fetch release information from GitHub API${NC}"
echo "Please check your internet connection and try again."
exit 1
fi
LATEST_RELEASE=$(echo "$RELEASE_JSON" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/' | head -n1)
if [[ -z "$LATEST_RELEASE" ]]; then
echo -e "${RED}Error: Failed to parse latest release version${NC}"
echo "Please report this issue at https://github.com/turlockmike/murl/issues"
exit 1
fi
echo -e "${GREEN}Latest version: $LATEST_RELEASE${NC}"
# Create temporary directory
TEMP_DIR=$(mktemp -d)
if [[ -z "$TEMP_DIR" || ! -d "$TEMP_DIR" ]]; then
echo -e "${RED}Error: Failed to create temporary directory${NC}"
exit 1
fi
cd "$TEMP_DIR"
# Download the wheel file from the latest release
WHEEL_URL="https://github.com/turlockmike/murl/releases/download/v${LATEST_RELEASE}/mcp_curl-${LATEST_RELEASE}-py3-none-any.whl"
echo -e "${GREEN}Downloading from: $WHEEL_URL${NC}"
if ! curl -fL -o "mcp_curl-${LATEST_RELEASE}-py3-none-any.whl" "$WHEEL_URL"; then
echo -e "${RED}Error: Failed to download release${NC}"
echo "URL: $WHEEL_URL"
echo "This might mean the release doesn't have the expected wheel file."
exit 1
fi
echo -e "${GREEN}Installing murl from GitHub release...${NC}"
# Install murl
if [[ "$EUID" -eq 0 ]]; then
# Running as root
$PYTHON_CMD -m pip install "mcp_curl-${LATEST_RELEASE}-py3-none-any.whl"
echo -e "${GREEN}✓ murl installed successfully${NC}"
else
# Running as user - try with --user flag
if $PYTHON_CMD -m pip install --user "mcp_curl-${LATEST_RELEASE}-py3-none-any.whl"; then
echo -e "${GREEN}✓ murl installed successfully${NC}"
# Check if user's local bin is in PATH
USER_BIN="$HOME/.local/bin"
if [[ -d "$USER_BIN" && ":$PATH:" != *":$USER_BIN:"* ]]; then
# Detect user's shell for appropriate rc file
RC_FILE=$(get_shell_rc_file)
echo -e "${YELLOW}Warning: $USER_BIN is not in your PATH${NC}"
echo ""
echo "Add the following to your $RC_FILE:"
echo ""
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
echo "Then run:"
echo ""
echo " source $RC_FILE"
echo " murl --version"
echo ""
fi
else
# If --user fails, try with sudo
echo -e "${YELLOW}User installation failed. Trying with sudo...${NC}"
if command -v sudo &> /dev/null; then
sudo $PYTHON_CMD -m pip install "mcp_curl-${LATEST_RELEASE}-py3-none-any.whl"
echo -e "${GREEN}✓ murl installed successfully${NC}"
else
echo -e "${RED}Error: Cannot install murl. Please run as root or install pip for your user.${NC}"
exit 1
fi
fi
fi
# Function to provide PATH instructions
provide_path_instructions() {
local bin_dir="$1"
local rc_file
rc_file=$(get_shell_rc_file)
echo -e "${YELLOW}Installation completed, but 'murl' command not found in PATH.${NC}"
echo ""
echo "Add the following to your $rc_file:"
echo ""
echo " export PATH=\"$bin_dir:\$PATH\""
echo ""
echo "Then run:"
echo ""
echo " source $rc_file"
echo " murl --version"
echo ""
}
# Verify installation
if command -v murl &> /dev/null; then
VERSION=$(murl --version 2>&1 | head -n1 || echo "unknown")
echo -e "${GREEN}✓ Installation complete!${NC}"
echo -e "murl version: $VERSION"
echo ""
echo "Usage: murl http://localhost:3000/tools"
echo "Help: murl --help"
else
# Determine where pip installed the package
PYTHON_SCRIPTS_DIR=""
# Try to get the user scripts directory from Python
if [[ "$EUID" -ne 0 ]]; then
# For user installation, try to get the user base bin directory
PYTHON_SCRIPTS_DIR=$($PYTHON_CMD -c "import site; import os; print(os.path.join(site.USER_BASE, 'bin'))" 2>/dev/null)
# Ensure the derived directory exists and contains the murl executable
if [[ -z "$PYTHON_SCRIPTS_DIR" || ! -d "$PYTHON_SCRIPTS_DIR" || ! -x "$PYTHON_SCRIPTS_DIR/murl" ]]; then
PYTHON_SCRIPTS_DIR=""
fi
# If that doesn't exist or doesn't contain murl, try common locations
if [[ -z "$PYTHON_SCRIPTS_DIR" ]]; then
# Check common user bin locations
if [[ -d "$HOME/.local/bin" && -x "$HOME/.local/bin/murl" ]]; then
PYTHON_SCRIPTS_DIR="$HOME/.local/bin"
elif [[ -d "$HOME/Library/Python/$PYTHON_VERSION/bin" && -x "$HOME/Library/Python/$PYTHON_VERSION/bin/murl" ]]; then
PYTHON_SCRIPTS_DIR="$HOME/Library/Python/$PYTHON_VERSION/bin"
fi
fi
else
# For system installation, check common system bin directories
for dir in /usr/local/bin /usr/bin; do
if [[ -d "$dir" && -x "$dir/murl" ]]; then
PYTHON_SCRIPTS_DIR="$dir"
break
fi
done
fi
# If we found a scripts directory that contains murl, provide instructions
if [[ -n "$PYTHON_SCRIPTS_DIR" && -x "$PYTHON_SCRIPTS_DIR/murl" ]]; then
provide_path_instructions "$PYTHON_SCRIPTS_DIR"
else
# Fallback to generic message
echo -e "${YELLOW}Installation completed, but 'murl' command not found in PATH.${NC}"
echo "You may need to add the Python scripts directory to your PATH."
fi
fi