-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·299 lines (258 loc) · 8.59 KB
/
install.sh
File metadata and controls
executable file
·299 lines (258 loc) · 8.59 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
#!/bin/bash
# PinePods Firewood Installation Script
# Supports Linux, macOS, and Windows (via Git Bash/WSL)
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
INSTALL_DIR=""
FORCE_INSTALL=false
VERSION="latest"
# Functions
print_header() {
echo -e "${BLUE}"
echo "┌─────────────────────────────────────────┐"
echo "│ 🌲 PinePods Firewood Installer │"
echo "│ Terminal UI for PinePods Server │"
echo "└─────────────────────────────────────────┘"
echo -e "${NC}"
}
print_usage() {
echo "Usage: $0 [options]"
echo "Options:"
echo " -d, --dir DIR Install directory (default: /usr/local/bin or ~/bin)"
echo " -v, --version VER Install specific version (default: latest)"
echo " -f, --force Force installation even if already installed"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Install latest to default location"
echo " $0 -d ~/.local/bin # Install to custom directory"
echo " $0 -v v1.0.0 # Install specific version"
echo ""
echo "Quick install:"
echo " curl -sSL https://raw.githubusercontent.com/madeofpendletonwool/pinepods-firewood/main/install.sh | bash"
}
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
detect_platform() {
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch=$(uname -m)
case $os in
linux*)
case $arch in
x86_64|amd64) echo "linux-amd64" ;;
aarch64|arm64) echo "linux-arm64" ;;
*) log_error "Unsupported architecture: $arch"; exit 1 ;;
esac
;;
darwin*)
case $arch in
x86_64) echo "macos-amd64" ;;
arm64) echo "macos-arm64" ;;
*) log_error "Unsupported architecture: $arch"; exit 1 ;;
esac
;;
mingw*|msys*|cygwin*)
echo "windows-amd64"
;;
*)
log_error "Unsupported operating system: $os"
exit 1
;;
esac
}
get_install_dir() {
if [ -n "$INSTALL_DIR" ]; then
echo "$INSTALL_DIR"
return
fi
# Try to install to system directory if we have permission
if [ -w "/usr/local/bin" ] 2>/dev/null; then
echo "/usr/local/bin"
elif [ -w "$(dirname "$(which bash)")" ] 2>/dev/null; then
dirname "$(which bash)"
else
# Fall back to user directory
mkdir -p "$HOME/bin"
echo "$HOME/bin"
fi
}
get_latest_version() {
local url="https://api.github.com/repos/madeofpendletonwool/pinepods-firewood/releases/latest"
if command -v curl >/dev/null 2>&1; then
curl -s "$url" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
elif command -v wget >/dev/null 2>&1; then
wget -qO- "$url" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
else
log_error "Neither curl nor wget is available. Please install one of them."
exit 1
fi
}
download_and_install() {
local platform=$(detect_platform)
local install_dir=$(get_install_dir)
local version_tag
if [ "$VERSION" = "latest" ]; then
version_tag=$(get_latest_version)
if [ -z "$version_tag" ]; then
log_error "Failed to fetch latest version"
exit 1
fi
log_info "Latest version: $version_tag"
else
version_tag=$VERSION
fi
# Ensure version starts with 'v'
if [[ ! $version_tag =~ ^v ]]; then
version_tag="v$version_tag"
fi
local binary_name="pinepods_firewood"
local archive_ext=".tar.gz"
if [[ $platform == windows-* ]]; then
binary_name="pinepods_firewood.exe"
archive_ext=".zip"
fi
local archive_name="pinepods-firewood-${platform}${archive_ext}"
local download_url="https://github.com/madeofpendletonwool/pinepods-firewood/releases/download/${version_tag}/${archive_name}"
log_info "Downloading from: $download_url"
log_info "Installing to: $install_dir"
# Create temporary directory
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
# Download archive
log_info "Downloading PinePods Firewood $version_tag..."
if command -v curl >/dev/null 2>&1; then
if ! curl -L -o "$tmp_dir/$archive_name" "$download_url"; then
log_error "Failed to download $archive_name"
exit 1
fi
elif command -v wget >/dev/null 2>&1; then
if ! wget -O "$tmp_dir/$archive_name" "$download_url"; then
log_error "Failed to download $archive_name"
exit 1
fi
else
log_error "Neither curl nor wget is available"
exit 1
fi
# Extract archive
log_info "Extracting archive..."
cd "$tmp_dir"
if [[ $platform == windows-* ]]; then
if command -v unzip >/dev/null 2>&1; then
unzip -q "$archive_name"
else
log_error "unzip is required to extract Windows archives"
exit 1
fi
else
tar -xzf "$archive_name"
fi
# Check if binary exists and is executable
if [ ! -f "$binary_name" ]; then
log_error "Binary $binary_name not found in archive"
exit 1
fi
# Create install directory if needed
mkdir -p "$install_dir"
# Check if already installed
local target_path="$install_dir/$binary_name"
if [ -f "$target_path" ] && [ "$FORCE_INSTALL" = false ]; then
log_warn "PinePods Firewood is already installed at $target_path"
echo -n "Do you want to overwrite it? (y/N): "
read -r response
if [[ ! $response =~ ^[Yy]$ ]]; then
log_info "Installation cancelled"
exit 0
fi
fi
# Install binary
log_info "Installing binary to $target_path..."
if ! cp "$binary_name" "$target_path"; then
log_error "Failed to copy binary to $target_path"
log_error "You may need to run this script with elevated permissions"
exit 1
fi
# Make executable (not needed on Windows)
if [[ ! $platform == windows-* ]]; then
chmod +x "$target_path"
fi
log_success "PinePods Firewood $version_tag installed successfully!"
# Check if install directory is in PATH
if [[ ":$PATH:" != *":$install_dir:"* ]]; then
log_warn "Warning: $install_dir is not in your PATH"
echo "To use pinepods_firewood from anywhere, add this to your shell profile:"
echo " export PATH=\"\$PATH:$install_dir\""
fi
# Test installation
log_info "Testing installation..."
if "$target_path" --version >/dev/null 2>&1; then
log_success "Installation verified successfully!"
else
log_warn "Installation may have issues. Try running: $target_path --version"
fi
echo ""
echo -e "${GREEN}🎉 Installation complete!${NC}"
echo ""
echo "Usage:"
echo " $binary_name # Run with default settings"
echo " $binary_name --help # Show help message"
echo ""
echo "Documentation: https://github.com/madeofpendletonwool/pinepods-firewood"
echo "Issues: https://github.com/madeofpendletonwool/pinepods-firewood/issues"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-d|--dir)
INSTALL_DIR="$2"
shift 2
;;
-v|--version)
VERSION="$2"
shift 2
;;
-f|--force)
FORCE_INSTALL=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
log_error "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Main execution
main() {
print_header
# Check for required tools
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
log_error "Either curl or wget is required for installation"
exit 1
fi
log_info "Starting PinePods Firewood installation..."
log_info "Platform: $(detect_platform)"
download_and_install
}
# Run main function
main "$@"