diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-06-02 17:58:57 +0200 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-06-02 17:58:57 +0200 |
| commit | d49dd672463aff72bd754d657abbd11cf8a0d8e0 (patch) | |
| tree | 87f2c40733ec18528a518013f84e2dd523d15f66 /custom/recv-media.sh | |
| parent | 329245b4e3b9a2a9bbf7afd4570d7da311c58a42 (diff) | |
| download | nixos-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.sh | 56 |
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 | |||
| 3 | pid=$? | ||
| 4 | |||
| 5 | exec 1> >(@utillinux@/bin/logger --id=$pid -t recv-media -p user.notice) | ||
| 6 | exec 2> >(@utillinux@/bin/logger --id=$pid -t recv-media -p user.error) | ||
| 7 | |||
| 8 | [[ -z "$1" || -z "$2" ]] && exit 2 | ||
| 9 | |||
| 10 | dir=@mediaDir@ | ||
| 11 | group=$(@coreutils@/bin/stat -c '%G' $dir) | ||
| 12 | tmpFile="${dir}/.tmp/${1:t}" | ||
| 13 | target="${dir}/${1:t}" | ||
| 14 | |||
| 15 | if [[ -n "${3}" ]]; then | ||
| 16 | target="${dir}"/$(@coreutils@/bin/base64 -d <<<${3}) | ||
| 17 | fi | ||
| 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}) | ||
| 24 | EOF | ||
| 25 | |||
| 26 | if [[ $(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 $*" | ||
| 29 | fi | ||
| 30 | |||
| 31 | typeset -a failures | ||
| 32 | failures=() | ||
| 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 | |||
| 43 | if @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 | ||
| 45 | fi | ||
| 46 | |||
| 47 | if @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 | ||
| 56 | fi | ||
