Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
146 lines (122 loc) · 3.38 KB
/
Copy pathinstall.sh
File metadata and controls
146 lines (122 loc) · 3.38 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'
# install.sh - install rtunnel from GitHub Releases.
#
# Examples:
# curl -fsSL https://github.com/FriendlyDev/rtunnel/releases/latest/download/install.sh | bash
# curl -fsSL https://github.com/FriendlyDev/rtunnel/releases/latest/download/install.sh | bash -s -- --version v0.2.0
# ... | bash -s -- --bindir "$HOME/.local/bin"
#
# Flags:
# --version vX.Y.Z Install specific release tag (default: latest)
# --prefix PATH Install into PATH/bin (default: ~/.local)
# --bindir PATH Install into PATH (overrides --prefix)
# --no-verify Skip SHA256 verification (not recommended)
OWNER="${RTUNNEL_OWNER:-FriendlyDev}"
REPO="${RTUNNEL_REPO:-rtunnel}"
PREFIX="${PREFIX:-$HOME/.local}"
BINDIR=""
VERSION_TAG="latest"
VERIFY=1
info() { printf '%s\n' "$*"; }
warn() { printf 'install: %s\n' "$*" >&2; }
die() { warn "$*"; exit 1; }
have() { command -v "$1" >/dev/null 2>&1; }
sha256_verify() {
local file="$1"
local expected="$2"
if have shasum; then
local actual
actual="$(shasum -a 256 "$file" | awk '{print $1}')"
[[ "$actual" == "$expected" ]]
return
fi
if have sha256sum; then
local actual
actual="$(sha256sum "$file" | awk '{print $1}')"
[[ "$actual" == "$expected" ]]
return
fi
die "Neither 'shasum' nor 'sha256sum' found; cannot verify SHA256. Install one or use --no-verify."
}
usage() {
cat <<EOF
Install rtunnel from GitHub Releases.
Usage:
install.sh [--version vX.Y.Z] [--prefix PATH] [--bindir PATH] [--no-verify]
Defaults:
--version latest
--prefix $HOME/.local
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
shift
[[ $# -gt 0 ]] || die "missing value for --version"
VERSION_TAG="$1"
;;
--version=*)
VERSION_TAG="${1#--version=}"
;;
--prefix)
shift
[[ $# -gt 0 ]] || die "missing value for --prefix"
PREFIX="$1"
;;
--prefix=*)
PREFIX="${1#--prefix=}"
;;
--bindir)
shift
[[ $# -gt 0 ]] || die "missing value for --bindir"
BINDIR="$1"
;;
--bindir=*)
BINDIR="${1#--bindir=}"
;;
--no-verify)
VERIFY=0
;;
-h|--help)
usage
exit 0
;;
*)
die "unknown argument: $1"
;;
esac
shift
done
if [[ -z "$BINDIR" ]]; then
BINDIR="${BINDIR:-$PREFIX/bin}"
fi
mkdir -p "$BINDIR"
TMP_DIR="$(mktemp -d)"
cleanup() { rm -rf "$TMP_DIR"; }
trap cleanup EXIT
BASE_URL="https://github.com/${OWNER}/${REPO}/releases/${VERSION_TAG}/download"
if [[ "$VERSION_TAG" == "latest" ]]; then
BASE_URL="https://github.com/${OWNER}/${REPO}/releases/latest/download"
fi
RTUNNEL_URL="${BASE_URL}/rtunnel"
SHA_URL="${BASE_URL}/SHA256SUMS"
info "Downloading rtunnel from: $RTUNNEL_URL"
curl -fsSL "$RTUNNEL_URL" -o "$TMP_DIR/rtunnel"
if [[ "$VERIFY" -eq 1 ]]; then
info "Downloading checksums from: $SHA_URL"
curl -fsSL "$SHA_URL" -o "$TMP_DIR/SHA256SUMS"
expected="$(awk '$2=="rtunnel"{print $1}' "$TMP_DIR/SHA256SUMS")"
[[ -n "$expected" ]] || die "Could not find checksum for 'rtunnel' in SHA256SUMS"
info "Verifying SHA256..."
sha256_verify "$TMP_DIR/rtunnel" "$expected" || die "SHA256 verification failed for rtunnel"
else
warn "Skipping SHA256 verification (--no-verify)."
fi
DEST="$BINDIR/rtunnel"
install -m 0755 "$TMP_DIR/rtunnel" "$DEST"
info "Installed: $DEST"
info ""
info "Next:"
info " rtunnel --help"