mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
Merge pull request #4410 from DenisKolodin/relinstall
Use relative paths in install script template
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user