From cc1755d436bc1d9b6c4b65165de3387b566d0ac6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 2 Oct 2016 23:30:19 +0200 Subject: cleanup --- hel/recv-media.nix | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hel/recv-media.nix b/hel/recv-media.nix index 06483cdf..bde3e2e8 100644 --- a/hel/recv-media.nix +++ b/hel/recv-media.nix @@ -1,16 +1,26 @@ -{ stdenv, coreutils, writeScriptBin, eject, ffmpeg }: +{ stdenv +, coreutils +, writeScriptBin +, eject +, notifyUser ? "gkleen" +, showTitle ? true +, ffmpeg ? null +, gnused ? null +}: + +assert showTitle -> ffmpeg != null && gnused != null; writeScriptBin "recv-media" '' #!${stdenv.shell} pid=$? - exec 1> >(${eject}/bin/logger --id=$pid -t recv-media -p user.notice) - exec 2> >(${eject}/bin/logger --id=$pid -t recv-media -p user.error) + export PATH=/var/setuid-wrappers/:${eject}/bin:${coreutils}/bin:${if showTitle then ''${ffmpeg}/bin:${gnused}/bin:'' else ""}$PATH - [[ -z "$1" || -z "$2" ]] && exit 2 + exec 1> >(logger --id=$pid -t recv-media -p user.notice) + exec 2> >(logger --id=$pid -t recv-media -p user.error) - PATH=${coreutils}/bin + [[ -z "$1" || -z "$2" ]] && exit 2 dir=/var/media tmpFile="''${dir}"/.tmp/$(basename "$1") @@ -19,13 +29,13 @@ writeScriptBin "recv-media" '' if ! cp -lnv --preserve=all "$1" "''${target}"; then mkdir -pv $(dirname "''${tmpFile}") - ${eject}/bin/ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" + ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" touch -c -m -t "$2" "''${target}" fi ( - title=$(${ffmpeg}/bin/ffmpeg -i "''${target}" -f ffmetadata 2>/dev/null | sed -r '/^title=/!d; s/^title=//') + title=$(ffmpeg -i "''${target}" -f ffmetadata 2>/dev/null | sed -r '/^title=/!d; s/^title=//') [[ -z "''${title}" ]] && title=$(basename "$1") - printf "%s\n%s\n" "''${title}" "" | /var/setuid-wrappers/notify-gkleen -a recv-media || true + printf "%s\n%s\n" "''${title}" "" | notify-${notifyUser} -a recv-media || true ) || true '' -- cgit v1.2.3