diff --git a/lib/asdf.sh b/lib/asdf.sh index b74bc2c1..62fbdbf4 100755 --- a/lib/asdf.sh +++ b/lib/asdf.sh @@ -1,11 +1,3 @@ -#!/usr/bin/env sh - -#TODO run command with args - -#TODO decide which function to run based on args - -ASDF_DIR=$(dirname $0) - run_command() { run_callback_if_command "--version" $1 asdf_version "${@:2}" run_callback_if_command "install" $1 install_command "${@:2}" @@ -20,12 +12,25 @@ run_command() { install_command() { - local source_path=$(get_source_path $1) + local package=$1 + local version=$2 + local source_path=$(get_source_path $package) + check_if_source_exists $source_path - echo "TODO" + + local install_path=$(get_install_path $package $version) + ./${source_path}/install $version $install_path "${@:3}" } +get_install_path() { + local package=$1 + local versio=$2 + mkdir -p $(asdf_dir)/installs/$package + + echo $(asdf_dir)/installs/$package/$(generate_random_hash) +} + list_all_command() { local source_path=$(get_source_path $1) diff --git a/lib/asdf/utils.sh b/lib/asdf/utils.sh index ac29a34e..2c26c515 100644 --- a/lib/asdf/utils.sh +++ b/lib/asdf/utils.sh @@ -8,6 +8,11 @@ asdf_dir() { } +generate_random_hash() { + openssl rand -hex 4 +} + + run_callback_if_command() { if [ "$1" = "$2" ] then diff --git a/sources/erlang/install b/sources/erlang/install new file mode 100755 index 00000000..27e93d17 --- /dev/null +++ b/sources/erlang/install @@ -0,0 +1,55 @@ +#!/usr/bin/env sh + + + +install_erlang() { + local version=$1 + local install_path=$2 + local source_path=$(get_download_file_path $1) + + + # download_git_source $1 + cp ~/projects/asdf/tryout/otp-17.3.4.tar.gz $TMPDIR/ + + # running this in a subshell + # because we don't want to disturb current working dir + echo + ( + cd $(dirname $source_path) + tar zxf $source_path + cd $(untar_path $1) + ./otp_build autoconf + pwd + echo $install_path + ./configure --prefix=$install_path + # make + # make install + ) +} + + +untar_path() { + local version=$1 + echo "$TMPDIR/otp-OTP-$1" +} + + +download_git_source() { + curl -Lo $(get_download_file_path $1) $(get_github_download_url $1) +} + + +get_download_file_path() { + local version=$1 + echo "$TMPDIR/otp-$1.tar.gz" +} + + +get_github_download_url() { + local version=$1 + #TODO support downloading tags, branches and commits + echo "https://github.com/erlang/otp/archive/OTP-${$1}.tar.gz" +} + + +install_erlang $@