Skip to content

Instantly share code, notes, and snippets.

@privatmamtora
Last active March 23, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save privatmamtora/75c74cc937d54c3620ac to your computer and use it in GitHub Desktop.
Save privatmamtora/75c74cc937d54c3620ac to your computer and use it in GitHub Desktop.
A script to update perl using perlbrew (perlbrew upgrade-perl, doesn't seem to work)
#!/bin/bash
# Name: updateperl
# Purpose: Upgrade perl
# Author: Privat Krish Mamtora Atmaram
# -----------------------------------------------------------------------------------
usage ()
{
cat <<EOF
Update perl version (using perlbrew)
USAGE: . updatePerl
EOF
exit 1;
}
if [ "$#" -ge 1 ]
then
usage
fi
if [[ "$(basename -- "$0")" == "updatePerl" ]]; then
echo "Don't run $0, source it" >&2
exit 1
fi
command -v perlbrew >/dev/null 2>&1 || { echo >&2 "Perlbrew is not installed. Aborting."; exit 1; }
#Situations
#If no current > Get latest
#If not using latest and it is already installed > switch to latest
#If latest not installed and not current > install latest, switch to it, remove current
latest=$(perlbrew available | head -1 | xargs | cut -d " " -f 2)
current=$(perlbrew list | sed '/^*/! d' | cut -d " " -f 2)
installed=$(perlbrew list | sed "/$latest/! d" | xargs | cut -d " " -f 2)
eval "perlbrew self-upgrade"
echo ""
echo "Executing updatePerl"
if [ "$latest" == "$current" ]
then
echo "Already have latest"
elif [ "$latest" != "$current" ] && [ "$latest" == "$installed" ]
then
echo "Have latest, switching to $latest"
eval "perlbrew switch $latest" && source ${PERLBREW_ROOT}/etc/bashrc
elif [ "$latest" != "$current" ] && [ "$latest" != "$installed" ]
then
if [ "$current" != "" ]
then
echo "Dont have latest, installing $latest, removing $current"
eval "perlbrew install --switch $latest" && source ${PERLBREW_ROOT}/etc/bashrc && eval "perlbrew uninstall perl-$current"
else
echo "Dont have latest, installing $latest"
eval "perlbrew install --switch $latest" && source ${PERLBREW_ROOT}/etc/bashrc
fi
fi
echo ""
eval "perlbrew clean"
@privatmamtora
Copy link
Author

Added condition for when don't have latest and no current version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment