-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·127 lines (105 loc) · 3.97 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·127 lines (105 loc) · 3.97 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
#!/usr/bin/env bash
# shellcheck shell=bash
# dibs installer — downloads the latest binary from GitHub releases.
#
# SECURITY NOTE: We recommend reviewing the script before running:
# curl -fsSL https://raw.githubusercontent.com/sitapix/dibs/main/install.sh -o install.sh
# less install.sh
# bash install.sh
#
# Or install via Homebrew (preferred):
# brew install sitapix/dibs/dibs
set -euo pipefail
REPO="sitapix/dibs"
BINARY="dibs"
# ============================================================================
# COLORS (only if stdout is a terminal)
# ============================================================================
if [[ -t 1 ]]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
else
RED='' GREEN='' YELLOW='' CYAN='' BOLD='' NC=''
fi
die() { printf '%bError: %s%b\n' "$RED" "$1" "$NC" >&2; exit 1; }
info() { printf '%b%s%b\n' "$CYAN" "$1" "$NC"; }
success() { printf ' %b✓%b %s\n' "$GREEN" "$NC" "$1"; }
# ============================================================================
# DETECT PLATFORM
# ============================================================================
detect_platform() {
local os arch
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os" in
darwin) os="darwin" ;;
linux) os="linux" ;;
*) die "Unsupported OS: $os" ;;
esac
case "$arch" in
x86_64|amd64) arch="amd64" ;;
arm64|aarch64) arch="arm64" ;;
*) die "Unsupported architecture: $arch" ;;
esac
printf '%s-%s' "$os" "$arch"
}
# ============================================================================
# MAIN
# ============================================================================
printf '%b%bdibs installer%b\n\n' "$CYAN" "$BOLD" "$NC"
# Check for curl
command -v curl &>/dev/null || die "curl is required but not installed."
# Detect platform
PLATFORM="$(detect_platform)"
info "Detected platform: $PLATFORM"
# Get latest release tag
info "Fetching latest release..."
LATEST=$(curl -fsSI -o /dev/null -w '%{redirect_url}' "https://github.com/$REPO/releases/latest" | grep -oE '[^/]+$')
[[ -n "$LATEST" ]] || die "Could not determine latest release"
success "Latest release: $LATEST"
# Download binary
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST/$BINARY-$PLATFORM"
TMP=$(mktemp) || die "Failed to create temp file"
trap 'rm -f -- "$TMP"' EXIT
info "Downloading $BINARY-$PLATFORM..."
curl -fsSL "$DOWNLOAD_URL" -o "$TMP" || die "Download failed. Check https://github.com/$REPO/releases for available binaries."
# Verify checksum
CHECKSUMS_URL="https://github.com/$REPO/releases/download/$LATEST/checksums.txt"
if CHECKSUMS=$(curl -fsSL "$CHECKSUMS_URL" 2>/dev/null); then
EXPECTED=$(printf '%s' "$CHECKSUMS" | grep "$BINARY-$PLATFORM" | awk '{print $1}')
if [[ -n "$EXPECTED" ]]; then
if command -v sha256sum &>/dev/null; then
ACTUAL=$(sha256sum "$TMP" | awk '{print $1}')
elif command -v shasum &>/dev/null; then
ACTUAL=$(shasum -a 256 "$TMP" | awk '{print $1}')
else
ACTUAL=""
fi
if [[ -n "$ACTUAL" ]]; then
if [[ "$EXPECTED" != "$ACTUAL" ]]; then
die "Checksum mismatch! Expected: $EXPECTED, Got: $ACTUAL"
fi
success "Checksum verified"
fi
fi
fi
# Install
INSTALL_DIR="/usr/local/bin"
if [[ ! -w "$INSTALL_DIR" ]]; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
mv -- "$TMP" "$INSTALL_DIR/$BINARY" || die "Failed to install to $INSTALL_DIR"
chmod +x "$INSTALL_DIR/$BINARY"
trap - EXIT
success "Installed to $INSTALL_DIR/$BINARY"
# Check PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
printf '\n%bAdd %s to your PATH:%b\n' "$YELLOW" "$INSTALL_DIR" "$NC"
printf ' export PATH="%s:$PATH"\n\n' "$INSTALL_DIR"
fi
printf '\n%b%bDone!%b Run %bdibs --help%b to get started.\n' "$GREEN" "$BOLD" "$NC" "$CYAN" "$NC"