{ stdenv , coreutils , writeScriptBin , eject , notifyUser ? "gkleen" , showTitle ? true , ffmpeg ? null , gnused ? null }: assert showTitle -> ffmpeg != null && gnused != null && notifyUser != null; writeScriptBin "recv-media" '' #!${stdenv.shell} pid=$? PATH=${eject}/bin:${coreutils}/bin:${if showTitle then ''${ffmpeg}/bin:${gnused}/bin:'' else ""}/var/setuid-wrappers exec 1> >(logger --id=$pid -t recv-media -p user.notice) exec 2> >(logger --id=$pid -t recv-media -p user.error) [[ -z "$1" || -z "$2" ]] && exit 2 dir=/var/media tmpFile="''${dir}"/.tmp/$(basename "$1") target="''${dir}"/$(basename "$1") if ! cp -lnv --preserve=all "$1" "''${target}"; then mkdir -pv $(dirname "''${tmpFile}") ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" touch -c -m -t "$2" "''${target}" fi ${if notifyUser == null then "" else "#"}exit 0 ( summary=$(${if showTitle then ''ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^title=/!d; s/^title=//' '' else ''""'' fi) [[ -z "''${summary}" ]] && summary=$(basename "$1") printf "%s\n%s\n" "''${summary}" "" | notify-${notifyUser} -a recv-media || true ) || true ''