-
Notifications
You must be signed in to change notification settings - Fork 3
/
stubdl
executable file
·51 lines (43 loc) · 1.14 KB
/
stubdl
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
#!/bin/sh
DEST="/tmp/._bdlstub_dbin.bin"
# Determine architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH_SUFFIX="amd64" ;;
aarch64) ARCH_SUFFIX="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
DBIN_URL="https://github.com/xplshn/dbin/releases/latest/download/dbin_${ARCH_SUFFIX}.upx"
# Handle --install option
if [ "$1" = "--install" ]; then
DEST="$2"
shift 2
fi
# Function to download the binary
download_dbin() {
if command -v wget >/dev/null 2>&1; then
wget -q "$DBIN_URL" -O "$DEST"
elif command -v curl >/dev/null 2>&1; then
curl -qfsSL "$DBIN_URL" -o "$DEST"
else
echo "Neither wget nor curl is available."
exit 1
fi
}
# Check if binary exists and is executable
if [ -e "$DEST" ] && [ ! "$1" = "--install" ]; then
# Run the binary
"$DEST" "$@"
else
# Download and install the binary
mkdir -p "$(dirname "$DEST")"
download_dbin
if [ "$1" = "--install" ]; then
chmod +x "$DEST"
echo "DBIN IS NOW AVAILABLE. ($DEST)"
exit 0
fi
# Make the binary executable and run it
chmod +x "$DEST"
"$DEST" "$@"
fi