forked from ROCm/rocm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocm-core.postinst
executable file
·66 lines (57 loc) · 2.46 KB
/
rocm-core.postinst
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
#!/bin/bash
do_update_alternatives(){
# skip update if program doesn't exist
command -v update-alternatives >/dev/null || return 0
local altscore now
now=$(date -u +%s) # Number of seconds since 1 Jan 1970
# The reason for this approach rather than using the build number
# is to allow for jobs from different builds. In one build job the
# job number might be at 1200, whilst in a release job the number
# may be only 1. This approach assums that if you install a build
# with a different semantic version then the highest is the
# desired one, but if you install two with the same semver then
# the newest is the desired version.
# Build up a score. It needs to fit in 32 bits
altscore=$((@VERSION_MAJOR@ - 3))
altscore=$((altscore * 14 + @VERSION_MINOR@)) # Allow up to 14 minor
altscore=$((altscore * 14 + @VERSION_PATCH@)) # Allow up to 14 patch
# So far if the version is less than 9 we have a number (altscore)
# that is less than 1175. 2**31/1175 is about 1.8 million. So
# multiply altscore by 1,000,000 and add in a factor of how many
# minutes have passed from an arbitary point in time (1,600,000,000
# seconds after 1 Jan 1970 or Sep 13 12:26:40 2020) on the
# basis that no one is going to be installing a new version more
# often than every minute. This does get things wrong if a million
# minutes pass and you are downgrading, but the chances of someone
# waiting almost 2 years between installing a version and the
# previous patch level is small.
altscore=$((altscore*1000000+(now-1600000000)/60))
# Update the /opt/rocm symlink
update-alternatives --install "/opt/rocm" "rocm" "@CPACK_PACKAGING_INSTALL_PREFIX@" "$altscore"
for loc in "/usr/share/modules/modulefiles" "/usr/local/Modules/modulefiles" "/usr/share/Modules/modulefiles"
do
if [ -d "$loc" ]
then
mkdir -p "$loc/rocm"
update-alternatives --install "$loc/rocm/@ROCM_VERSION@" "rocmmod@ROCM_VERSION@" "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/rocmmod" "$altscore"
break;
fi
done
true
}
if [ -e /etc/lsb-release ] && source /etc/lsb-release && [ "$DISTRIB_ID" = "Ubuntu" ]
then
case "$1" in
(configure)
do_update_alternatives
;;
(abort-upgrade|abort-remove|abort-deconfigure)
echo "$1"
;;
(*)
exit 0
;;
esac
else
do_update_alternatives
fi