summaryrefslogtreecommitdiff
path: root/custom/recv-media.sh
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-06-02 17:58:57 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-06-02 17:58:57 +0200
commitd49dd672463aff72bd754d657abbd11cf8a0d8e0 (patch)
tree87f2c40733ec18528a518013f84e2dd523d15f66 /custom/recv-media.sh
parent329245b4e3b9a2a9bbf7afd4570d7da311c58a42 (diff)
downloadnixos-d49dd672463aff72bd754d657abbd11cf8a0d8e0.tar
nixos-d49dd672463aff72bd754d657abbd11cf8a0d8e0.tar.gz
nixos-d49dd672463aff72bd754d657abbd11cf8a0d8e0.tar.bz2
nixos-d49dd672463aff72bd754d657abbd11cf8a0d8e0.tar.xz
nixos-d49dd672463aff72bd754d657abbd11cf8a0d8e0.zip
revamp uucp-mediaclient
Diffstat (limited to 'custom/recv-media.sh')
-rw-r--r--custom/recv-media.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/custom/recv-media.sh b/custom/recv-media.sh
new file mode 100644
index 00000000..29e3d158
--- /dev/null
+++ b/custom/recv-media.sh
@@ -0,0 +1,56 @@
1#!@zsh@/bin/zsh
2
3pid=$?
4
5exec 1> >(@utillinux@/bin/logger --id=$pid -t recv-media -p user.notice)
6exec 2> >(@utillinux@/bin/logger --id=$pid -t recv-media -p user.error)
7
8[[ -z "$1" || -z "$2" ]] && exit 2
9
10dir=@mediaDir@
11group=$(@coreutils@/bin/stat -c '%G' $dir)
12tmpFile="${dir}/.tmp/${1:t}"
13target="${dir}/${1:t}"
14
15if [[ -n "${3}" ]]; then
16 target="${dir}"/$(@coreutils@/bin/base64 -d <<<${3})
17fi
18
19@utillinux@/bin/logger --id=$pid -t recv-media -p user.debug <<EOF
20$(id)
21$(stat ${dir})
22$(stat ${1})
23$(echo ${2})
24EOF
25
26if [[ $(id -Gn) != *"$group"* ]]; then
27 printf "Groups are ā€˜%sā€™. Trying to switch primary group to ā€˜%sā€™..." $(id -Gn) $group
28 exec -- @wrapperDir@/sg $group "$0 $*"
29fi
30
31typeset -a failures
32failures=()
33
34(
35 if ! cp -lnv --preserve=all "$1" "${target}"; then
36 @coreutils@/bin/mkdir -pv "${tmpFile:h}" || failures+="mkdir"
37
38 @utillinux@/bin/ionice -c 3 -t @coreutils@/bin/cp -vn --preserve=all "$1" "${tmpFile}" && mv -v "${tmpFile}" "${target}" || failures+="cp"
39 fi
40 @coreutils@/bin/touch -c -m -t "$2" "${target}" || failures+="touch"
41)
42
43if @doNotify@ && [[ $#failures -gt 0 ]]; then
44 printf "%s\n%s\n%s" "${target:t}" "Failed to download" ${(j:, :)failures} | @notify@ -a recv-media -u Critical
45fi
46
47if @doNotify@; then
48 (
49 if @showTitle@; then
50 summary=$(@ffmpeg@/bin/ffmpeg -i "${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/\[CHAPTER\]/q; /^title=/!d; s/^title=//')
51 else
52 summary=${target:t}
53 fi
54 printf "%s\n%s\n" "${summary}" "" | @notify@ -a recv-media || true
55 ) || true
56fi