From 6285d1ea755453112f195de5bee43a0a57972cab Mon Sep 17 00:00:00 2001 From: "James P. Ketrenos" Date: Thu, 19 Sep 2019 14:17:44 -0700 Subject: [PATCH] Improved entry point scripts (sort of) Signed-off-by: James P. Ketrenos --- assets/cmd_decode | 4 +- assets/cmd_encode | 5 ++- assets/entry | 97 +++++++++++++++++++++++++++++++++-------------- intel-docker | 3 ++ 4 files changed, 76 insertions(+), 33 deletions(-) create mode 100755 intel-docker diff --git a/assets/cmd_decode b/assets/cmd_decode index 74a4354..a3ce413 100755 --- a/assets/cmd_decode +++ b/assets/cmd_decode @@ -1,7 +1,8 @@ #!/bin/bash PARAM=$0 -PARAM=${PARAM/.\/cmd_} +# Strip path and cmd_ prefix from command name +PARAM=${PARAM##*/cmd_} short() { echo "Decode H264 video and save as raw file" @@ -40,7 +41,6 @@ ffmpeg \ EOF } - arguments=() for arg in $*; do [[ $arg =~ ^-- ]] && { diff --git a/assets/cmd_encode b/assets/cmd_encode index 45b75cd..f0bd1b5 100755 --- a/assets/cmd_encode +++ b/assets/cmd_encode @@ -1,7 +1,8 @@ #!/bin/bash PARAM=$0 -PARAM=${PARAM/.\/cmd_} +# Strip path and cmd_ prefix from command name +PARAM=${PARAM##*/cmd_} short() { echo "Encode 10 frames from YUV420 raw input as H264 with 5Mbps using VBR mode" @@ -43,8 +44,8 @@ ffmpeg -loglevel debug \ EOF } - arguments=() + for arg in $*; do [[ $arg =~ ^-- ]] && { command=${arg/--} diff --git a/assets/entry b/assets/entry index 8cb7826..d3158fb 100755 --- a/assets/entry +++ b/assets/entry @@ -1,14 +1,24 @@ #!/bin/bash -request=$1 -shift -commands=(info help version ffmpeg) -commands+=(cmd_*) +# Pull off any 'entry' options +options=() +arguments=() +for arg in "$@"; do + (( ${#arguments[@]} == 0 )) && [[ "${arg}" =~ ^--.* ]] && { + options+=(${arg##--}) + } || { + arguments+=($arg) + } +done -cd /assets +request=${arguments[0]} +arguments=("${arguments[@]:1}") -. SOLUTION -. MANIFEST +commands=(info help version ffmpeg shell) +commands+=(/assets/cmd_*) + +. /assets/SOLUTION +. /assets/MANIFEST name() { cat << EOF @@ -33,6 +43,21 @@ 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" @@ -48,7 +73,7 @@ ffmpeg() { [ "$1" == "--short" ] && { echo "Run ffmpeg commands." } || { - /usr/local/bin/ffmpeg $* + /usr/local/bin/ffmpeg "${@}" } } @@ -61,35 +86,49 @@ $(name) Commands: EOF - # Change cmd_foo to ./cmd_foo in expansion below for cmd in ${commands[@]}; do - printf " %-15s %s\n" ${cmd/cmd_} "$(${cmd/cmd_/./cmd_} --short)" + printf " %-15s %s\n" ${cmd##*/cmd_} "$(${cmd} --short)" done } + + echo "" } -case $request in -info) - info $* - ;; +badOption() { +cat << EOF +$(name) -ffmpeg) - ffmpeg $* - ;; +Error: Unrecognized option: $1 -version) - version $* - ;; +EOF + exit 3 +} -help|"") - help $* - ;; +[[ "${request}" == "" ]] && { + request="help" +} -*) - [ ! -f ./cmd_$request ] && { - echo "'${request}' is not a recognized command." +[[ " ${commands[@]} " =~ " ${request} " ]] && { + $request "${arguments[@]}" + exit $? +} + +for option in "${options[@]}"; do + case $option in + debug) debug=1 + ;; + *) unrecognizedOption $option + ;; + esac +done + +[ ! -f /assets/cmd_$request ] && { + echo "'${request}' is not a recognized command." +} || { + (( $debug )) && { + /bin/bash -x /assets/cmd_$request "${arguments[@]}" } || { - ./cmd_$request $* + /assets/cmd_$request "${arguments[@]}" } - ;; -esac + exit $? +} diff --git a/intel-docker b/intel-docker new file mode 100755 index 0000000..fed5920 --- /dev/null +++ b/intel-docker @@ -0,0 +1,3 @@ +#!/bin/sh +QSV_DEVICE=${QSV_DEVICE:-/dev/dri/renderD128} +docker run -e QSV_DEVICE --device=/dev/dri "$@"