-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·336 lines (267 loc) · 8.98 KB
/
install.sh
File metadata and controls
executable file
·336 lines (267 loc) · 8.98 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/bin/bash
set -e
REPO="LumoSolutions/yerd"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="yerd"
YERD_DIRS="/opt/yerd"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
detect_arch() {
local arch
arch=$(uname -m)
case $arch in
x86_64)
echo "amd64"
;;
aarch64|arm64)
echo "arm64"
;;
i386|i686)
echo "386"
;;
armv7l)
echo "arm"
;;
*)
print_error "Unsupported architecture: $arch"
exit 1
;;
esac
}
detect_os() {
local os
os=$(uname -s)
case $os in
Linux)
echo "linux"
;;
Darwin)
echo "darwin"
;;
*)
print_error "Unsupported operating system: $os"
exit 1
;;
esac
}
detect_distribution() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
elif [ -f /etc/arch-release ]; then
echo "arch"
elif [ -f /etc/debian_version ]; then
echo "debian"
elif [ -f /etc/redhat-release ]; then
echo "rhel"
else
echo "unknown"
fi
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
check_prerequisites() {
print_status "Checking prerequisites..."
if ! command_exists curl && ! command_exists wget; then
print_error "Neither curl nor wget found. Please install one of them."
local distro
distro=$(detect_distribution)
case $distro in
ubuntu|debian)
print_status "Try: sudo apt update && sudo apt install curl wget"
;;
arch|manjaro)
print_status "Try: sudo pacman -S curl wget"
;;
fedora)
print_status "Try: sudo dnf install curl wget"
;;
*)
print_status "Please install curl or wget using your system's package manager"
;;
esac
exit 1
fi
if ! command_exists tar; then
print_error "tar command not found. Please install tar."
exit 1
fi
print_success "Prerequisites check passed"
}
get_latest_version() {
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
if command_exists curl; then
curl -s "$api_url" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
elif command_exists wget; then
wget -qO- "$api_url" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
else
print_error "Failed to get latest version"
exit 1
fi
}
install_yerd() {
local version="$1"
local os="$2"
local arch="$3"
version=${version#v}
local filename="${BINARY_NAME}_${version}_${os}_${arch}.tar.gz"
local download_url="https://github.com/${REPO}/releases/download/v${version}/${filename}"
local temp_dir
temp_dir=$(mktemp -d)
print_status "Downloading YERD v${version} for ${os}/${arch}..."
if command_exists curl; then
if ! curl -sL "$download_url" -o "${temp_dir}/${filename}"; then
print_error "Failed to download using curl"
exit 1
fi
elif command_exists wget; then
if ! wget -q "$download_url" -O "${temp_dir}/${filename}"; then
print_error "Failed to download using wget"
exit 1
fi
fi
if [ ! -f "${temp_dir}/${filename}" ]; then
print_error "Failed to download ${filename}"
print_error "URL: ${download_url}"
exit 1
fi
print_status "Extracting archive..."
if ! tar -xzf "${temp_dir}/${filename}" -C "$temp_dir"; then
print_error "Failed to extract archive"
print_error "Archive might be corrupted or incompatible"
exit 1
fi
if [ ! -f "${temp_dir}/${BINARY_NAME}" ]; then
print_error "Binary not found in archive"
exit 1
fi
print_status "Installing YERD to ${INSTALL_DIR}..."
if [ -w "$INSTALL_DIR" ]; then
cp "${temp_dir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
else
print_warning "Installing to ${INSTALL_DIR} requires sudo privileges"
sudo cp "${temp_dir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
fi
rm -rf "$temp_dir"
print_success "YERD binary installed successfully"
}
setup_directories() {
print_status "Setting up YERD directories..."
if [ -w "$(dirname "$YERD_DIRS")" ]; then
mkdir -p "${YERD_DIRS}"/{bin,php,etc}
else
print_warning "Setting up directories in ${YERD_DIRS} requires sudo privileges"
sudo mkdir -p "${YERD_DIRS}"/{bin,php,etc}
if [ "$EUID" -ne 0 ]; then
read -p "Set user ownership for ${YERD_DIRS}? This allows installation without sudo. (y/N): " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo chown -R "$USER:$USER" "$YERD_DIRS"
print_success "User ownership set for ${YERD_DIRS}"
fi
fi
fi
print_success "YERD directories created"
}
verify_installation() {
print_status "Verifying installation..."
if command_exists "$BINARY_NAME"; then
local installed_version
installed_version=$($BINARY_NAME --version 2>/dev/null | head -n1 | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/v//' || echo "unknown")
if [ "$installed_version" = "unknown" ]; then
print_success "YERD installed successfully!"
else
print_success "YERD v${installed_version} installed successfully!"
fi
print_status "Try: ${BINARY_NAME} --help"
else
print_error "Installation failed. ${BINARY_NAME} command not found."
print_warning "Make sure ${INSTALL_DIR} is in your PATH"
if [[ ":$PATH:" != *":${INSTALL_DIR}:"* ]]; then
print_warning "${INSTALL_DIR} is not in your PATH"
print_status "Add this line to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
print_status "export PATH=\"${INSTALL_DIR}:\$PATH\""
print_status "Then run: source ~/.bashrc (or restart your shell)"
fi
exit 1
fi
}
main() {
echo "╔══════════════════════════════════════════════════════════════════════════════╗"
echo "║ YERD Installation Script ║"
echo "║ A powerful, developer-friendly tool for managing PHP versions ║"
echo "╚══════════════════════════════════════════════════════════════════════════════╝"
echo
local force_version=""
while [[ $# -gt 0 ]]; do
case $1 in
--version)
force_version="$2"
shift 2
;;
--help|-h)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --version VERSION Install specific version"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 Install latest version"
echo " $0 --version 1.0.0 Install version 1.0.0"
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
check_prerequisites
local os arch version
os=$(detect_os)
arch=$(detect_arch)
if [ -n "$force_version" ]; then
version="$force_version"
print_status "Installing specified version: v${version}"
else
print_status "Getting latest version from GitHub..."
version=$(get_latest_version)
if [ -z "$version" ]; then
print_error "Failed to get latest version"
exit 1
fi
print_status "Latest version: ${version}"
fi
install_yerd "$version" "$os" "$arch"
setup_directories
verify_installation
echo
print_success "🎉 YERD installation completed!"
echo
echo "Next steps:"
echo "1. Run: yerd --help"
echo "2. List PHP versions: yerd php list"
echo "3. Install PHP: sudo yerd php 8.4 install"
echo
}
# Call main function with all arguments
main "$@"