파일
rocm-systems/projects/rdc/src/DEBIAN_postinst.in
T
Galantsev, Dmitrii 06a1bba81a INSTALL - Fix rdc groups and lock file check
This fixes issues like:

1.

  /run/lock/rdcd.lock: Bad file descriptor
  Failed to determine owner of lock file.: Numerical result out of range

2.

  rdc.service: Failed to determine group credentials: No such process
  rdc.service: Failed at step GROUP spawning rdcd: No such process

Change-Id: I0ef5eb6ab72d036a3ea8dcb81f7a9108d279f7d6
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>


[ROCm/rdc commit: c015f0fcaa]
2024-08-12 18:54:43 -05:00

117 라인
3.6 KiB
Bash
실행 파일

#!/bin/bash
do_update_alternatives(){
# skip update if program doesn't exist
command -v update-alternatives >/dev/null || return 0
local binaries 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))
binaries=(
rdcd
rdci
)
for i in "${binaries[@]}"
do
# No obvious recover strategy if things fail
# No manual or other slave pages to install
if [ -e @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/"$i" ]
then
update-alternatives --install /usr/bin/"$i" "$i" \
@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/"$i" "$altscore"
else
echo "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/$i not found, but that is OK" >&2
fi
done
true
}
# This will return 0 if an id is created and non-zero if
# it already exists
# https://www.debian.org/doc/debian-policy/ch-opersys.html#users-and-groups
do_create_rdc_user() {
# create rdc group
if ! getent group rdc > /dev/null 2>&1 ; then
addgroup --system rdc
fi
# create rdc user
if ! getent passwd rdc > /dev/null 2>&1 ; then
adduser \
--system \
--quiet \
--home /nonexistent \
--no-create-home \
--disabled-password \
--ingroup rdc \
rdc
fi
# only add render if it exists
if getent group render > /dev/null 2>&1 ; then
usermod -a -G render rdc
fi
# add video always
usermod -a -G video rdc
# Make sure this doesn't return non-zero if an id already exists
return 0
}
create_rdc_service() {
#Symlink RDC Service
if [ -d /run/systemd/system ]; then
ln -s -f -r @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/rdc/rdc.service /lib/systemd/system/rdc.service
fi
}
reload_systemd() {
if [ -d /run/systemd/system ]; then
systemctl daemon-reload
fi
return 0
}
case "$1" in
configure)
do_update_alternatives
do_create_rdc_user
create_rdc_service
reload_systemd
exit 0
;;
abort-upgrade|abort-remove|abort-deconfigure)
echo "$1"
;;
*)
exit 0
;;
esac