Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ouest-moove committed Jul 24, 2020
1 parent a036db9 commit e82d4a3
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
41 changes: 41 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -e

source "$(dirname "$0")/utils.sh"

install_perl() {
local install_type=$1
local version=$2
local install_path=$3

if [ "$install_type" != "version" ]; then
echoerr "Cannot install specific ref from source, sorry."
echoerr "For a list of available versions, see \`asdf list-all perl\`."
exit 1
fi
install_or_update_perl_build

echo "perl-build $version $install_path"
$(perl_build_path) "$version" "$install_path"
}

install_default_perl_packages() {
local default_perl_packages="${HOME}/.default-perl-packages"

if [ ! -f $default_perl_packages ]; then return; fi

cat "$default_perl_packages" | while read -r name; do
echo -ne "\nInstalling \033[33m${name}\033[39m perl package... "
PATH="$ASDF_INSTALL_PATH/bin:$PATH" pip install "$name" > /dev/null 2>&1 && rc=$? || rc=$?
if [[ $rc -eq 0 ]]; then
echo -e "\033[32mSUCCESS\033[39m"
else
echo -e "\033[31mFAIL\033[39m"
fi
done
}

ensure_perl_build_installed
install_perl "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_default_perl_packages
10 changes: 10 additions & 0 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

source "$(dirname "$0")/utils.sh"

list_all() {
install_or_update_perl_build
$(perl_build_path) --definitions | tr '\n' ' '
}

list_all
57 changes: 57 additions & 0 deletions bin/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
echoerr() {
printf "\033[0;31m%s\033[0m" "$1" >&2
}

ensure_perl_build_installed() {
if [ ! -f "$(perl_build_path)" ]; then
download_perl_build
fi
}

download_perl_build() {
echo "Downloading perl-build..." >&2
local plenv_url="https://github.com/tokuhirom/plenv.git"
local perl_build_url="https://github.com/tokuhirom/Perl-Build.git"
git clone $plenv_url "$(plenv_path)"
git clone $perl_build_url "$(plenv_path)/plugins/perl-build/"
}

perl_build_path() {
echo "$(plenv_path)/plugins/perl-build/bin/perl-build"
}

update_perl_build() {
cd "$(plenv_path)" && git fetch && git reset --hard origin/master > /dev/null 2>&1
}

plenv_path() {
echo "$(dirname $(dirname $0))/plenv"
}

plenv_update_timestamp_path() {
echo "$(dirname $(dirname "$0"))/plenv_last_update"
}

plenv_should_update() {
update_timeout=3600
update_timestamp_path=$(plenv_update_timestamp_path)

if [ ! -f "$update_timestamp_path" ]; then
return 0
fi

last_update=$(cat "$update_timestamp_path")
current_timestamp=$(date +%s)
invalidated_at=$(($last_update + $update_timeout))

[ $invalidated_at -lt $current_timestamp ]
}

install_or_update_perl_build() {
if [ ! -f "$(perl_build_path)" ]; then
download_perl_build
elif plenv_should_update; then
update_perl_build
date +%s > "$(plenv_update_timestamp_path)"
fi
}

0 comments on commit e82d4a3

Please sign in to comment.