-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
203 lines (167 loc) · 4.99 KB
/
install.sh
File metadata and controls
203 lines (167 loc) · 4.99 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
#!/bin/bash
# plissken installer script
# Usage: curl -fsSL https://raw.githubusercontent.com/colliery-io/plissken/main/install.sh | bash
set -euo pipefail
REPO="colliery-io/plissken"
BINARY_NAME="plissken"
INSTALL_DIR="${PLISSKEN_INSTALL_DIR:-$HOME/.local/bin}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() {
echo -e "${BLUE}info:${NC} $1"
}
success() {
echo -e "${GREEN}success:${NC} $1"
}
warn() {
echo -e "${YELLOW}warning:${NC} $1"
}
error() {
echo -e "${RED}error:${NC} $1" >&2
exit 1
}
# Detect OS
detect_os() {
local os
os="$(uname -s)"
case "$os" in
Linux*) echo "linux" ;;
Darwin*) echo "macos" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) error "Unsupported operating system: $os" ;;
esac
}
# Detect architecture
detect_arch() {
local arch
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) echo "x86_64" ;;
arm64|aarch64) echo "aarch64" ;;
*) error "Unsupported architecture: $arch" ;;
esac
}
# Get the download URL for the latest release
get_download_url() {
local os="$1"
local arch="$2"
local target
case "$os" in
linux)
target="${arch}-unknown-linux-gnu"
;;
macos)
target="${arch}-apple-darwin"
;;
windows)
target="${arch}-pc-windows-msvc"
;;
esac
# Get latest release info from GitHub API
local release_url="https://api.github.com/repos/${REPO}/releases/latest"
local release_info
if command -v curl &> /dev/null; then
release_info=$(curl -fsSL "$release_url")
elif command -v wget &> /dev/null; then
release_info=$(wget -qO- "$release_url")
else
error "Neither curl nor wget found. Please install one of them."
fi
# Extract the download URL for our target
local download_url
if [ "$os" = "windows" ]; then
download_url=$(echo "$release_info" | grep -o "https://[^\"]*${target}[^\"]*\.zip" | head -1)
else
download_url=$(echo "$release_info" | grep -o "https://[^\"]*${target}[^\"]*\.tar\.gz" | head -1)
fi
if [ -z "$download_url" ]; then
error "Could not find download URL for target: $target"
fi
echo "$download_url"
}
# Download and extract the binary
download_and_install() {
local url="$1"
local os="$2"
local tmpdir
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
info "Downloading from $url"
local archive="$tmpdir/plissken-archive"
if command -v curl &> /dev/null; then
curl -fsSL "$url" -o "$archive"
elif command -v wget &> /dev/null; then
wget -q "$url" -O "$archive"
fi
info "Extracting archive"
if [ "$os" = "windows" ]; then
unzip -q "$archive" -d "$tmpdir"
else
tar -xzf "$archive" -C "$tmpdir"
fi
# Create install directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Find and install the binary
local binary
if [ "$os" = "windows" ]; then
binary=$(find "$tmpdir" -name "${BINARY_NAME}.exe" -type f | head -1)
cp "$binary" "$INSTALL_DIR/${BINARY_NAME}.exe"
else
binary=$(find "$tmpdir" -name "$BINARY_NAME" -type f | head -1)
cp "$binary" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
success "Installed $BINARY_NAME to $INSTALL_DIR"
}
# Check if install directory is in PATH
check_path() {
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
warn "$INSTALL_DIR is not in your PATH"
echo ""
echo "Add it to your PATH by adding this line to your shell profile:"
echo ""
local shell_name
shell_name=$(basename "$SHELL")
case "$shell_name" in
bash)
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc"
;;
zsh)
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc"
;;
fish)
echo " fish_add_path $INSTALL_DIR"
;;
*)
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
;;
esac
echo ""
fi
}
main() {
echo ""
echo " ╔═══════════════════════════════════════╗"
echo " ║ plissken installer ║"
echo " ╚═══════════════════════════════════════╝"
echo ""
local os arch url
info "Detecting platform..."
os=$(detect_os)
arch=$(detect_arch)
info "Detected: $os ($arch)"
info "Finding latest release..."
url=$(get_download_url "$os" "$arch")
download_and_install "$url" "$os"
check_path
echo ""
success "Installation complete!"
echo ""
echo " Run 'plissken --help' to get started"
echo ""
}
main "$@"