-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·79 lines (63 loc) · 2.06 KB
/
install.sh
File metadata and controls
executable file
·79 lines (63 loc) · 2.06 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
#!/usr/bin/env bash
set -euo pipefail
REPO="techops-services/share"
die() { echo "Error: $*" >&2; exit 1; }
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*) die "Unsupported architecture: $ARCH" ;;
esac
case "$OS" in
darwin|linux) ;;
*) die "Unsupported OS: $OS" ;;
esac
# Pick a writable install directory — prefer /usr/local/bin, fall back to ~/.local/bin
if [ -d "/usr/local/bin" ] && [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | cut -d'"' -f4)
[ -n "$VERSION" ] || die "Could not determine latest version"
URL="https://github.com/${REPO}/releases/download/${VERSION}/share_${VERSION#v}_${OS}_${ARCH}.tar.gz"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
echo "Installing share ${VERSION} (${OS}/${ARCH})..."
curl -fsSL "$URL" -o "$TMP/share.tar.gz"
tar xzf "$TMP/share.tar.gz" -C "$TMP"
mv "$TMP/share" "$INSTALL_DIR/share"
echo "Installed share to ${INSTALL_DIR}/share"
# Add install dir to PATH if needed
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
SHELL_NAME=$(basename "${SHELL:-/bin/bash}")
case "$SHELL_NAME" in
zsh) RC_FILE="$HOME/.zshrc" ;;
bash)
if [ -f "$HOME/.bashrc" ]; then
RC_FILE="$HOME/.bashrc"
else
RC_FILE="$HOME/.bash_profile"
fi
;;
fish) RC_FILE="$HOME/.config/fish/config.fish" ;;
*) RC_FILE="$HOME/.profile" ;;
esac
EXPORT_LINE="export PATH=\"${INSTALL_DIR}:\$PATH\""
if [ "$SHELL_NAME" = "fish" ]; then
EXPORT_LINE="fish_add_path ${INSTALL_DIR}"
fi
if ! grep -qF "$INSTALL_DIR" "$RC_FILE" 2>/dev/null; then
echo "" >> "$RC_FILE"
echo "$EXPORT_LINE" >> "$RC_FILE"
echo "Added ${INSTALL_DIR} to PATH in ${RC_FILE}"
fi
export PATH="${INSTALL_DIR}:$PATH"
;;
esac
echo "Run 'share init' to configure."