diff options
author | Denis Kolodin <deniskolodin@gmail.com> | 2016-06-25 08:35:37 +0300 |
---|---|---|
committer | Denis Kolodin <deniskolodin@gmail.com> | 2016-07-03 12:05:51 +0300 |
commit | b8ab419067207127bd05bbefb5a5332d792bca61 (patch) | |
tree | d0c29d582720fee9901e47e3edae50817fc84aed /tools/niminst | |
parent | 7f3b4accb00ea3406bde35123ae27b72a5cad638 (diff) | |
download | Nim-b8ab419067207127bd05bbefb5a5332d792bca61.tar.gz |
Use relative paths in install script template
Diffstat (limited to 'tools/niminst')
-rw-r--r-- | tools/niminst/install.tmpl | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tools/niminst/install.tmpl b/tools/niminst/install.tmpl index f9266b867..3f17840a8 100644 --- a/tools/niminst/install.tmpl +++ b/tools/niminst/install.tmpl @@ -3,7 +3,35 @@ # result = "#! /bin/sh\n# Generated by niminst\n" # var proj = c.name.toLower -set -e +## Current directory you start script from +BASE_DIR=$(pwd) + +## The following one-liner takes directory path which contains install script. +## `command -v -- "$0"` takes path if script sourced from interactive shell +## `dirname` returns relative directory path to install script +## `cd -P` dive into directory to use `pwd` +## `pwd -P` prints full path to install script directory path +## -P option allows to use symlinks in path +## Good explanation can be found here: +## http://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh +NIM_DIR=$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P) + +go_back() { + cd $BASE_DIR +} + +## Go to base dir on exit +trap go_back EXIT + +install_error() { + echo "Nim installation failed!" + exit 1 +} + +## Exit if any command failed +trap install_error ERR ## `set -e` alternative + +cd $NIM_DIR if [ $# -eq 1 ] ; then # if c.cat[fcUnixBin].len > 0: |