Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·145 lines (120 loc) · 3.92 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·145 lines (120 loc) · 3.92 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# Asana CLI installer
# Usage: curl -fsSL https://raw.githubusercontent.com/vincentsch/asana-cli/main/install.sh | bash
set -euo pipefail
REPO="vincentsch/asana-cli"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
BINARY_NAME="asana"
TMP_DIR=""
cleanup() {
if [ -n "$TMP_DIR" ]; then
rm -rf "$TMP_DIR"
fi
}
trap cleanup EXIT
# Detect OS and architecture
detect_platform() {
local os arch
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux) os="linux" ;;
darwin) os="darwin" ;;
mingw*|msys*|cygwin*) os="windows" ;;
*) echo "Unsupported OS: $os" >&2; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) arch="amd64" ;;
arm64|aarch64) arch="arm64" ;;
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
esac
echo "${os}-${arch}"
}
# Get latest release version
get_latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | \
grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/'
}
main() {
echo "Installing Asana CLI..."
local platform version asset_name url checksums_url binary_path tmp_file checksums_file
platform=$(detect_platform)
echo "Detected platform: $platform"
# Keep the script's own message when the lookup fails; under `set -e` a bare
# failed command substitution would exit silently.
version=$(get_latest_version || true)
if [ -z "$version" ]; then
echo "Could not determine latest version" >&2
exit 1
fi
echo "Latest version: $version"
# Build download URL
if [[ "$platform" == *"windows"* ]]; then
asset_name="${BINARY_NAME}-${platform}.exe"
binary_path="${INSTALL_DIR}/${BINARY_NAME}.exe"
else
asset_name="${BINARY_NAME}-${platform}"
binary_path="${INSTALL_DIR}/${BINARY_NAME}"
fi
url="https://github.com/${REPO}/releases/download/${version}/${asset_name}"
checksums_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
echo "Downloading from: $url"
TMP_DIR=$(mktemp -d)
tmp_file="${TMP_DIR}/${asset_name}"
checksums_file="${TMP_DIR}/checksums.txt"
if ! curl -fsSL "$url" -o "$tmp_file"; then
echo "Download failed" >&2
exit 1
fi
if ! curl -fsSL "$checksums_url" -o "$checksums_file"; then
echo "Checksum download failed" >&2
exit 1
fi
verify_checksum "$checksums_file" "$asset_name" "$tmp_file"
if [ ! -d "$INSTALL_DIR" ]; then
if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
echo "Creating $INSTALL_DIR (requires sudo)..."
sudo mkdir -p "$INSTALL_DIR"
fi
fi
if [ -w "$INSTALL_DIR" ]; then
mv "$tmp_file" "$binary_path"
chmod +x "$binary_path"
else
echo "Installing to $INSTALL_DIR (requires sudo)..."
sudo mv "$tmp_file" "$binary_path"
sudo chmod +x "$binary_path"
fi
echo ""
echo "Asana CLI installed successfully!"
echo ""
echo "Get started:"
echo " asana login"
echo " asana workspace list"
echo ""
echo "For help: asana --help"
}
verify_checksum() {
local checksums_file asset_name downloaded_file expected actual
checksums_file="$1"
asset_name="$2"
downloaded_file="$3"
expected=$(awk -v name="$asset_name" '$2 == name {print $1}' "$checksums_file")
if [ -z "$expected" ]; then
echo "Checksum for $asset_name not found" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$downloaded_file" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$downloaded_file" | awk '{print $1}')
else
echo "Need sha256sum or shasum to verify the download" >&2
exit 1
fi
if [ "$actual" != "$expected" ]; then
echo "Checksum verification failed for $asset_name" >&2
exit 1
fi
}
main "$@"