Last active
April 21, 2022 22:07
-
-
Save ytnobody/5660193 to your computer and use it in GitHub Desktop.
automated plenv setup - https://github.com/ytnobody/plenvsetup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# shellcheck disable=SC2016 | |
# | |
# plenvsetup http://is.gd/plenvsetup | |
# Tue Jan 7 17:29:22 JST 2020 v0.06 by ytnobody | |
# | |
set -e | |
die () { | |
echo "$1" >&2 | |
exit 1 | |
} | |
write_profile () { | |
if [ ! -f "$PROF_FILE" ] || [ "$(grep -c "$1" "$PROF_FILE")" -le 0 ] ; then | |
echo "$1" >> "$PROF_FILE" | |
fi | |
} | |
write_rc () { | |
if [ ! -f "$RC_FILE" ] || [ "$(grep -c "$1" "$RC_FILE")" -le 0 ]; then | |
echo "$1" >> "$RC_FILE" | |
fi | |
} | |
PLENV_REPO=https://github.com/tokuhirom/plenv.git | |
PLENV_ROOT=$HOME/.plenv | |
PERLBUILDER_REPO=https://github.com/skaji/perl-install | |
PLENV_PLUGIN_DIR=$PLENV_ROOT/plugins | |
if [ "$(echo "$SHELL" | sed -n '/\/bash$/p')" ]; then | |
PROF_FILE=$HOME/.bash_profile | |
RC_FILE=$HOME/.bashrc | |
elif [ "$(echo "$SHELL" | sed -n '/\/zsh$/p')" ]; then | |
PROF_FILE=$HOME/.zprofile | |
RC_FILE=$HOME/.zshrc | |
else | |
echo 'use on bash or zsh only.' | |
exit 1 | |
fi | |
git --version || die "git is not installed." | |
if echo "$HOME" | grep ' ' >/dev/null 2>&1 ; then | |
echo 'this script not support include space to home directory path.' | |
exit 1 | |
# ... or quote all variables? | |
fi | |
### setup plenv | |
if [ ! -d "$PLENV_ROOT" ] ; then | |
git clone "$PLENV_REPO" "$PLENV_ROOT" || die "git clone failure : $PLENV_REPO" | |
fi | |
write_profile 'export PLENV_ROOT=$HOME/.plenv' | |
write_profile 'export PATH=$PLENV_ROOT/bin:$PATH' | |
write_profile 'eval "$(plenv init -)"' | |
grep '\. \~\/\.bashrc' "$PROF_FILE" > /dev/null 2>&1 || write_rc ". $PROF_FILE" | |
### setup Perl-Builder | |
if [ ! -d "$PLENV_PLUGIN_DIR" ] ; then | |
mkdir -p "$PLENV_PLUGIN_DIR" | |
git clone "$PERLBUILDER_REPO" "$PLENV_PLUGIN_DIR/perl-build" || die "git clone failure : $PERLBUILDER_REPO" | |
fi | |
### notify to finished installing | |
echo 'plenv deploy was installed.' | |
echo '' | |
echo 'To finish install plenv, please exec following command.' | |
echo '' | |
echo ' . '"$PROF_FILE" | |
echo '' | |
echo 'or restart your terminal.' | |
echo '' | |
echo 'enjoy.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment