#!/bin/sh -eu # if not run from AppImage (eg. extracted), use default values APPIMAGE=${APPIMAGE-none} ARGV0=${ARGV0-$0} DIR=`dirname $0` export LD_LIBRARY_PATH=$DIR/usr/lib${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"} # there is an issue with running_from_path() which evaluates this executable # as being system-installed #export PATH=$DIR/usr/bin:$PATH export QT_QPA_FONTDIR=$DIR/usr/lib/fonts export QT_PLUGIN_PATH=$DIR/usr/lib/qt5/plugins export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_PLUGIN_PATH/platforms usage() { printf "usage:\n" printf "\t$ARGV0 [--gui [args]]\n" printf "\t\tinvokes GUI\n" printf "\n" printf "\t$ARGV0 --appimage-help\n" printf "\t\tprints AppImage related options\n" printf "\n" printf "\t$ARGV0 -h|--help|--fullhelp\n" printf "\t\tprints this help (extended version with --fullhelp)\n" printf "\n" printf "\t$ARGV0 -m|--man [uv|hd-rum-transcode]\n" printf "\t\tprints manual page\n" printf "\n" printf "\t$ARGV0 -u|--update [args]\n" printf "\t\tupdates AppImage (args will be passed to appimageupdatetool)\n" printf "\n" printf "\t$ARGV0 --tool uv --help\n" printf "\t\tprints command-line UltraGrid help\n" printf "\n" printf "\t$ARGV0 --tool [args]\n" printf "\t\tinvokes specified tool\n" printf "\t\ttool may be: $(ls $DIR/usr/bin | tr '\n' ' ')\n" printf "\n" printf "\t$ARGV0 args\n" printf "\t\tinvokes command-line UltraGrid\n" printf "\n" } usage_aux() { printf "environment variables:\n" printf "\tULTRAGRID_AUTOUPDATE: 1 - try to autoupdate; 0 - disable update advice\n" printf "\tULTRAGRID_USE_FIREJAIL: run the UltraGrid executable with firejail. If\n" printf "\t the variable contains printf a profile path\n" printf "\t (ends with '.profile'), it will be used.\n" printf "\n" } update_notify_days=90 ## Print update hint if UG binary is older than $update_notify_days days, if $ULTRAGRID_AUTOUPDATE=1 triggers update. handle_updates() { if [ $APPIMAGE = none ]; then return fi if [ -n ${ULTRAGRID_AUTOUPDATE-""} ]; then if [ $ULTRAGRID_AUTOUPDATE -eq 1 ]; then $DIR/appimageupdatetool $APPIMAGE fi return fi if expr $APPIMAGE : '.*continuous' > /dev/null; then update_notify_days=30 fi APPIMAGE_MTIME=$(stat --format=%Y $APPIMAGE) CURR_TIMESTAMP=$(date +%s) if [ $CURR_TIMESTAMP -lt $(($APPIMAGE_MTIME + $update_notify_days * 24 * 60 * 60)) ]; then return fi printf "UltraGrid binary older than $update_notify_days days, consider checking updates:\n" printf "\n" printf "$ARGV0 -u\n" printf "\t- updates AppImage\n" printf "$ARGV0 -u -j; [ \$? -eq 1 ] && echo Update available || echo No update available\n" printf "\t- check for update without actually updating\n" printf "$ARGV0 -u -h\n" printf "\t- prints update options\n" printf "\n" printf "Hint: you can set environment variable ULTRAGRID_AUTOUPDATE to 1 for automatic update or 0 to suppress the above message.\n" printf "\n" } RUN= if [ -n "${ULTRAGRID_USE_FIREJAIL-}" ]; then command -v firejail || { echo "Firejail not present in system!"; exit 1; } if expr $ULTRAGRID_USE_FIREJAIL : '.*\.profile' >/dev/null; then FIREJAIL_OPTS="--profile=$ULTRAGRID_USE_FIREJAIL" else FIREJAIL_OPTS="--caps.drop=all --ipc-namespace --nonewprivs --noroot --protocol=unix,inet,inet6,netlink --seccomp --shell=none --disable-mnt --private-bin=none --private-opt=none --private --read-only=/tmp --writable-var" FIREJAIL_OPTS="$FIREJAIL_OPTS --private-etc=alsa,group,hostname,ld.so.conf,ld.so.cache,ld.so.conf.d,nsswitch.conf,passwd,resolv.conf" fi if firejail --version | grep -iq "d-\{0,1\}bus.*enabled"; then FIREJAIL_OPTS="$FIREJAIL_OPTS --dbus-user=none --dbus-system=none" fi if firejail --help | grep -q -- --keep-var-tmp; then FIREJAIL_OPTS="$FIREJAIL_OPTS --keep-var-tmp" fi RUN="firejail --env=LD_LIBRARY_PATH=${LD_LIBRARY_PATH} $FIREJAIL_OPTS " fi if [ $# -eq 0 -o x"${1-}" = x"--gui" ]; then handle_updates [ $# -eq 0 ] && usage || shift if [ -x $DIR/usr/bin/uv-qt ]; then $DIR/usr/bin/uv-qt --with-uv $DIR/usr/bin/uv "$@" else echo "GUI was not compiled in!" >&2 exit 1 fi elif [ x"$1" = x"--tool" ]; then handle_updates TOOL=$2 shift 2 ${RUN}$DIR/usr/bin/$TOOL "$@" elif [ x"$1" = x"-h" -o x"$1" = x"--help" ]; then usage exit 0 elif [ x"$1" = x"--fullhelp" ]; then usage usage_aux exit 0 elif [ x"$1" = x"-m" -o x"$1" = x"--man" ]; then PAGE=${2:-uv} cat $DIR/usr/share/man/man1/$PAGE.1 | man -l - elif [ x"$1" = x"-u" -o x"$1" = x"--update" ]; then shift unset LD_LIBRARY_PATH touch $APPIMAGE # update AppImage mtime to avoid update notices if there are no updates avalable but were checked for $DIR/appimageupdatetool ${1+"$@" }$APPIMAGE else handle_updates ${RUN}$DIR/usr/bin/uv "$@" fi exit $?