Automatically set the absolute path of the program in the wrapper script
[conversations_http_downloader.git] / open_wrapper.sh.in
diff --git a/open_wrapper.sh.in b/open_wrapper.sh.in
new file mode 100644 (file)
index 0000000..16dbc61
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# open_warapper.sh - wrapper script for conversations_http_downloader.py
+#
+# Copyright (C) 2016  Antonio Ospite <ao2@ao2.it>
+#
+# This program is free software. It comes without any warranty, to
+# the extent permitted by applicable law. You can redistribute it
+# and/or modify it under the terms of the Do What The Fuck You Want
+# To Public License, Version 2, as published by Sam Hocevar. See
+# http://sam.zoy.org/wtfpl/COPYING for more details.
+#
+# This script is based on
+# https://github.com/iNPUTmice/ImageDownloader/blob/master/openbrowser.sh
+
+set -e
+
+DOWNLOADER="@bindir@/conversations_http_downloader.py"
+URL="$1"
+
+decrypted_file()
+{
+  URL="$1"
+
+  TEMPDIR=$(mktemp -d)
+
+  cd $TEMPDIR
+  $DOWNLOADER "$URL"
+  cd $OLDPWD
+
+  FILENAME=$(basename ${URL%#*})
+  echo "${TEMPDIR}/${FILENAME}"
+}
+
+if echo -n "$URL" | grep -q '#[[:xdigit:]]\{96\}$';
+then
+  DESTINATION=$(decrypted_file "$URL")
+else
+  DESTINATION="$URL"
+fi
+
+exec xdg-open "$DESTINATION"