Last active
September 13, 2018 03:45
-
-
Save chrissimpkins/4d4be62555e16274a714ee36ecd24315 to your computer and use it in GitHub Desktop.
restore-py-cache.sh
This file contains hidden or 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 | |
#------------------------------------------- | |
## add to the setup | |
## source ./restore-py-cache.sh 3.7.0 | |
#------------------------------------------- | |
set -e | |
py_ver=${1:-'3.7.0'} | |
py_cache_archive="$SEMAPHORE_CACHE_DIR/py$py_ver-cache.tar.gz" | |
# Install pyenv | |
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash | |
echo 'export PATH="/home/runner/.pyenv/bin:$PATH"' | tee -a ~/.bash_profile | |
echo 'eval "$(pyenv init -)"' | tee -a ~/.bash_profile | |
echo 'eval "$(pyenv virtualenv-init -)"' | tee -a ~/.bash_profile | |
source ~/.bash_profile | |
# Restore the Python version from cache, if exists | |
if [ -e $py_cache_archive ]; then | |
echo "Restoring Python $py_ver installation cache..." | |
tar -xf $py_cache_archive -C $SEMAPHORE_CACHE_DIR | |
rm -rf ~/.pyenv/versions/$py_ver | |
mkdir ~/.pyenv/versions/$py_ver | |
cp -r $SEMAPHORE_CACHE_DIR/py$py_ver/* ~/.pyenv/versions/$py_ver/ | |
echo "Python $py_ver installation cache restored." | |
else | |
echo "Cached Python $py_ver installation not found, downloading..." | |
# install the prerequisites | |
sudo apt-get update | |
sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdm-dev libc6-dev libbz2-dev zlib1g-dev openssl libffi-dev python3-dev python3-setuptools python3-pip wget | |
pyenv install $py_ver | |
rm -rf $SEMAPHORE_CACHE_DIR/py$py_ver | |
cp -r ~/.pyenv/versions/$py_ver $SEMAPHORE_CACHE_DIR/py$py_ver | |
fi | |
pyenv global $py_ver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment