-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·163 lines (144 loc) · 4.45 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·163 lines (144 loc) · 4.45 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
set -eu
repository=${XPROBE_REPOSITORY:-itdevwu/xprobe}
version=${XPROBE_VERSION:-0.5.1}
if [ -n "${XPROBE_PREFIX:-}" ]; then
prefix=$XPROBE_PREFIX
elif [ -n "${HOME:-}" ]; then
prefix=$HOME/.local
else
prefix=
fi
uninstall=0
usage() {
cat <<'EOF'
Install a released xprobe binary and its CUDA Agents.
Usage: install.sh [--version VERSION] [--prefix DIR] [--uninstall]
Options:
--version VERSION Release to install (default: 0.5.1)
--prefix DIR Installation prefix (default: $HOME/.local)
--uninstall Remove xprobe from the selected prefix
-h, --help Show this help
EOF
}
fail() {
printf 'xprobe install: %s\n' "$*" >&2
exit 1
}
while [ "$#" -gt 0 ]; do
case $1 in
--version)
[ "$#" -ge 2 ] || fail "--version requires a value"
version=$2
shift 2
;;
--prefix)
[ "$#" -ge 2 ] || fail "--prefix requires a value"
prefix=$2
shift 2
;;
--uninstall)
uninstall=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
fail "unknown argument: $1"
;;
esac
done
[ -n "$prefix" ] || fail "HOME is not set; pass --prefix"
version=${version#v}
case $version in
''|*[!0-9A-Za-z.-]*) fail "invalid release version: $version" ;;
esac
if [ "$uninstall" -eq 1 ]; then
rm -f "$prefix/bin/xprobe" "$prefix/include/xprobe/cupti_agent.h"
rm -rf "$prefix/lib/xprobe" "$prefix/share/xprobe"
printf 'Removed xprobe from %s\n' "$prefix"
exit 0
fi
[ "$(uname -s)" = Linux ] || fail "only Linux is supported"
case $(uname -m) in
x86_64|amd64) ;;
*) fail "only x86_64 is supported" ;;
esac
glibc=$(getconf GNU_LIBC_VERSION) || fail "glibc was not found"
set -- $glibc
[ "${1:-}" = glibc ] && [ -n "${2:-}" ] || fail "glibc was not found"
glibc_major=${2%%.*}
glibc_minor=${2#*.}
glibc_minor=${glibc_minor%%.*}
if [ "$glibc_major" -lt 2 ] || { [ "$glibc_major" -eq 2 ] && [ "$glibc_minor" -lt 34 ]; }; then
fail "glibc 2.34 or newer is required; found $2"
fi
source_dir=
temporary_dir=
case $0 in
install.sh|*/install.sh)
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
if [ -x "$script_dir/bin/xprobe" ]; then
source_dir=$script_dir
fi
;;
esac
cleanup() {
if [ -n "$temporary_dir" ]; then
rm -rf "$temporary_dir"
fi
}
trap cleanup EXIT HUP INT TERM
if [ -z "$source_dir" ]; then
command -v curl >/dev/null 2>&1 || fail "curl is required to download xprobe"
command -v sha256sum >/dev/null 2>&1 || fail "sha256sum is required to verify xprobe"
temporary_dir=$(mktemp -d)
package=xprobe-$version-linux-x86_64
release_url=https://github.com/$repository/releases/download/v$version
archive=$temporary_dir/$package.tar.gz
checksum=$archive.sha256
printf 'Downloading xprobe %s...\n' "$version"
curl --fail --location --proto '=https' --tlsv1.2 \
--output "$archive" "$release_url/$package.tar.gz"
curl --fail --location --proto '=https' --tlsv1.2 \
--output "$checksum" "$release_url/$package.tar.gz.sha256"
(cd "$temporary_dir" && sha256sum --check "$(basename "$checksum")")
tar -xzf "$archive" -C "$temporary_dir"
source_dir=$temporary_dir/$package
fi
[ -x "$source_dir/bin/xprobe" ] || fail "release package does not contain bin/xprobe"
for major in 12 13; do
agent=$source_dir/lib/xprobe/cuda$major/libxprobe-cupti.so
[ -f "$agent" ] || fail "release package does not contain the CUDA $major Agent"
done
[ -f "$source_dir/include/xprobe/cupti_agent.h" ] || \
fail "release package does not contain the CUPTI Agent header"
install -d \
"$prefix/bin" \
"$prefix/lib/xprobe/cuda12" \
"$prefix/lib/xprobe/cuda13" \
"$prefix/include/xprobe" \
"$prefix/share/xprobe"
install -m 0755 "$source_dir/bin/xprobe" "$prefix/bin/xprobe"
for major in 12 13; do
install -m 0755 \
"$source_dir/lib/xprobe/cuda$major/libxprobe-cupti.so" \
"$prefix/lib/xprobe/cuda$major/libxprobe-cupti.so"
done
install -m 0644 \
"$source_dir/include/xprobe/cupti_agent.h" \
"$prefix/include/xprobe/cupti_agent.h"
rm -rf "$prefix/share/xprobe/docs" "$prefix/share/xprobe/schemas" \
"$prefix/share/xprobe/skills"
install -m 0644 "$source_dir/LICENSE" "$source_dir/README.md" \
"$source_dir/AGENTS.md" "$prefix/share/xprobe/"
cp -R "$source_dir/docs" "$source_dir/schemas" "$source_dir/skills" \
"$prefix/share/xprobe/"
"$prefix/bin/xprobe" --version
printf 'Installed xprobe %s to %s\n' "$version" "$prefix"
case :${PATH:-}: in
*:"$prefix/bin":*) ;;
*) printf 'Add %s/bin to PATH to run xprobe.\n' "$prefix" >&2 ;;
esac