-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·234 lines (196 loc) Β· 6.13 KB
/
install.sh
File metadata and controls
executable file
Β·234 lines (196 loc) Β· 6.13 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
#!/bin/bash
# GoQueue Installation Script
# This script downloads and installs the latest version of GoQueue
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
# Configuration
REPO="Irtesaam/goqueue"
INSTALL_DIR="/usr/local/bin"
USER_INSTALL_DIR="$HOME/.local/bin"
BINARY_NAME="goq"
# Functions
print_info() {
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 OS and Architecture
detect_platform() {
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch=$(uname -m)
case $os in
linux)
OS="linux"
;;
darwin)
OS="darwin"
;;
*)
print_error "Unsupported operating system: $os"
exit 1
;;
esac
case $arch in
x86_64|amd64)
ARCH="amd64"
;;
arm64|aarch64)
ARCH="arm64"
;;
*)
print_error "Unsupported architecture: $arch"
exit 1
;;
esac
PLATFORM="${OS}-${ARCH}"
print_info "Detected platform: $PLATFORM"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Get latest release version
get_latest_version() {
if command_exists curl; then
VERSION=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
elif command_exists wget; then
VERSION=$(wget -qO- "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
print_error "Neither curl nor wget is available. Please install one of them."
exit 1
fi
if [ -z "$VERSION" ]; then
print_error "Failed to get latest version"
exit 1
fi
print_info "Latest version: $VERSION"
}
# Download binary
download_binary() {
local url="https://github.com/$REPO/releases/download/$VERSION/${BINARY_NAME}-${PLATFORM}"
local tmp_file="/tmp/${BINARY_NAME}"
print_info "Downloading $BINARY_NAME from $url"
if command_exists curl; then
curl -L -o "$tmp_file" "$url"
elif command_exists wget; then
wget -O "$tmp_file" "$url"
fi
if [ ! -f "$tmp_file" ]; then
print_error "Failed to download binary"
exit 1
fi
chmod +x "$tmp_file"
DOWNLOADED_BINARY="$tmp_file"
print_success "Downloaded successfully"
}
# Install binary
install_binary() {
# Try system installation first
if [ -w "$INSTALL_DIR" ] || [ "$EUID" -eq 0 ]; then
print_info "Installing to $INSTALL_DIR (system-wide)"
mv "$DOWNLOADED_BINARY" "$INSTALL_DIR/$BINARY_NAME"
print_success "Installed to $INSTALL_DIR/$BINARY_NAME"
else
# Try with sudo
if command_exists sudo; then
print_info "Installing to $INSTALL_DIR (requires sudo)"
sudo mv "$DOWNLOADED_BINARY" "$INSTALL_DIR/$BINARY_NAME"
print_success "Installed to $INSTALL_DIR/$BINARY_NAME"
else
# Fall back to user installation
print_warning "Cannot install system-wide, installing to user directory"
mkdir -p "$USER_INSTALL_DIR"
mv "$DOWNLOADED_BINARY" "$USER_INSTALL_DIR/$BINARY_NAME"
print_success "Installed to $USER_INSTALL_DIR/$BINARY_NAME"
# Check if user bin is in PATH
if [[ ":$PATH:" != *":$USER_INSTALL_DIR:"* ]]; then
print_warning "β οΈ $USER_INSTALL_DIR is not in your PATH"
print_info "Add this line to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo "export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
print_info "Then reload your shell or run: source ~/.bashrc"
fi
fi
fi
}
# Verify installation
verify_installation() {
if command_exists "$BINARY_NAME"; then
print_success "β
GoQueue installed successfully!"
print_info "Version: $($BINARY_NAME --version 2>/dev/null || echo 'Unknown')"
echo ""
print_info "π You can now use GoQueue with the 'goq' command"
print_info "Try: goq add \"My first todo\""
print_info " goq list"
else
print_error "Installation verification failed. GoQueue may not be in your PATH."
print_info "Try running: hash -r"
print_info "Or start a new terminal session"
fi
}
# Build from source (fallback)
build_from_source() {
print_info "Building from source..."
if ! command_exists git; then
print_error "Git is not installed. Please install git and try again."
exit 1
fi
if ! command_exists go; then
print_error "Go is not installed. Please install Go 1.19+ and try again."
exit 1
fi
local tmp_dir="/tmp/goqueue-build"
rm -rf "$tmp_dir"
print_info "Cloning repository..."
git clone "https://github.com/$REPO.git" "$tmp_dir"
cd "$tmp_dir"
print_info "Resolving dependencies..."
go mod tidy
print_info "Building binary..."
go build -o "$BINARY_NAME"
DOWNLOADED_BINARY="$tmp_dir/$BINARY_NAME"
install_binary
# Cleanup
rm -rf "$tmp_dir"
}
# Main installation process
main() {
echo "π GoQueue Installation Script"
echo "=============================="
echo ""
detect_platform
# Try to download pre-built binary
if get_latest_version && download_binary; then
install_binary
verify_installation
else
print_warning "Failed to download pre-built binary, trying to build from source..."
build_from_source
verify_installation
fi
echo ""
print_success "π Installation complete!"
echo ""
print_info "π Documentation: https://github.com/$REPO"
print_info "π Issues: https://github.com/$REPO/issues"
echo ""
print_info "Get started:"
echo " goq add \"Buy groceries\""
echo " goq add \"Learn something new\""
echo " goq list"
echo " goq --help"
}
# Run main function
main "$@"