From b2eb581803cb3e5e6ca26eea8b018a22c9b1ea9a Mon Sep 17 00:00:00 2001 From: Mikhail Novosyolov Date: Thu, 2 Sep 2021 11:46:54 +0300 Subject: [PATCH] Add quick and hacky prototype of bbb-build-recording backend --- cups-backend-build-recording.sh | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 cups-backend-build-recording.sh diff --git a/cups-backend-build-recording.sh b/cups-backend-build-recording.sh new file mode 100755 index 0000000..07767a0 --- /dev/null +++ b/cups-backend-build-recording.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +# Put it into /usr/lib/cups/backend/bbb-build-recording + +# Authors: +# - Mikhail Novosyolov , 2021 + +# Based on examples at https://community.kde.org/Printing/Developer_Tools +# Docs: +# - backend(7) https://www.cups.org/doc/man-backend.html +############################################################################### + +set -efu +set -o pipefail + +# jobtitle=meeting ID (/var/bigbluebutton/recording/raw/$meeting_id), +# we are not interested in all other variables +readonly jobtitle=${3} + +BBB_DIR_RAW="${BBB_DIR_RAW:-/var/bigbluebutton/recording/raw}" + +# Exit codes from /usr/include/cups/backend.h +CUPS_BACKEND_OK=0 # Job completed successfully +CUPS_BACKEND_FAILED=1 # Job failed, use error-policy +CUPS_BACKEND_AUTH_REQUIRED=2 # Job failed, authentication required +CUPS_BACKEND_HOLD=3 # Job failed, hold job +CUPS_BACKEND_STOP=4 # Job failed, stop queue +CUPS_BACKEND_CANCEL=5 # Job failed, cancel job +CUPS_BACKEND_RETRY=6 # Job failed, retry this job later +CUPS_BACKEND_RETRY_CURRENT=7 # Job failed, retry this job immediately + +# We use 'set -e', script may fail somewhere, +# make CUPS restart the job later if the error was unexpected +_trap_exit(){ + if [ $? != "$CUPS_BACKEND_OK" ] && [ $? != "$CUPS_BACKEND_FAILED" ]; then + exit "$CUPS_BACKEND_RETRY" + fi +} +trap '_trap_exit' EXIT + +input="" + +case ${#} in + 0 ) + # This is CUPS listing backends + # device-class scheme "Unknown" "device-info" + echo direct bbb-build-recording \"Unknown\" \"Build recording of BigBlueButton\" + exit + ;; + 12 ) + input=/dev/stdin + ;; + 13 ) + # do not remove {} here! + input="${13}" + ;; + * ) + echo CRIT: unsupported number of arguements! 1>&2 + exit "$CUPS_BACKEND_FAILED" + ;; +esac + +if [ "$jobtitle" = "(stdin)" ]; then + echo CRIT: printing job must be titled! 1>&2 + exit "$CUPS_BACKEND_FAILED" +fi + +if [ -z "$jobtitle" ]; then + echo CRIT: empty title of the printing job! 1>&2 + exit "$CUPS_BACKEND_FAILED" +fi + +if ! test -d "$BBB_DIR_RAW"/"$jobtitle" ; then + echo CRIT: recording ${jobtitle} does not exist! 1>&2 + exit "$CUPS_BACKEND_FAILED" +fi + +if ! test -f "$BBB_RAW_DIR"/"$jobtitle"/events.xml ; then + echo CRIT: recording ${jobtitle} does not have events.xml! 1>&2 + exit "$CUPS_BACKEND_FAILED" +fi + +# TODO: process it by ourself +# TODO: watch *.failed and *.done files +# TODO: use ionotify +c=0 +while true +do + # 2 hours + if [ $c -gt 240 ]; then + echo CRIT: timeout waiting for BBB to process recording ${jobtitle} 1>&2 + exit "$CUPS_BACKEND_RETRY" + fi + if test -f /var/bigbluebutton/recording/status/processed/${jobtitle}-presentation.fail; then + echo CRIT: BBB failed to process recording ${jobtitle} 1>&2 + exit "$CUPS_BACKEND_FAILED" + fi + if test -f /var/bigbluebutton/recording/status/processed/${jobtitle}-presentation.done ; then + echo INFO: BBB has processed recording ${jobtitle} 1>&2 + exit "$CUPS_BACKEND_OK" + fi + sleep 30s + c=$((++c)) +done