Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.*.s[a-w][a-z]
.idea
104 changes: 82 additions & 22 deletions evm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
EVM_PS_SHELL="$SHELL"
fi

VERSION="5.0.2"
VERSION="5.0.3"
ERLANG_ORG="http://www.erlang.org/download/"
ERLANG_URL="https://github.com"
FILE_PATH="/erlang/otp/archive/OTP-"
Expand Down Expand Up @@ -125,27 +125,59 @@ function _unzip_strip() {
# shopt is a bash built-in command. Zsh, has setopt instead
# so, set the command according to the type of shell (only supports bash and zsh)
local SHOPT="shopt"
if [[ "$EVM_PS_SHELL" == *zsh ]]; then
if [[ "$EVM_PS_SHELL" == *zsh ]] || [[ "$(which $SHELL)" == *"/zsh" ]] ; then
SHOPT="setopt"
fi

local zip="$1"
local dest="${2:-.}"
local temp=$(mktemp -d)

local -i _err=0
local temp=$(mktemp -d)
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi
unzip -d "$temp" "$zip"
mkdir -p "$dest"
$SHOPT -s dotglob
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi
mkdir -p "$dest"
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi
$SHOPT -s dotglob
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi
local f=("$temp"/*)

if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
mv "$temp"/*/* "$dest"
else
mv "$temp"/* "$dest"
fi

rm -rf "$temp"
}
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi

if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
mv "$temp"/*/* "$dest"
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi

else
mv "$temp"/* "$dest"
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi
fi
rm -rf "$temp"
_err=$?
if [ ${_err} -ne 0 ] ; then
return ${_err}
fi
} # end _unzip_strip


# This function will download the erlang version if needed,
Expand Down Expand Up @@ -193,28 +225,56 @@ function evm_install() {
# tar xvzf ~/.evm/erlang_tars/otp_src_R15B03-1.tar.gz --strip-components 1 -C otp_src_R15B03-1
local UNTAR_DIR=$DEFAULT_TAR_LOCATION$FOLDER_PREFIX$VER
mkdir $UNTAR_DIR
# PARENT_COMMAND=$(ps -o comm= $PPID)
# >&2 echo PWD:$(PWD) PARENT_COMMAND:${PARENT_COMMAND} > $HOME/evm.log
local -i _err=0
_unzip_strip $DEFAULT_TAR_LOCATION$FILE_PREFIX$VER$FILE_EXTENSION $UNTAR_DIR

_err=$?
if [ ${_err} -ne 0 ] ; then
echo "There was an error unzipping ... $UNTAR_DIR"
exit 1
fi
echo "Configuring... $UNTAR_DIR"
_err=0

# In zshell or other systems, the contents of the zip file
# are expanded inside a new directory in the destination,
# so we need to check whether there's one single entry in the destination
# or multiple and cd into the right place
if [ $(ls -1 $UNTAR_DIR | wc -l) -gt 1 ]; then
cd $UNTAR_DIR
_err=$?
else
cd $UNTAR_DIR/* # CD into the new subdirectory
_err=$?
fi
if [ ${_err} -ne 0 ] ; then
echo "There was an error going to directory unzipped ... $UNTAR_DIR"
exit 1
fi

local INSTALL_DIR="$DEFAULT_INSTALL_LOCATION$FOLDER_PREFIX$VER"
# Sanitize extra parameters. Extra spaces break configure
# Multiple spaces becomes one space and spaces from begining of string are removed.
EXTRA="$(echo "$EXTRA" | sed -E 's/[[:blank:]]+/ /g;s/^[[:blank:]]+//g')"
chmod +X otp_build
_err=$?
if [ ${_err} -ne 0 ] ; then
echo "There was an error calling ... .chmod +X otp_build "
exit 1
fi
./otp_build autoconf # To generate the configure file
_err=$?
if [ ${_err} -ne 0 ] ; then
echo "There was an error calling ... ./otp_build autoconf "
exit 1
fi
./configure --prefix="$INSTALL_DIR" $EXTRA

_err=$?
if [ ${_err} -ne 0 ] ; then
echo "There was an error calling ... ./configure --prefix="$INSTALL_DIR" $EXTRA"
exit 1
fi
# Block execution so the user can check if any dependency is missing
# before continue with installation unless '-y' is passed along
# with evm install command
Expand Down Expand Up @@ -607,7 +667,7 @@ function evm() {
_load

## Setup autocomplete
if [[ "$EVM_PS_SHELL" == *zsh ]]; then
if [[ "$EVM_PS_SHELL" == *zsh ]] || [[ "$(which $SHELL)" == *"/zsh" ]] ; then
autoload bashcompinit
bashcompinit
fi
Expand All @@ -622,14 +682,14 @@ function _evm_complete() {
# DEBUG >&2 echo "ps:;$(ps | grep $$)"
# DEBUG >&2 echo "EVM_PS_SHELL:;${EVM_PS_SHELL}"
# DEBUG >&2 echo "who:;${0}"
if [[ "$EVM_PS_SHELL" == *bash ]] ; then
if [[ "$EVM_PS_SHELL" == *bash ]] || [[ "$(which $SHELL)" == *"/bash" ]] ; then
# DEBUG >&2 echo "COMP_CWORD:;${COMP_CWORD};"
i_comp_cword=$COMP_CWORD
COMPREPLY=()
# DEBUG >&2 echo "COMP_WORDS:;${COMP_WORDS};"
cur=${COMP_WORDS[i_comp_cword]}
prev=${COMP_WORDS[i_comp_cword-1]}
elif [[ "$EVM_PS_SHELL" == *zsh ]] ; then
elif [[ "$EVM_PS_SHELL" == *zsh ]] || [[ "$(which $SHELL)" == *"/zsh" ]] ; then
# DEBUG >&2 echo "CURRENT:;${CURRENT};"
# DEBUG >&2 echo "words:;${words};"
# DEBUG >&2 echo "curcontext:;${curcontext};"
Expand All @@ -643,7 +703,7 @@ function _evm_complete() {
# DEBUG >&2 echo "cur:;${cur};"
# DEBUG >&2 echo "prev:;${prev};"

if [[ "$EVM_PS_SHELL" == *bash ]] ; then
if [[ "$EVM_PS_SHELL" == *bash ]] || [[ "$(which $SHELL)" == *"/bash" ]] ; then
# shellcheck disable=SC2086
if [ ${i_comp_cword} -eq 1 ] ; then
# DEBUG >&2 echo "bash true 01"
Expand Down Expand Up @@ -684,7 +744,7 @@ function _evm_complete() {
;;
esac
fi
elif [[ "$EVM_PS_SHELL" == *zsh ]] ; then
elif [[ "$EVM_PS_SHELL" == *zsh ]] || [[ "$(which $SHELL)" == *"/zsh" ]] ; then
# shellcheck disable=SC2086
if [ ${i_comp_cword} -eq 1 ] ; then
# DEBUG >&2 echo "zsh true 01"
Expand Down