diff options
Diffstat (limited to 'hel')
| -rw-r--r-- | hel/recv-media.nix | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/hel/recv-media.nix b/hel/recv-media.nix deleted file mode 100644 index 91801593..00000000 --- a/hel/recv-media.nix +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | { stdenv | ||
| 2 | , coreutils | ||
| 3 | , writeScriptBin | ||
| 4 | , eject | ||
| 5 | , notifyUser ? "gkleen" | ||
| 6 | , showTitle ? true | ||
| 7 | , ffmpeg ? null | ||
| 8 | , gnused ? null | ||
| 9 | , wrapperDir ? "/run/wrappers/bin" | ||
| 10 | }: | ||
| 11 | |||
| 12 | assert showTitle -> ffmpeg != null && gnused != null && notifyUser != null; | ||
| 13 | |||
| 14 | writeScriptBin "recv-media" '' | ||
| 15 | #!${stdenv.shell} | ||
| 16 | |||
| 17 | pid=$? | ||
| 18 | notify=${if notifyUser == null then "false" else "true"} | ||
| 19 | notifyUser=${if notifyUser == null then "" else notifyUser} | ||
| 20 | |||
| 21 | PATH=${wrapperDir}:${eject}/bin:${coreutils}/bin${if showTitle then '':${ffmpeg}/bin:${gnused}/bin'' else ""} | ||
| 22 | |||
| 23 | exec 1> >(logger --id=$pid -t recv-media -p user.notice) | ||
| 24 | exec 2> >(logger --id=$pid -t recv-media -p user.error) | ||
| 25 | |||
| 26 | [[ -z "$1" || -z "$2" ]] && exit 2 | ||
| 27 | |||
| 28 | dir=/var/media | ||
| 29 | group=$(stat -c '%G' $dir) | ||
| 30 | tmpFile="''${dir}/.tmp/''${1:t}" | ||
| 31 | target="''${dir}/''${1:t}" | ||
| 32 | |||
| 33 | if [[ -n "''${3}" ]]; then | ||
| 34 | target="''${dir}"/$(base64 -d <<<''${3}) | ||
| 35 | fi | ||
| 36 | |||
| 37 | logger --id=$pid -t recv-media -p user.debug <<EOF | ||
| 38 | $(id) | ||
| 39 | $(stat ''${dir}) | ||
| 40 | $(stat ''${1}) | ||
| 41 | $(echo ''${2}) | ||
| 42 | EOF | ||
| 43 | |||
| 44 | if [[ $(id -Gn) != *"$group"* ]]; then | ||
| 45 | printf "Groups are ā%sā. Trying to switch primary group to ā%sā..." $(id -Gn) $group | ||
| 46 | exec -- sg $group "$0 $*" | ||
| 47 | fi | ||
| 48 | |||
| 49 | typeset -a failures | ||
| 50 | failures=() | ||
| 51 | |||
| 52 | ( | ||
| 53 | if ! cp -lnv --preserve=all "$1" "''${target}"; then | ||
| 54 | mkdir -pv "''${tmpFile:h}" || failures+="mkdir" | ||
| 55 | |||
| 56 | ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || failures+="cp" | ||
| 57 | fi | ||
| 58 | touch -c -m -t "$2" "''${target}" || failures+="touch" | ||
| 59 | ) | ||
| 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 | |||
| 65 | if $notify; then | ||
| 66 | ( | ||
| 67 | summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''} | ||
| 68 | [[ -z "''${summary}" ]] && summary=$(basename "$1") | ||
| 69 | printf "%s\n%s\n" "''${summary}" "" | notify-''${notifyUser} -a recv-media || true | ||
| 70 | ) || true | ||
| 71 | fi | ||
| 72 | '' | ||
