-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·118 lines (100 loc) · 4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·118 lines (100 loc) · 4 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
#!/bin/sh
set -eu
REPO="cs01/termpair"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
if [ -t 1 ]; then
bold="\033[1m" dim="\033[2m" green="\033[32m" cyan="\033[36m"
yellow="\033[33m" red="\033[31m" reset="\033[0m"
else
bold="" dim="" green="" cyan="" yellow="" red="" reset=""
fi
info() { printf " ${cyan}>${reset} %s\n" "$1"; }
ok() { printf " ${green}>${reset} %s\n" "$1"; }
warn() { printf " ${yellow}!${reset} %s\n" "$1" >&2; }
err() { printf " ${red}x${reset} %s\n" "$1" >&2; exit 1; }
detect_platform() {
os="$(uname -s)"; arch="$(uname -m)"
case "$os" in
Linux) os="unknown-linux-gnu" ;;
Darwin) os="apple-darwin" ;;
MINGW*|MSYS*|CYGWIN*) err "On Windows, download from https://github.com/${REPO}/releases" ;;
*) err "Unsupported OS: $os" ;;
esac
case "$arch" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) err "Unsupported architecture: $arch" ;;
esac
echo "${arch}-${os}"
}
get_latest_version() {
if command -v curl >/dev/null 2>&1; then
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed 's/.*"tag_name": *"//;s/".*//'
elif command -v wget >/dev/null 2>&1; then
wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed 's/.*"tag_name": *"//;s/".*//'
else
err "Neither curl nor wget found"
fi
}
download() {
if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2"
else wget -qO "$2" "$1"; fi
}
verify_checksum() {
archive="$1"; expected_name="$2"; checksums_file="$3"
expected=$(grep -F "$expected_name" "$checksums_file" | awk '{print $1}')
[ -z "$expected" ] && err "No checksum found for $expected_name"
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$archive" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$archive" | awk '{print $1}')
else
err "Neither sha256sum nor shasum found"
fi
[ "$actual" != "$expected" ] && err "Checksum mismatch (expected $expected, got $actual)"
}
main() {
printf "\n"
printf " ${bold}TermPair Installer${reset}\n"
printf " ${dim}End-to-end encrypted terminal sharing${reset}\n"
printf "\n"
platform="$(detect_platform)"
version="${VERSION:-$(get_latest_version)}"
[ -z "$version" ] && err "Could not determine latest version"
info "Downloading termpair ${version} (${platform})..."
archive_name="termpair-${platform}.tar.gz"
url="https://github.com/${REPO}/releases/download/${version}/${archive_name}"
checksums_url="https://github.com/${REPO}/releases/download/${version}/sha256sums.txt"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
download "$url" "$tmp/${archive_name}"
download "$checksums_url" "$tmp/sha256sums.txt" || err "Could not download checksums"
info "Verifying checksum..."
verify_checksum "$tmp/${archive_name}" "$archive_name" "$tmp/sha256sums.txt"
tar xzf "$tmp/${archive_name}" -C "$tmp" --no-same-owner --no-same-permissions 2>/dev/null || \
tar xzf "$tmp/${archive_name}" -C "$tmp"
mkdir -p "$INSTALL_DIR"
mv "$tmp/termpair" "$INSTALL_DIR/termpair"
chmod +x "$INSTALL_DIR/termpair"
ok "Installed to ${INSTALL_DIR}/termpair"
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
printf "\n"
warn "${INSTALL_DIR} is not in your PATH. Add it:"
printf " ${bold}export PATH=\"${INSTALL_DIR}:\$PATH\"${reset}\n"
printf " ${dim}Add to ~/.bashrc or ~/.zshrc to make permanent${reset}\n"
;;
esac
printf "\n"
printf " ${bold}Quick start${reset}\n"
printf "\n"
printf " ${green}termpair${reset} Private encrypted session\n"
printf " ${green}termpair --public${reset} Public, read-only, no encryption\n"
printf " ${green}termpair --read-only${reset} Viewers can watch but not type\n"
printf " ${green}termpair --host https://my-server${reset} Share via a custom server\n"
printf "\n"
printf " ${dim}https://github.com/cs01/termpair${reset}\n"
printf "\n"
}
main