Skip to content

Commit cf95d84

Browse files
committed
added install.sh
1 parent 39943f4 commit cf95d84

2 files changed

Lines changed: 171 additions & 5 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# WarpShare
22

3-
#
43

54
WarpShare lets someone share files directly from their own device and give another person a link to browse, download, and work with those files immediately.
65

@@ -18,19 +17,19 @@ Built executables:
1817
- `warpshare-linux-musl-aarch64`
1918
- `warpshare-windows-amd64.exe`
2019

21-
Quick install with script:
20+
Quick install:
2221

2322
```bash
2423
curl -fsSL https://raw.githubusercontent.com/hallofcodes/WarpShare/master/install.sh | bash
2524
```
2625

27-
If `curl` is not available:
26+
If curl is not available:
2827

2928
```bash
3029
wget -qO- https://raw.githubusercontent.com/hallofcodes/WarpShare/master/install.sh | bash
3130
```
3231

33-
Manual install
32+
Manual install:
3433

3534
Linux x64:
3635

@@ -57,7 +56,7 @@ Invoke-WebRequest -Uri https://github.com/hallofcodes/WarpShare/releases/latest/
5756
Start-Process .\warpshare.exe
5857
```
5958

60-
To keep it as a global command on Windows, move it to a folder already in your `Path`, or create one:
59+
Windows global command:
6160

6261
```powershell
6362
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\bin" | Out-Null

install.sh

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
REPO="hallofcodes/WarpShare"
5+
BINARY_NAME="warpshare"
6+
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
7+
USER_BIN_DIR="${HOME:-$PWD}/.local/bin"
8+
API_URL="https://api.github.com/repos/${REPO}/releases/latest"
9+
RAW_BASE="https://github.com/${REPO}/releases/latest/download"
10+
11+
say() {
12+
printf '%s\n' "$*"
13+
}
14+
15+
need_cmd() {
16+
command -v "$1" >/dev/null 2>&1
17+
}
18+
19+
fetch() {
20+
local url="$1"
21+
local out="$2"
22+
23+
if need_cmd curl; then
24+
curl -fsSL "$url" -o "$out"
25+
elif need_cmd wget; then
26+
wget -qO "$out" "$url"
27+
else
28+
say "Error: curl or wget is required."
29+
exit 1
30+
fi
31+
}
32+
33+
fetch_text() {
34+
local url="$1"
35+
36+
if need_cmd curl; then
37+
curl -fsSL "$url"
38+
elif need_cmd wget; then
39+
wget -qO- "$url"
40+
else
41+
say "Error: curl or wget is required."
42+
exit 1
43+
fi
44+
}
45+
46+
normalize_arch() {
47+
case "$1" in
48+
x86_64|amd64) echo "amd64" ;;
49+
aarch64|arm64) echo "arm64" ;;
50+
*) echo "$1" ;;
51+
esac
52+
}
53+
54+
normalize_os() {
55+
case "$1" in
56+
Linux|linux) echo "linux" ;;
57+
Darwin|darwin) echo "darwin" ;;
58+
MINGW*|MSYS*|CYGWIN*|Windows_NT) echo "windows" ;;
59+
*) echo "unknown" ;;
60+
esac
61+
}
62+
63+
is_musl() {
64+
if ldd --version 2>&1 | grep -qi musl; then
65+
return 0
66+
fi
67+
68+
if [ -e /lib/ld-musl-aarch64.so.1 ] || [ -e /lib/ld-musl-x86_64.so.1 ]; then
69+
return 0
70+
fi
71+
72+
return 1
73+
}
74+
75+
pick_asset() {
76+
local os="$1"
77+
local arch="$2"
78+
79+
if [ "$os" = "linux" ] && [ "$arch" = "amd64" ]; then
80+
echo "warpshare-linux-amd64"
81+
return 0
82+
fi
83+
84+
if [ "$os" = "linux" ] && [ "$arch" = "arm64" ] && is_musl; then
85+
echo "warpshare-linux-musl-aarch64"
86+
return 0
87+
fi
88+
89+
if [ "$os" = "windows" ] && [ "$arch" = "amd64" ]; then
90+
echo "warpshare-windows-amd64.exe"
91+
return 0
92+
fi
93+
94+
return 1
95+
}
96+
97+
latest_tag() {
98+
fetch_text "$API_URL" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1
99+
}
100+
101+
ensure_path_hint() {
102+
case ":${PATH}:" in
103+
*":${USER_BIN_DIR}:"*) ;;
104+
*) say "Add this to your shell profile if '${USER_BIN_DIR}' is not in PATH:" && say "export PATH=\"${USER_BIN_DIR}:\$PATH\"" ;;
105+
esac
106+
}
107+
108+
install_binary() {
109+
local src="$1"
110+
local target_name="$2"
111+
112+
chmod +x "$src"
113+
114+
if [ -w "$INSTALL_DIR" ] || { [ ! -e "$INSTALL_DIR" ] && mkdir -p "$INSTALL_DIR" 2>/dev/null; }; then
115+
mv "$src" "${INSTALL_DIR}/${target_name}"
116+
say "Installed to ${INSTALL_DIR}/${target_name}"
117+
return 0
118+
fi
119+
120+
if need_cmd sudo; then
121+
sudo mkdir -p "$INSTALL_DIR"
122+
sudo mv "$src" "${INSTALL_DIR}/${target_name}"
123+
say "Installed to ${INSTALL_DIR}/${target_name}"
124+
return 0
125+
fi
126+
127+
mkdir -p "$USER_BIN_DIR"
128+
mv "$src" "${USER_BIN_DIR}/${target_name}"
129+
say "Installed to ${USER_BIN_DIR}/${target_name}"
130+
ensure_path_hint
131+
}
132+
133+
main() {
134+
local os arch asset tmp_file tag
135+
os="$(normalize_os "$(uname -s 2>/dev/null || echo unknown)")"
136+
arch="$(normalize_arch "$(uname -m 2>/dev/null || echo unknown)")"
137+
138+
if [ "$os" = "unknown" ]; then
139+
say "Unsupported operating system."
140+
exit 1
141+
fi
142+
143+
if ! asset="$(pick_asset "$os" "$arch")"; then
144+
say "No prebuilt WarpShare binary for ${os}/${arch}."
145+
say "Available release assets from current workflow:"
146+
say "- warpshare-linux-amd64"
147+
say "- warpshare-linux-musl-aarch64"
148+
say "- warpshare-windows-amd64.exe"
149+
exit 1
150+
fi
151+
152+
tag="$(latest_tag || true)"
153+
tmp_file="$(mktemp)"
154+
155+
say "Downloading ${asset}${tag:+ (${tag})}..."
156+
fetch "${RAW_BASE}/${asset}" "$tmp_file"
157+
158+
install_binary "$tmp_file" "$BINARY_NAME"
159+
160+
say ""
161+
say "Run it with:"
162+
say " ${BINARY_NAME} local"
163+
say "or"
164+
say " ${BINARY_NAME} remote"
165+
}
166+
167+
main "$@"

0 commit comments

Comments
 (0)