xplshn
·
2025-08-13
stubdl
Bash
1#!/bin/sh
2
3DEST="${TMPDIR:-/tmp}/._bdlstub_dbin.bin"
4
5# Determine architecture
6ARCH="$(uname -m)"
7case "$ARCH" in
8 x86_64) ARCH_SUFFIX="amd64" ;;
9 aarch64) ARCH_SUFFIX="arm64" ;;
10 *) echo "Unsupported architecture: $ARCH"; exit 1 ;;
11esac
12
13DBIN_URL="https://github.com/xplshn/dbin/releases/latest/download/dbin_${ARCH_SUFFIX}.upx"
14
15# Handle --install option
16if [ "$1" = "--install" ]; then
17 DEST="$2"
18 shift 2
19fi
20
21# Function to download the binary
22download_dbin() {
23 if command -v curl >/dev/null 2>&1; then
24 curl -qfsSL "$DBIN_URL" -o "$DEST"
25 elif command -v wget >/dev/null 2>&1; then
26 wget -q "$DBIN_URL" -O "$DEST"
27 else
28 echo "Neither curl nor wget are available."
29 exit 1
30 fi
31}
32
33# Check if binary exists and is executable
34if [ -e "$DEST" ] && [ ! "$1" = "--install" ]; then
35 # Run the binary
36 "$DEST" "$@"
37else
38 # Download and install the binary
39 mkdir -p "$(dirname "$DEST")"
40 download_dbin
41
42 if [ "$1" = "--install" ]; then
43 chmod +x "$DEST"
44 echo "DBIN IS NOW AVAILABLE. ($DEST)"
45 exit 0
46 fi
47
48 # Make the binary executable and run it
49 chmod +x "$DEST"
50 "$DEST" "$@"
51fi