-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·130 lines (102 loc) · 3.73 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·130 lines (102 loc) · 3.73 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
#!/usr/bin/env sh
# install.sh — install try-bedazzled and wire up the shell function.
#
# curl -fsSL https://raw.githubusercontent.com/hmk/try-bedazzled/main/install.sh | sh
#
# Env overrides:
# TRY_INSTALL_DIR install location for the binary (default: /usr/local/bin)
# TRY_VERSION release tag to install (default: latest)
# TRY_NO_RC_EDIT if set, skip editing the shell rc file
set -eu
REPO="hmk/try-bedazzled"
INSTALL_DIR="${TRY_INSTALL_DIR:-/usr/local/bin}"
VERSION="${TRY_VERSION:-latest}"
bold() { printf '\033[1m%s\033[0m\n' "$1"; }
info() { printf ' %s\n' "$1"; }
warn() { printf '\033[33m %s\033[0m\n' "$1" >&2; }
die() { printf '\033[31merror:\033[0m %s\n' "$1" >&2; exit 1; }
bold "try-bedazzled installer"
# --- detect platform ----------------------------------------------------------
uname_s=$(uname -s)
uname_m=$(uname -m)
case "$uname_s" in
Darwin) os=darwin ;;
Linux) os=linux ;;
*) die "unsupported OS: $uname_s (try Homebrew or download from GitHub Releases)" ;;
esac
case "$uname_m" in
x86_64|amd64) arch=amd64 ;;
arm64|aarch64) arch=arm64 ;;
*) die "unsupported architecture: $uname_m" ;;
esac
info "platform: ${os}_${arch}"
# --- resolve download URL -----------------------------------------------------
if [ "$VERSION" = "latest" ]; then
url="https://github.com/${REPO}/releases/latest/download/try-bedazzled_${os}_${arch}.tar.gz"
else
url="https://github.com/${REPO}/releases/download/${VERSION}/try-bedazzled_${os}_${arch}.tar.gz"
fi
info "download: $url"
# --- download + extract -------------------------------------------------------
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
if ! curl -fsSL -o "$tmp/try.tar.gz" "$url"; then
die "download failed — check that ${VERSION} has a release asset for ${os}_${arch}"
fi
tar -xzf "$tmp/try.tar.gz" -C "$tmp"
if [ ! -x "$tmp/try" ]; then
die "downloaded archive does not contain a 'try' binary"
fi
# --- install binary -----------------------------------------------------------
info "install: $INSTALL_DIR/try"
if [ -w "$INSTALL_DIR" ]; then
install -m 0755 "$tmp/try" "$INSTALL_DIR/try"
else
if ! command -v sudo >/dev/null 2>&1; then
die "$INSTALL_DIR is not writable and sudo is not available — set TRY_INSTALL_DIR to a writable path"
fi
warn "$INSTALL_DIR not writable — using sudo"
sudo install -m 0755 "$tmp/try" "$INSTALL_DIR/try"
fi
# --- wire up shell function ---------------------------------------------------
if [ -n "${TRY_NO_RC_EDIT:-}" ]; then
info "rc file: skipped (TRY_NO_RC_EDIT set)"
echo
bold "Done."
echo " Add this line to your shell config to enable the 'try' function:"
echo " eval \"\$(try init)\" # bash/zsh"
echo " try init | source # fish"
exit 0
fi
shell_name=$(basename "${SHELL:-/bin/sh}")
case "$shell_name" in
bash) rc="$HOME/.bashrc"; line='eval "$(try init)"' ;;
zsh) rc="$HOME/.zshrc"; line='eval "$(try init)"' ;;
fish) rc="$HOME/.config/fish/config.fish"; line='try init | source' ;;
*)
warn "unrecognized shell '$shell_name' — skipping rc edit"
echo
bold "Done."
echo " Add the appropriate line to your shell config:"
echo " eval \"\$(try init)\" # bash/zsh"
echo " try init | source # fish"
exit 0
;;
esac
mkdir -p "$(dirname "$rc")"
[ -f "$rc" ] || : > "$rc"
if grep -Fq 'try init' "$rc" 2>/dev/null; then
info "rc file: $rc (already configured)"
else
info "rc file: $rc (appending)"
{
echo ''
echo '# try-bedazzled (https://github.com/hmk/try-bedazzled)'
echo "$line"
} >> "$rc"
fi
# --- done ---------------------------------------------------------------------
echo
bold "Installed!"
echo " Restart your shell or run: source $rc"
echo " Then try it: try"