Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·126 lines (106 loc) · 4.37 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·126 lines (106 loc) · 4.37 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
#!/bin/sh
# Cleared for Push installer for Linux and macOS.
#
# curl -fsSL https://raw.githubusercontent.com/sanjayrohith/clearedforpush/main/scripts/install.sh | sh
#
# Environment overrides:
# CFP_VERSION version tag to install (default: latest release)
# CFP_INSTALL_DIR directory to install into (default: ~/.local/bin)
set -eu
REPO="sanjayrohith/clearedforpush"
BIN="clearedforpush"
VERSION="${CFP_VERSION:-}"
INSTALL_DIR="${CFP_INSTALL_DIR:-$HOME/.local/bin}"
info() { printf ' %s\n' "$1"; }
warn() { printf ' warning: %s\n' "$1" >&2; }
err() { printf ' error: %s\n' "$1" >&2; exit 1; }
# --- http helpers ---------------------------------------------------------
# Prefer curl, fall back to wget so minimal containers still work.
if command -v curl >/dev/null 2>&1; then
http_get() { curl -fsSL "$1"; }
http_dl() { curl -fsSL "$1" -o "$2"; }
elif command -v wget >/dev/null 2>&1; then
http_get() { wget -qO- "$1"; }
http_dl() { wget -qO "$2" "$1"; }
else
err "need curl or wget to download; please install one and retry"
fi
# --- platform detection ---------------------------------------------------
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux)
case "$arch" in
# The musl build is statically linked, so it runs on every distro
# regardless of glibc version.
x86_64 | amd64) target="x86_64-unknown-linux-musl" ;;
aarch64 | arm64)
err "no prebuilt binary for linux/$arch yet.
Install with Rust instead: cargo install $BIN" ;;
*) err "unsupported linux architecture: $arch" ;;
esac
;;
Darwin)
case "$arch" in
arm64 | aarch64) target="aarch64-apple-darwin" ;;
x86_64) target="x86_64-apple-darwin" ;;
*) err "unsupported macos architecture: $arch" ;;
esac
;;
*)
err "unsupported operating system: $os
On Windows, run the PowerShell installer instead:
irm https://raw.githubusercontent.com/$REPO/main/scripts/install.ps1 | iex" ;;
esac
# --- resolve version ------------------------------------------------------
if [ -z "$VERSION" ]; then
info "Resolving latest release..."
VERSION="$(http_get "https://api.github.com/repos/$REPO/releases/latest" \
| tr ',' '\n' \
| grep '"tag_name"' \
| head -n 1 \
| sed 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')"
[ -n "$VERSION" ] || err "could not determine the latest release version"
fi
ARCHIVE="$BIN-$VERSION-$target.tar.gz"
URL="https://github.com/$REPO/releases/download/$VERSION/$ARCHIVE"
# --- download and unpack --------------------------------------------------
tmp="$(mktemp -d)"
# shellcheck disable=SC2064
trap "rm -rf \"$tmp\"" EXIT INT TERM
info "Downloading $BIN $VERSION ($target)..."
http_dl "$URL" "$tmp/$ARCHIVE" || err "download failed: $URL"
tar xzf "$tmp/$ARCHIVE" -C "$tmp" || err "could not extract $ARCHIVE"
[ -f "$tmp/$BIN" ] || err "archive did not contain the expected $BIN binary"
chmod +x "$tmp/$BIN"
# Downloads that arrive through a browser carry a quarantine flag, which makes
# Gatekeeper refuse to run the unsigned binary. Clear it when the attribute is
# present; harmless everywhere else.
if [ "$os" = "Darwin" ] && command -v xattr >/dev/null 2>&1; then
xattr -d com.apple.quarantine "$tmp/$BIN" >/dev/null 2>&1 || true
fi
# --- install --------------------------------------------------------------
mkdir -p "$INSTALL_DIR" || err "could not create $INSTALL_DIR"
if [ ! -w "$INSTALL_DIR" ]; then
err "$INSTALL_DIR is not writable.
Retry with a different location: CFP_INSTALL_DIR=\$HOME/bin sh"
fi
mv "$tmp/$BIN" "$INSTALL_DIR/$BIN" || err "could not install to $INSTALL_DIR"
printf '\n'
info "Installed $BIN $VERSION to $INSTALL_DIR/$BIN"
# --- PATH check -----------------------------------------------------------
case ":$PATH:" in
*":$INSTALL_DIR:"*)
info "Run '$BIN --help' to get started."
;;
*)
printf '\n'
warn "$INSTALL_DIR is not on your PATH."
info "Add it by running the line for your shell, then restart your terminal:"
printf '\n'
info " bash: echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.bashrc"
info " zsh: echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.zshrc"
info " fish: fish_add_path \"$INSTALL_DIR\""
;;
esac
printf '\n'