Automatically set the absolute path of the program in the wrapper script
authorAntonio Ospite <ao2@ao2.it>
Fri, 29 Jul 2016 14:36:22 +0000 (16:36 +0200)
committerAntonio Ospite <ao2@ao2.it>
Fri, 29 Jul 2016 21:11:55 +0000 (23:11 +0200)
In order to keep the wrapper script open_wrapper.sh simple and solid,
the absolute path of conversations_http_downloader.py is used, however
the hardcoded example value can confuse some users, because the path is
not valid on their system.

So use a Makefile so replace the value automatically.

.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
README
open_wrapper.sh [deleted file]
open_wrapper.sh.in [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a10070b
--- /dev/null
@@ -0,0 +1 @@
+open_wrapper.sh
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..710870f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+bindir ?= $(PWD)
+
+all:
+       sed -e 's#@bindir@#$(bindir)#g' open_wrapper.sh.in > open_wrapper.sh \
+         && chmod +x open_wrapper.sh
+
+clean:
+       rm -f open_wrapper.sh
diff --git a/README b/README
index 1b602f7..9dbc633 100644 (file)
--- a/README
+++ b/README
@@ -23,3 +23,10 @@ Example of use:
 
 The open_wrapper.sh script can be used in gajim as a browser command to
 download, decrypt, and open the files automatically.
 
 The open_wrapper.sh script can be used in gajim as a browser command to
 download, decrypt, and open the files automatically.
+
+
+NOTE:
+
+Run make to prepare the wrapper script, this is needed only the first time the
+project is downloaded.
+
diff --git a/open_wrapper.sh b/open_wrapper.sh
deleted file mode 100755 (executable)
index 7f35ce8..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/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="/home/ao2/Proj/conversations_http_downloader/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"
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"