diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-10-02 23:30:19 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-10-02 23:30:19 +0200 |
commit | cc1755d436bc1d9b6c4b65165de3387b566d0ac6 (patch) | |
tree | 3854ad1db5d99d1b9c3f783414a6a789fea0d77b | |
parent | 81d1878ff325f0a41fc34fdaa4005e5b3ab48407 (diff) | |
download | nixos-cc1755d436bc1d9b6c4b65165de3387b566d0ac6.tar nixos-cc1755d436bc1d9b6c4b65165de3387b566d0ac6.tar.gz nixos-cc1755d436bc1d9b6c4b65165de3387b566d0ac6.tar.bz2 nixos-cc1755d436bc1d9b6c4b65165de3387b566d0ac6.tar.xz nixos-cc1755d436bc1d9b6c4b65165de3387b566d0ac6.zip |
cleanup
-rw-r--r-- | hel/recv-media.nix | 26 |
1 files 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 @@ | |||
1 | { stdenv, coreutils, writeScriptBin, eject, ffmpeg }: | 1 | { stdenv |
2 | , coreutils | ||
3 | , writeScriptBin | ||
4 | , eject | ||
5 | , notifyUser ? "gkleen" | ||
6 | , showTitle ? true | ||
7 | , ffmpeg ? null | ||
8 | , gnused ? null | ||
9 | }: | ||
10 | |||
11 | assert showTitle -> ffmpeg != null && gnused != null; | ||
2 | 12 | ||
3 | writeScriptBin "recv-media" '' | 13 | writeScriptBin "recv-media" '' |
4 | #!${stdenv.shell} | 14 | #!${stdenv.shell} |
5 | 15 | ||
6 | pid=$? | 16 | pid=$? |
7 | 17 | ||
8 | exec 1> >(${eject}/bin/logger --id=$pid -t recv-media -p user.notice) | 18 | export PATH=/var/setuid-wrappers/:${eject}/bin:${coreutils}/bin:${if showTitle then ''${ffmpeg}/bin:${gnused}/bin:'' else ""}$PATH |
9 | exec 2> >(${eject}/bin/logger --id=$pid -t recv-media -p user.error) | ||
10 | 19 | ||
11 | [[ -z "$1" || -z "$2" ]] && exit 2 | 20 | exec 1> >(logger --id=$pid -t recv-media -p user.notice) |
21 | exec 2> >(logger --id=$pid -t recv-media -p user.error) | ||
12 | 22 | ||
13 | PATH=${coreutils}/bin | 23 | [[ -z "$1" || -z "$2" ]] && exit 2 |
14 | 24 | ||
15 | dir=/var/media | 25 | dir=/var/media |
16 | tmpFile="''${dir}"/.tmp/$(basename "$1") | 26 | tmpFile="''${dir}"/.tmp/$(basename "$1") |
@@ -19,13 +29,13 @@ writeScriptBin "recv-media" '' | |||
19 | if ! cp -lnv --preserve=all "$1" "''${target}"; then | 29 | if ! cp -lnv --preserve=all "$1" "''${target}"; then |
20 | mkdir -pv $(dirname "''${tmpFile}") | 30 | mkdir -pv $(dirname "''${tmpFile}") |
21 | 31 | ||
22 | ${eject}/bin/ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" | 32 | ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" |
23 | touch -c -m -t "$2" "''${target}" | 33 | touch -c -m -t "$2" "''${target}" |
24 | fi | 34 | fi |
25 | 35 | ||
26 | ( | 36 | ( |
27 | title=$(${ffmpeg}/bin/ffmpeg -i "''${target}" -f ffmetadata 2>/dev/null | sed -r '/^title=/!d; s/^title=//') | 37 | title=$(ffmpeg -i "''${target}" -f ffmetadata 2>/dev/null | sed -r '/^title=/!d; s/^title=//') |
28 | [[ -z "''${title}" ]] && title=$(basename "$1") | 38 | [[ -z "''${title}" ]] && title=$(basename "$1") |
29 | printf "%s\n%s\n" "''${title}" "" | /var/setuid-wrappers/notify-gkleen -a recv-media || true | 39 | printf "%s\n%s\n" "''${title}" "" | notify-${notifyUser} -a recv-media || true |
30 | ) || true | 40 | ) || true |
31 | '' | 41 | '' |