This repository was archived by the owner on Mar 20, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·214 lines (177 loc) · 5.02 KB
/
install.sh
File metadata and controls
executable file
·214 lines (177 loc) · 5.02 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
#!/usr/bin/env bash
# RestMan installer script for Linux and macOS
# Usage: curl -fsSL https://restman.sh/install | bash
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
REPO="cadamsdev/restman"
INSTALL_DIR="${RESTMAN_INSTALL:-$HOME/.restman}"
BIN_DIR="$INSTALL_DIR/bin"
EXECUTABLE="$BIN_DIR/restman"
# Detect OS and architecture
detect_platform() {
local os arch
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux*)
os="linux"
;;
darwin*)
os="darwin"
;;
*)
echo -e "${RED}Unsupported OS: $os${NC}" >&2
exit 1
;;
esac
case "$arch" in
x86_64 | amd64)
arch="x64"
;;
aarch64 | arm64)
arch="arm64"
;;
*)
echo -e "${RED}Unsupported architecture: $arch${NC}" >&2
exit 1
;;
esac
echo "${os}-${arch}"
}
# Get the latest release version from GitHub
get_latest_version() {
local version
version=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$version" ]; then
echo -e "${RED}Failed to get latest version${NC}" >&2
exit 1
fi
echo "$version"
}
# Download and extract RestMan
install_restman() {
local platform version download_url archive_name
platform=$(detect_platform)
version=$(get_latest_version)
echo -e "${GREEN}Installing RestMan ${version} for ${platform}...${NC}"
# Construct download URL
archive_name="restman-${platform}"
if [[ "$platform" == "linux-"* ]]; then
archive_name="${archive_name}.tar.gz"
else
archive_name="${archive_name}.zip"
fi
download_url="https://github.com/$REPO/releases/download/${version}/${archive_name}"
echo "Downloading from: $download_url"
# Create directories
mkdir -p "$BIN_DIR"
# Download and extract
local temp_dir
temp_dir=$(mktemp -d)
cd "$temp_dir"
if ! curl -fL "$download_url" -o "$archive_name"; then
echo -e "${RED}Failed to download RestMan${NC}" >&2
exit 1
fi
# Extract based on format
if [[ "$archive_name" == *.tar.gz ]]; then
tar -xzf "$archive_name"
else
unzip -q "$archive_name"
fi
# Find and move binary to install directory
# The archive contains a directory like restman-platform/restman
local binary_path
binary_path=$(find . -name "restman" -type f | head -n 1)
if [ -n "$binary_path" ] && [ -f "$binary_path" ]; then
mv "$binary_path" "$EXECUTABLE"
chmod +x "$EXECUTABLE"
else
echo -e "${RED}Binary not found in archive${NC}" >&2
rm -rf "$temp_dir"
exit 1
fi
# macOS specific: Remove quarantine attribute
if [[ "$(uname -s)" == "Darwin" ]]; then
echo -e "${YELLOW}Removing macOS quarantine attribute...${NC}"
xattr -d com.apple.quarantine "$EXECUTABLE" 2>/dev/null || true
fi
echo -e "${GREEN}✓ RestMan installed to $EXECUTABLE${NC}"
# Cleanup
rm -rf "$temp_dir"
}
# Add to PATH by updating shell profile
update_path() {
local shell_profile shell_name
# Detect shell from $SHELL environment variable
shell_name=$(basename "${SHELL:-/bin/sh}")
case "$shell_name" in
bash)
if [ -f "$HOME/.bashrc" ]; then
shell_profile="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
shell_profile="$HOME/.bash_profile"
else
shell_profile="$HOME/.profile"
fi
;;
zsh)
shell_profile="$HOME/.zshrc"
;;
fish)
# Ensure fish config directory exists
mkdir -p "$HOME/.config/fish"
shell_profile="$HOME/.config/fish/config.fish"
;;
*)
# Default to .profile for unknown shells
shell_profile="$HOME/.profile"
;;
esac
# Check if already in PATH
if [[ ":$PATH:" == *":$BIN_DIR:"* ]]; then
echo -e "${GREEN}✓ $BIN_DIR is already in PATH${NC}"
return
fi
# Add to profile
local export_line
if [[ "$shell_name" == "fish" ]]; then
export_line="set -gx PATH \$PATH $BIN_DIR"
else
export_line="export PATH=\"\$PATH:$BIN_DIR\""
fi
# Check if BIN_DIR is already configured in the profile
if ! grep -q "$BIN_DIR" "$shell_profile" 2>/dev/null; then
echo "" >> "$shell_profile"
echo "# RestMan" >> "$shell_profile"
echo "$export_line" >> "$shell_profile"
echo -e "${GREEN}✓ Added $BIN_DIR to PATH in $shell_profile${NC}"
echo -e "${YELLOW}Run 'source $shell_profile' or restart your terminal to use restman${NC}"
else
echo -e "${GREEN}✓ $BIN_DIR already configured in $shell_profile${NC}"
fi
}
# Main installation flow
main() {
echo -e "${GREEN}RestMan Installer${NC}"
echo ""
install_restman
update_path
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo "To get started:"
echo " 1. Reload your shell or run one of:"
echo " source ~/.bashrc"
echo " source ~/.zshrc"
echo " source ~/.config/fish/config.fish"
echo " 2. Run: restman"
echo ""
echo "For more information, visit: https://github.com/$REPO"
}
main