#!/bin/bash # Pull off any 'entry' options options=() arguments=() for arg in "$@"; do (( ${#arguments[@]} == 0 )) && [[ "${arg}" =~ ^--.* ]] && { options+=(${arg##--}) } || { arguments+=($arg) } done request=${arguments[0]} arguments=("${arguments[@]:1}") commands=(info help version ffmpeg shell) commands+=(/assets/commands/*) . /assets/SOLUTION . /assets/MANIFEST name() { cat << EOF Intel Accelerated Graphics and Media Access container Copyright (C) 2019 Intel Corporation ----- EOF } info() { HW=$(/assets/agama-hw) [ $? ] || { HW="None" } [ "$1" == "--short" ] && { echo "Information about running container environment" } || { cat << EOF $(name) Detected base OS: Ubuntu 19.04 Detected hardware: ${HW} Detected Agama version: ${AGAMA_VERSION} 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 built using Agama $AGAMA_VERSION. EOF } } ffmpeg() { [ "$1" == "--short" ] && { echo "Run ffmpeg commands." } || { /usr/local/bin/ffmpeg "${@}" } } 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 "" } badOption() { cat << EOF $(name) Error: Unrecognized option: $1 EOF exit 3 } [[ "${request}" == "" ]] && { request="help" } [[ " ${commands[@]} " =~ " ${request} " ]] && { $request "${arguments[@]}" exit $? } for option in "${options[@]}"; do case $option in debug) debug=1 ;; *) unrecognizedOption $option ;; esac done [ ! -f /assets/commands/$request ] && { echo "'${request}' is not a recognized command." } || { (( $debug )) && { /bin/bash -x /assets/commands/$request "${arguments[@]}" } || { /assets/commands/$request "${arguments[@]}" } exit $? }