Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·129 lines (114 loc) · 3.9 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·129 lines (114 loc) · 3.9 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
#!/bin/bash
set -e
# Variables
VERSION=${1:-latest}
ARCH=$(uname -m)
[ "$ARCH" = "aarch64" ] && ARCH=arm64
case "$(uname -s)" in
Darwin) ARCHIVE="sesh_Darwin_${ARCH}.zip" ;;
Linux) ARCHIVE="sesh_Linux_${ARCH}.tar.gz" ;;
*)
echo "❌ Sorry, only macOS and Linux are supported"
exit 1
;;
esac
if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "arm64" ]; then
echo "❌ Unsupported architecture: $ARCH"
exit 1
fi
# Install directory is always ~/.local/bin
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
echo "📋 Installing to $INSTALL_DIR (standard user location)"
# Add to PATH if needed
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
SHELL_RC=""
if [[ "$SHELL" == */zsh ]]; then
SHELL_RC="${ZDOTDIR:-$HOME}/.zshrc"
elif [[ "$SHELL" == */bash ]]; then
SHELL_RC="$HOME/.bashrc"
fi
if [ -n "$SHELL_RC" ]; then
if grep -q '/.local/bin' "$SHELL_RC" 2>/dev/null; then
echo "ℹ️ ~/.local/bin is already in $SHELL_RC — open a new terminal to pick it up"
else
# The answer comes from the terminal, not stdin: run as curl … | bash,
# stdin is the script itself. With no terminal, the file is left alone.
REPLY=n
if { exec 3</dev/tty; } 2>/dev/null; then
printf "⚠️ ~/.local/bin is not in your PATH. Add it to %s? [Y/n] " "$SHELL_RC"
read -r REPLY <&3 || true
exec 3<&-
else
echo "⚠️ ~/.local/bin is not in your PATH."
fi
if [[ "$REPLY" =~ ^[Nn]$ ]]; then
echo " To add it manually:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
else
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC"
echo "✅ Added ~/.local/bin to PATH in $SHELL_RC"
echo " Run 'source $SHELL_RC' or open a new terminal to use sesh"
fi
fi
else
echo "⚠️ Please add ~/.local/bin to your PATH:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
fi
# Download the binary
if [ "$VERSION" = "latest" ]; then
BASE_URL="https://github.com/bashhack/sesh/releases/latest/download"
else
BASE_URL="https://github.com/bashhack/sesh/releases/download/${VERSION}"
fi
DOWNLOAD_URL="${BASE_URL}/${ARCHIVE}"
CHECKSUMS_URL="${BASE_URL}/checksums.txt"
echo "⬇️ Downloading sesh from $DOWNLOAD_URL..."
TMP_DIR=$(mktemp -d)
cleanup() { rm -rf "$TMP_DIR"; }
trap cleanup EXIT
if ! curl -sfL -o "$TMP_DIR/$ARCHIVE" "$DOWNLOAD_URL"; then
echo "❌ Download failed. Check that the version exists at:"
echo " https://github.com/bashhack/sesh/releases"
exit 1
fi
# Every release has checksums.txt: the archive is checked against it.
if ! curl -sfL -o "$TMP_DIR/checksums.txt" "$CHECKSUMS_URL"; then
echo "❌ Couldn't download checksums.txt to check the archive against: $CHECKSUMS_URL"
exit 1
fi
EXPECTED=$(grep " ${ARCHIVE}\$" "$TMP_DIR/checksums.txt" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
echo "❌ Checksum entry for ${ARCHIVE} not found in checksums.txt"
exit 1
fi
if command -v sha256sum &>/dev/null; then
ACTUAL=$(sha256sum "$TMP_DIR/$ARCHIVE" | awk '{print $1}')
else
ACTUAL=$(shasum -a 256 "$TMP_DIR/$ARCHIVE" | awk '{print $1}')
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "❌ Checksum verification failed (expected $EXPECTED, got $ACTUAL)"
exit 1
fi
echo "✅ Checksum verified"
case "$ARCHIVE" in
*.zip) unzip -q "$TMP_DIR/$ARCHIVE" -d "$TMP_DIR" ;;
*) tar -xzf "$TMP_DIR/$ARCHIVE" -C "$TMP_DIR" ;;
esac || {
echo "❌ Failed to extract archive. The download may be corrupted — please try again."
exit 1
}
chmod +x "$TMP_DIR/sesh"
mv "$TMP_DIR/sesh" "$INSTALL_DIR/sesh"
# Verify installation
echo "✅ Installation completed!"
"$INSTALL_DIR/sesh" --version
# Check for AWS CLI
if ! command -v aws &>/dev/null; then
echo "ℹ️ The AWS CLI isn't installed. Only sesh aws needs it: https://aws.amazon.com/cli/"
fi
echo ""
echo "🚀 To get started, run:"
echo " sesh # every command; the first sesh add creates your vault"