diff --git a/bin/install b/bin/install index 21ac644..9cfa085 100755 --- a/bin/install +++ b/bin/install @@ -1,12 +1,71 @@ #!/usr/bin/env bash +export KERL_BUILD_DOCS="${KERL_BUILD_DOCS:-yes}" + set -e -# shellcheck source=../bin/utils.sh -source "$(dirname "$0")/utils.sh" + +# shellcheck source=../lib/utils.sh +source "$(dirname $0)/../lib/utils.sh" install_erlang() { ensure_kerl_setup + + + if [ -z "$KERL_CONFIGURE_OPTIONS" ]; then + echo "KERL_CONFIGURE_OPTIONS is not set, will use default settings." + + export KERL_CONFIGURE_OPTIONS="--disable-debug --disable-silent-rules --enable-dynamic-ssl-lib" + export KERL_CONFIGURE_OPTIONS="$KERL_CONFIGURE_OPTIONS --enable-hipe --enable-sctp --enable-shared-zlib --enable-smp-support" + export KERL_CONFIGURE_OPTIONS="$KERL_CONFIGURE_OPTIONS --enable-threads --enable-wx --without-javac" + + if [ "$(uname -s)" = "Darwin" ]; then + echo "Using Homebrew for dependencies." + if [ -x "$(command -v brew)" ]; then + if [ ! -d "$(brew --prefix autoconf)" ]; then + echo "Missing autoconf from Homebrew" + echo "brew install autoconf" + exit 1 + fi + if [ ! -d "$(brew --prefix libtool)" ]; then + echo "Missing libtool from Homebrew" + echo "brew install libtool" + exit 1 + fi + if [ ! -d "$(brew --prefix openssl)" ]; then + echo "Missing openssl from Homebrew" + echo "brew install openssl" + exit 1 + fi + if [ ! -d "$(brew --prefix wxmac)" ]; then + echo "Missing wxmac from Homebrew" + echo "brew install wxmac" + exit 1 + fi + export KERL_CONFIGURE_OPTIONS="$KERL_CONFIGURE_OPTIONS --with-ssl=$(brew --prefix openssl) --enable-darwin-64bit --enable-kernel-poll --with-dynamic-trace=dtrace" + else + echo "Homebrew is not installed or in PATH" + echo "To install without Homebrew, set your own KERL_CONFIGURE_OPTIONS" + fi + fi + fi + + + + + + + echo "Installing Erlang $ASDF_INSTALL_VERSION" + if [ "$KERL_BUILD_DOCS" != "yes" ]; then + unset KERL_BUILD_DOCS + echo "without documentation" + else + echo "With documentation" + fi + echo "With KERL_CONFIGURE_OPTIONS set to: " + echo "$KERL_CONFIGURE_OPTIONS" + echo "---" + local asdf_activation_version local build_name @@ -17,6 +76,7 @@ install_erlang() { $(kerl_path) delete installation "$build_name" || true $(kerl_path) delete build "$build_name" || true + if [ "$ASDF_INSTALL_TYPE" = "ref" ]; then asdf_activation_version="$ASDF_INSTALL_TYPE:$ASDF_INSTALL_VERSION" $(kerl_path) build git "${OTP_GITHUB_URL:-https://github.com/erlang/otp.git}" "$ASDF_INSTALL_VERSION" "$build_name" diff --git a/bin/list-all b/bin/list-all index fb4140f..1e25e09 100755 --- a/bin/list-all +++ b/bin/list-all @@ -1,10 +1,11 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" +# shellcheck source=../lib/utils.sh +source "$(dirname $0)/../lib/utils.sh" + list_all() { ensure_kerl_setup - echo "$("$(kerl_path)" list releases | sed -e 's:Run.*::' | tr '\n' ' ')" } diff --git a/bin/uninstall b/bin/uninstall index f32b02a..03f521f 100755 --- a/bin/uninstall +++ b/bin/uninstall @@ -2,7 +2,8 @@ set -e -source "$(dirname $0)/utils.sh" +# shellcheck source=../lib/utils.sh +source "$(dirname $0)/../lib/utils.sh" ensure_kerl_setup diff --git a/bin/utils.sh b/bin/utils.sh deleted file mode 100755 index 423c9db..0000000 --- a/bin/utils.sh +++ /dev/null @@ -1,45 +0,0 @@ -KERL_VERSION="2.1.0" - -ensure_kerl_setup() { - set_kerl_env - ensure_kerl_installed - update_available_versions -} - -ensure_kerl_installed() { - if [ ! -f "$(kerl_path)" ]; then - download_kerl - elif [ "$("$(kerl_path)" version)" != "$KERL_VERSION" ]; then - # If the kerl file already exists and the version does not match, remove - # it and download the correct version - rm "$(kerl_path)" - download_kerl - fi -} - -download_kerl() { - # Print to stderr so asdf doesn't assume this string is a list of versions - echo "Downloading kerl..." >&2 - - local kerl_url="https://raw.githubusercontent.com/kerl/kerl/${KERL_VERSION}/kerl" - - curl -Lso "$(kerl_path)" $kerl_url - chmod +x "$(kerl_path)" -} - -kerl_path() { - echo "$(dirname "$(dirname $0)")/kerl" -} - -set_kerl_env() { - local kerl_home - kerl_home="$(dirname "$(dirname "$0")")/kerl-home" - mkdir -p "$kerl_home" - export KERL_BASE_DIR="$kerl_home" - export KERL_BUILD_BACKEND="git" - export KERL_CONFIG="$kerl_home/.kerlrc" -} - -update_available_versions() { - "$(kerl_path)" update releases > /dev/null -} diff --git a/lib/utils.sh b/lib/utils.sh new file mode 100755 index 0000000..c9f9409 --- /dev/null +++ b/lib/utils.sh @@ -0,0 +1,74 @@ +KERL_VERSION="${ASDF_KERL_VERSION:-2.1.0}" + + +echoerr() { + >&2 echo -e "\033[0;31m$1\033[0m" +} + +ensure_kerl_setup() { + export KERL_BASE_DIR="$(kerl_dir)" + export KERL_CONFIG="$(kerl_dir)/kerlrc" + #export KERL_BUILD_BACKEND="git" + ensure_kerl_installed +} + +ensure_kerl_installed() { + # If kerl exists + if [ -x "$(kerl_path)" ]; then + # But was passed an expected version + if [ -n "${ASDF_KERL_VERSION:-}" ]; then + current_kerl_version="$("$(kerl_path)" version)" + # Check if expected version matches current version + if [ "$current_kerl_version" != "$KERL_VERSION" ]; then + # If not, reinstall with ASDF_KERL_VERSION + download_kerl + fi + fi + else + # kerl does not exist, so install using default value in KERL_VERSION + download_kerl + fi +} + + + +download_kerl() { + # Remove directory in case it still exists from last download + rm -rf "$(kerl_source_dir)" + rm -rf "$(kerl_dir)" + + # Print to stderr so asdf doesn't assume this string is a list of versions + echoerr "Downloading kerl $KERL_INSTALL_VERSION" + + # Clone down and checkout the correct kerl version + git clone https://github.com/kerl/kerl.git "$(kerl_source_dir)" --quiet + (cd "$(kerl_source_dir)"; git checkout $KERL_INSTALL_VERSION --quiet;) + + mkdir -p "$(kerl_dir)/bin" + mv "$(kerl_source_dir)/kerl" "$(kerl_path)" + chmod +x "$(kerl_path)" + + rm -rf "$(kerl_source_dir)" +} + +asdf_erlang_plugin_path() { + echo "$(dirname "$(dirname "$0")")" +} + +kerl_dir() { + echo "$(asdf_erlang_plugin_path)/kerl" +} + +kerl_source_dir() { + echo "$(asdf_erlang_plugin_path)/kerl-install-source" +} + + +kerl_path() { + #Check if kerl exists without an expected version + if [ -x "$(command -v kerl)" ] && [ -z "${ASDF_KERL_VERSION:-}" ]; then + echo "$(command -v kerl)" + else + echo "$(kerl_dir)/bin/kerl" + fi +}