-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·116 lines (97 loc) · 2.64 KB
/
install.sh
File metadata and controls
executable file
·116 lines (97 loc) · 2.64 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
#!/bin/sh
set -e
REPO="joelmoss/workroom"
BINARY="workroom"
# Clean up temp dir on exit
cleanup() {
[ -n "$TMPDIR_CREATED" ] && rm -rf "$TMPDIR_CREATED"
}
trap cleanup EXIT
detect_os() {
case "$(uname -s)" in
Darwin*) echo "darwin" ;;
Linux*) echo "linux" ;;
*)
echo "Error: Unsupported operating system: $(uname -s)" >&2
exit 1
;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*)
echo "Error: Unsupported architecture: $(uname -m)" >&2
exit 1
;;
esac
}
get_latest_version() {
if command -v curl >/dev/null 2>&1; then
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p'
elif command -v wget >/dev/null 2>&1; then
wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p'
else
echo "Error: curl or wget is required" >&2
exit 1
fi
}
download() {
url="$1"
output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$output" "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$output" "$url"
fi
}
main() {
OS=$(detect_os)
ARCH=$(detect_arch)
if [ -n "$VERSION" ]; then
# Ensure version starts with 'v'
case "$VERSION" in
v*) ;;
*) VERSION="v${VERSION}" ;;
esac
else
echo "Fetching latest version..."
VERSION=$(get_latest_version)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine latest version" >&2
exit 1
fi
fi
# Strip leading 'v' for the archive filename
VERSION_NUM="${VERSION#v}"
ARCHIVE="workroom_${VERSION_NUM}_${OS}_${ARCH}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
echo "Installing workroom ${VERSION} (${OS}/${ARCH})..."
TMPDIR_CREATED=$(mktemp -d)
TMPFILE="${TMPDIR_CREATED}/${ARCHIVE}"
echo "Downloading ${URL}..."
download "$URL" "$TMPFILE"
tar -xzf "$TMPFILE" -C "$TMPDIR_CREATED"
INSTALL_DIR="${WORKROOM_INSTALL_PATH:-${HOME}/.local/bin}"
mkdir -p "$INSTALL_DIR"
cp "${TMPDIR_CREATED}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
chmod +x "${INSTALL_DIR}/${BINARY}"
echo "Installed workroom to ${INSTALL_DIR}/${BINARY}"
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "Add ${INSTALL_DIR} to your PATH:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
echo "Add this line to your shell profile (~/.bashrc, ~/.zshrc, etc.) to make it permanent."
;;
esac
# Verify installation
if command -v workroom >/dev/null 2>&1; then
echo ""
workroom version
fi
}
main