Makefile: use automatic variables in the rule body
[conversations_http_downloader.git] / open_wrapper.sh.in
1 #!/bin/sh
2 #
3 # open_warapper.sh - wrapper script for conversations_http_downloader.py
4 #
5 # Copyright (C) 2016  Antonio Ospite <ao2@ao2.it>
6 #
7 # This program is free software. It comes without any warranty, to
8 # the extent permitted by applicable law. You can redistribute it
9 # and/or modify it under the terms of the Do What The Fuck You Want
10 # To Public License, Version 2, as published by Sam Hocevar. See
11 # http://sam.zoy.org/wtfpl/COPYING for more details.
12 #
13 # This script is based on
14 # https://github.com/iNPUTmice/ImageDownloader/blob/master/openbrowser.sh
15
16 set -e
17
18 DOWNLOADER="@bindir@/conversations_http_downloader.py"
19 URL="$1"
20
21 decrypted_file()
22 {
23   URL="$1"
24
25   TEMPDIR=$(mktemp -d)
26
27   cd $TEMPDIR
28   $DOWNLOADER "$URL"
29   cd $OLDPWD
30
31   FILENAME=$(basename ${URL%#*})
32   echo "${TEMPDIR}/${FILENAME}"
33 }
34
35 if echo -n "$URL" | grep -q '#[[:xdigit:]]\{96\}$';
36 then
37   DESTINATION=$(decrypted_file "$URL")
38 else
39   DESTINATION="$URL"
40 fi
41
42 exec xdg-open "$DESTINATION"