1
0
James P. Ketrenos f3991efea3 Updated to latest xe-solutions
Signed-off-by: James P. Ketrenos <james.p.ketrenos@intel.com>
2022-01-06 13:51:51 -08:00

176 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
name() {
cat << EOF
Intel Accelerated Graphics and Media Access container
Copyright (C) 2019-2021 Intel Corporation
-----
EOF
}
info() {
HW=$(/assets/intel-gpu-info)
[ $? ] || {
HW="None"
}
[ "$1" == "--short" ] && {
echo "Information about running container environment"
} || {
cat << EOF
$(name)
Container base OS : ${NAME} ${VERSION}
Detected hardware : ${HW}
Package repository : ${GPGPU_PACKAGE_REPOSITORY}
Package stream : ${GPGPU_PACKAGE_STREAM}
EOF
}
}
shell() {
[ "$1" == "--short" ] && {
echo "Access container via /bin/bash (similar to --entrypoint /bin/bash)"
} || {
(( ${#@} > 0 )) && {
cmd=$1
shift
$cmd "${@}"
exit $?
}
/bin/bash
}
}
version() {
[ "$1" == "--short" ] && {
echo "Show container version information"
} || {
cat << EOF
${CONTAINER} version ${RELEASE_INFO}.
EOF
}
}
help() {
[ "$1" == "--short" ] && {
echo "This help information"
} || {
cat << EOF
$(name)
Commands:
EOF
for cmd in ${commands[@]}; do
printf " %-15s %s\n" ${cmd##*/} "$(${cmd} --short)"
done
}
echo ""
}
# *****************************************************************************
# Execution begins here
# *****************************************************************************
# Parse arguments, looking for -r REPO and -s STREAM at the start
arguments=()
REPO=
STREAM=
while (( ${#@} > 0 )); do
arg=$1
shift
# If any arguments have been provided, stop looking for
# -r and -s options
if (( ${#arguments[@]} )); then
arguments+=($arg)
continue
fi
if [[ "${arg}" == "-r" ]]; then
REPO=$1
shift
elif [[ "${arg}" == "-s" ]]; then
STREAM=$1
shift
else
arguments+=($arg)
fi
done
# First argument is the command
request=${arguments[0]}
# Rest of the arguments
arguments=("${arguments[@]:1}")
# Build up the set of supported commands, including
# on the built-in 'info', 'help', 'version', and 'shell'
commands=(info help version shell)
for file in /assets/commands/*; do
[[ -x "${file}" ]] && commands+=("${file}")
done
# Include solution specific defines
. /assets/SOLUTION
# Include OS specific defines
. /etc/os-release
# If REPO is set, re-configure the system repo file to point to the requested repo
if [[ "${REPO}" != "" ]]; then
echo "Setting repository to: ${REPO}"
case $OS_DISTRO in
ubuntu)
sudo sed -i -e "s,${GPGPU_PACKAGE_REPOSITORY},${REPO},g" /etc/apt/sources.list
;;
sles)
;;
rhel)
;;
esac
export GPGPU_PACKAGE_REPOSITORY=${REPO}
fi
# If STREAM is set, re-configure the system repo file to point to the requested stream
if [[ "${STREAM}" != "" ]]; then
echo "Setting stream to: ${STREAM}"
case $OS_DISTRO in
ubuntu)
sudo sed -i -e "s,${GPGPU_PACKAGE_STREAM},${STREAM},g" /etc/apt/sources.list
;;
sles)
;;
rhel)
;;
esac
export GPGPU_PACKAGE_STREAM=${STREAM}
fi
if [[ "${REPO}" != "" ]] || [[ "${STREAM}" != "" ]]; then
echo -e "\nUpdated container information:"
info
fi
# If no entry point was provided, default to help
request=${request:=help}
# If the requested command is in the set of build-in
# commands then run it with the rest of the arguments
if [[ " ${commands[@]} " =~ " ${request} " ]]; then
$request "${arguments[@]}"
exit $?
fi
# Otherwise if there is not a file with this command, run
# it from within a shell
if [ ! -f /assets/commands/$request ]; then
shell "${request}" "${arguments[@]}"
else
/assets/commands/$request "${arguments[@]}"
exit $?
fi