summaryrefslogtreecommitdiff
path: root/hel
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-06-02 13:12:50 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-06-02 13:12:50 +0200
commit329245b4e3b9a2a9bbf7afd4570d7da311c58a42 (patch)
tree13661807e0e6375d5f364a629b55ec2eea8b435f /hel
parent63e3d9b95c99509a3d7d2afd6fa8127cadca9d55 (diff)
downloadnixos-329245b4e3b9a2a9bbf7afd4570d7da311c58a42.tar
nixos-329245b4e3b9a2a9bbf7afd4570d7da311c58a42.tar.gz
nixos-329245b4e3b9a2a9bbf7afd4570d7da311c58a42.tar.bz2
nixos-329245b4e3b9a2a9bbf7afd4570d7da311c58a42.tar.xz
nixos-329245b4e3b9a2a9bbf7afd4570d7da311c58a42.zip
work on recv-media
Diffstat (limited to 'hel')
-rw-r--r--hel/recv-media.nix23
1 files changed, 13 insertions, 10 deletions
diff --git a/hel/recv-media.nix b/hel/recv-media.nix
index 582a1ee3..91801593 100644
--- a/hel/recv-media.nix
+++ b/hel/recv-media.nix
@@ -27,11 +27,11 @@ writeScriptBin "recv-media" ''
27 27
28 dir=/var/media 28 dir=/var/media
29 group=$(stat -c '%G' $dir) 29 group=$(stat -c '%G' $dir)
30 tmpFile="''${dir}"/.tmp/$(basename "$1") 30 tmpFile="''${dir}/.tmp/''${1:t}"
31 target="''${dir}"/$(basename "$1") 31 target="''${dir}/''${1:t}"
32 32
33 if [[ -n "''${3}" ]]; then 33 if [[ -n "''${3}" ]]; then
34 target="''${dir}"/$(echo ''${3} | base64 -d) 34 target="''${dir}"/$(base64 -d <<<''${3})
35 fi 35 fi
36 36
37 logger --id=$pid -t recv-media -p user.debug <<EOF 37 logger --id=$pid -t recv-media -p user.debug <<EOF
@@ -46,19 +46,22 @@ writeScriptBin "recv-media" ''
46 exec -- sg $group "$0 $*" 46 exec -- sg $group "$0 $*"
47 fi 47 fi
48 48
49 typeset -a failures
50 failures=()
51
49 ( 52 (
50 if ! cp -lnv --preserve=all "$1" "''${target}"; then 53 if ! cp -lnv --preserve=all "$1" "''${target}"; then
51 mkdir -pv $(dirname "''${tmpFile}") || exit 1 54 mkdir -pv "''${tmpFile:h}" || failures+="mkdir"
52 55
53 ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || exit 1 56 ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || failures+="cp"
54 fi
55 touch -c -m -t "$2" "''${target}" || exit 1
56 ) || (
57 if $notify; then
58 printf "%s\n%s\n" $(basename "$1") "Failed to download" | notify-''${notifyUser} -a recv-media -u Critical
59 fi 57 fi
58 touch -c -m -t "$2" "''${target}" || failures+="touch"
60 ) 59 )
61 60
61 if $notify && [[ $#failures -gt 0 ]]; then
62 printf "%s\n%s\n%s" $(basename "$1") "Failed to download" ''${(j:, :)failures} | notify-''${notifyUser} -a recv-media -u Critical
63 fi
64
62 if $notify; then 65 if $notify; then
63 ( 66 (
64 summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''} 67 summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''}