Skip to content

Instantly share code, notes, and snippets.

@zoidyzoidzoid
Last active December 29, 2017 11:27
Show Gist options
  • Save zoidyzoidzoid/093f36e8aa43ab21e7c5aea176cb2386 to your computer and use it in GitHub Desktop.
Save zoidyzoidzoid/093f36e8aa43ab21e7c5aea176cb2386 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Print out commands for uninstalling old Python 2.7, PyPy, 3.x versions,
# and installing the latest versions.
#
# Currently does 2.7, PyPy, 3.3, 3.4, 3.5, and 3.6.
# pyenv uninstall -f 2.7.13
# pyenv uninstall -f 3.3.6
# pyenv uninstall -f 3.4.6
# pyenv uninstall -f 3.5.3
# pyenv uninstall -f 3.6.0
# pyenv uninstall -f pypy3.3-5.2-alpha1
# pyenv install pypy-dev
# pyenv install 2.7.13
# pyenv install 3.3.6
# pyenv install 3.4.6
# pyenv install 3.5.3
# pyenv install 3.6.1
# pyenv global 3.6.1 3.5.3 2.7.13 pypy-dev
#set -x
set -efu
set -o pipefail
if ! which pyenv-migrate &> /dev/null; then
echo 'pyenv-migrate is required for this script.'
exit 1
fi
if ! which aria2c &> /dev/null; then
echo 'aria2c is recommended to speed up downloads'
fi
installable_versions="$(pyenv install -l)"
installed_versions="$(pyenv versions --bare)"
#for version in "2.7" "3.3" "3.4" "3.5" "3.6"; do
for version in "2.7" "3.5" "3.6"; do
echo "Checking ${version}"
version="${version/./\\.}"
versions="$(echo "$installable_versions" | egrep "^\W*${version}")"
echo "Found versions:"
echo "${versions}"
latest_version="$(echo "$versions" | tail -n 1 | tr -d "[:space:]")"
echo "Latest version: ${latest_version}"
installed_version="$(echo "$installed_versions" | egrep "^\W*${version}" | tr -d "[:space:]")"
echo "Installed version: ${installed_version}"
if [[ "${installed_version}" != "${latest_version}" ]]; then
echo "Needs to update!!!"
pyenv install "${latest_version}"
pyenv migrate "${installed_version}" "${latest_version}"
pyenv uninstall -f "${installed_version}"
fi
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment