|
1 | 1 | #!/bin/sh |
2 | 2 |
|
3 | | -DEST="${TMPDIR:-/tmp}/._bdlstub_dbin.bin" |
4 | | - |
5 | | -# Determine architecture |
6 | 3 | ARCH="$(uname -m)" |
7 | 4 | case "$ARCH" in |
8 | | - x86_64) ARCH_SUFFIX="amd64" ;; |
9 | | - aarch64) ARCH_SUFFIX="arm64" ;; |
10 | | - *) echo "Unsupported architecture: $ARCH"; exit 1 ;; |
| 5 | + x86_64|amd64) ARCH="amd64" ;; |
| 6 | + aarch64|arm64) ARCH="arm64" ;; |
| 7 | + riscv64) ARCH="riscv64" ;; |
| 8 | + loongarch64|loong64) ARCH="loong64" ;; |
| 9 | + *) echo "dbin: unsupported architecture: $ARCH" >&2; exit 1 ;; |
11 | 10 | esac |
12 | 11 |
|
13 | | -DBIN_URL="https://github.com/xplshn/dbin/releases/latest/download/dbin_${ARCH_SUFFIX}.upx" |
| 12 | +DEST="${TMPDIR:-/tmp}/.dbin_$ARCH" |
| 13 | +URL="https://github.com/xplshn/dbin/releases/download/1.7/dbin_$ARCH" |
| 14 | +[ "$ARCH" = "amd64" ] || [ "$ARCH" = "arm64" ] && URL="$URL.upx" |
14 | 15 |
|
15 | | -# Handle --install option |
16 | | -if [ "$1" = "--install" ]; then |
17 | | - DEST="$2" |
18 | | - shift 2 |
19 | | -fi |
| 16 | +[ "$1" = "--install" ] && { DEST="$2"; shift 2; } |
20 | 17 |
|
21 | | -# Function to download the binary |
22 | | -download_dbin() { |
| 18 | +if [ ! -x "$DEST" ]; then |
23 | 19 | if command -v curl >/dev/null 2>&1; then |
24 | | - curl -qfsSL "$DBIN_URL" -o "$DEST" |
| 20 | + curl -fsSL "$URL" -o "$DEST" || exit 1 |
25 | 21 | elif command -v wget >/dev/null 2>&1; then |
26 | | - wget -q "$DBIN_URL" -O "$DEST" |
| 22 | + wget -q "$URL" -O "$DEST" || exit 1 |
27 | 23 | else |
28 | | - echo "Neither curl nor wget are available." |
29 | | - exit 1 |
| 24 | + echo "dbin: curl or wget required" >&2; exit 1 |
30 | 25 | fi |
31 | | -} |
32 | | - |
33 | | -# Check if binary exists and is executable |
34 | | -if [ -e "$DEST" ] && [ ! "$1" = "--install" ]; then |
35 | | - # Run the binary |
36 | | - "$DEST" "$@" |
37 | | -else |
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 | 26 | chmod +x "$DEST" |
50 | | - "$DEST" "$@" |
| 27 | + [ "$1" = "--install" ] && { echo "dbin: installed to $DEST"; exit 0; } |
51 | 28 | fi |
| 29 | + |
| 30 | +exec "$DEST" "$@" |
0 commit comments