Skip to content

Instantly share code, notes, and snippets.

@jtribble
Last active April 26, 2019 22:16
Show Gist options
  • Save jtribble/6f14518dd34f9910f1bd9bd3e3825745 to your computer and use it in GitHub Desktop.
Save jtribble/6f14518dd34f9910f1bd9bd3e3825745 to your computer and use it in GitHub Desktop.
Install Python on CoreOS (e.g., to bootstrap for Ansible)
#!/usr/bin/env bash
set -euo pipefail # See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
IFS=$'\n\t'
if [[ -d ~/.portable-pypy ]]; then
echo "Directory already exists: ~/.portable-pypy"
exit 0
fi
echo "Installing portable pypy for user '${USER}' at location '${HOME}/.portable-pypy'"
wget https://bitbucket.org/squeaky/portable-pypy/downloads/pypy3.5-7.0.0-linux_x86_64-portable.tar.bz2
mkdir -p ~/.portable-pypy
tar xjf pypy3.5-7.0.0-linux_x86_64-portable.tar.bz2 -C ~/.portable-pypy --strip-components=1
rm pypy3.5-7.0.0-linux_x86_64-portable.tar.bz2
~/.portable-pypy/bin/pypy -m ensurepip
~/.portable-pypy/bin/pip3 install -U pip wheel
ln -rsfv ~/.portable-pypy/bin/pypy ~/.portable-pypy/bin/python
ln -rsfv ~/.portable-pypy/bin/pypy3 ~/.portable-pypy/bin/python3
ln -rsfv ~/.portable-pypy/bin/pip3 ~/.portable-pypy/bin/pip
if [[ ! -f ~/.bashrc ]]; then
touch ~/.bashrc
elif [[ ! -w ~/.bashrc ]]; then
cp "$(readlink ~/.bashrc)" ~/.bashrc.new && mv ~/.bashrc.new ~/.bashrc
fi
# shellcheck disable=SC2016
export_line='export PATH="${HOME}/.portable-pypy/bin:${PATH}"'
if ! grep -q "${export_line}" ~/.bashrc; then
old_contents=$(cat ~/.bashrc)
cat <<EOL > ~/.bashrc
# Added by install_portable_pypy.sh - $(date)
${export_line}
${old_contents}
EOL
fi
echo "All done! Source ~/.bashrc to make python available on your path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment