Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Last active April 21, 2022 22:07
Show Gist options
  • Save ytnobody/5660193 to your computer and use it in GitHub Desktop.
Save ytnobody/5660193 to your computer and use it in GitHub Desktop.
automated plenv setup - https://github.com/ytnobody/plenvsetup
#!/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