Skip to content

Instantly share code, notes, and snippets.

@hsntgm
Created October 12, 2021 20:50
Show Gist options
  • Save hsntgm/5e275871ccf2bf3ae9e5b80b5a93ac0f to your computer and use it in GitHub Desktop.
Save hsntgm/5e275871ccf2bf3ae9e5b80b5a93ac0f to your computer and use it in GitHub Desktop.
Useful function to get cpanm manually instead of relying package managers
# Need for further perl module installation which not found in distribution repo
# Best way for scripted perl module installation
get_cpanm (){
if ! command -v cpanm >/dev/null 2>&1; then # Check in $PATH
if [[ ! -f /usr/local/bin/cpanm ]]; then # Check in local path
{
cd /tmp
curl -sLk https://cpanmin.us | perl - --sudo App::cpanminus
} >/dev/null 2>&1
fi
if [[ ! -f /usr/local/bin/cpanm ]]; then
{
curl -sLk https://cpanmin.us/ -o cpanm
chmod +x cpanm
mkdir -p /usr/local/bin
mv cpanm /usr/local/bin/cpanm
} >/dev/null 2>&1
fi
fi
CPANM=$(type cpanm | awk '{print $3}')
if [[ ! -f "${CPANM}" && ! -f /usr/local/bin/cpanm ]]; then
return 1
fi
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment