Last active
July 1, 2016 10:45
-
-
Save myyc/58d5110c4b0737734a635ab8f0d51930 to your computer and use it in GitHub Desktop.
This file contains 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 zsh | |
log=/tmp/pybs.log | |
pip=/opt/local/bin/pip3.6 | |
pkgs=("pip" "numpy" "scipy" "pandas" "matplotlib" "seaborn") | |
autoload -Uz colors && colors | |
function y() { | |
echo "[$fg[$1]$2$reset_color]\t" | |
} | |
if [[ $1 == "-h" ]]; then | |
echo "$fg[yellow]Usage$reset_color: ./pybs.py [reinstall-python]" | |
exit 0 | |
fi | |
deb=`y red DEB` | |
bs=`y cyan BS` | |
err=`y magenta ERR` | |
echo "$bs Hi. I'm gonna install a bunch of stuff. I might need your root password right now." | |
sudo true | |
if [ ! -e /opt/local ]; then | |
echo "$bs /opt/local/ doesn't exist. I'm gonna create it and set you as the owner." | |
echo "$bs Feel free to change this later if you don't like it." | |
sudo mkdir /opt/local | |
sudo chown `whoami` /opt/local | |
fi | |
echo "" > $log | |
echo -n "$deb Running 'apt-get update' ... " | |
sudo apt-get update &>> $log | |
echo "done!" | |
reinst=0 | |
if [ ! -e $pip ]; then | |
echo "$bs Python 3.6 not found in '/opt/local'. Will install it." | |
reinst=1; | |
fi | |
if [[ $1 == "reinstall-python" || $reinst == 1 ]]; then | |
echo "$deb Installing build dependencies ..." | |
sudo apt-get build-dep --yes python3 &>> $log | |
echo "$deb Installing other dependencies ..." | |
sudo apt-get install --yes libgdbm-dev libbz2-dev liblzma-dev libreadline-dev libssl-dev \ | |
libncurses5-dev libsqlite3-dev &>> $log | |
tmprepo=/tmp/python | |
if [ ! -e $tmprepo ]; then | |
py=`y yellow PY` | |
echo "$py Cloning Python git repo ..." | |
git clone https://github.com/python/cpython $tmprepo &>> $log | |
cd $tmprepo | |
echo "$py Compiling ..." | |
./configure --prefix=/opt/local/ &>> $log | |
make &>> $log | |
echo "$py Installing ..." | |
make install &>> $log | |
cd - | |
rm -rf $tmprepo | |
echo "$py ... done." | |
fi | |
fi | |
echo "$bs Installing/upgrading some Python packages." | |
echo -n "$deb Installing some dependencies ... " | |
sudo apt-get install --yes libopenblas-dev gfortran librsvg2-dev libpng-dev &>> $log | |
echo "done!" | |
pipl=`y green PIP` | |
for pkg in $pkgs; do | |
echo -n "$pipl Installing $pkg ... " | |
$pip install $pkg -U &>> $log | |
if (( $? == 0 )); then | |
echo "done!"; | |
else | |
echo "" | |
echo "$err Couldn't install $pkg ... check '$log'"! | |
exit 1 | |
fi | |
done | |
if [[ `which pip3.6` != $pip ]]; then | |
echo "$bs 'pip3.6' not found in your PATH. Adding /opt/local/bin to your PATH". | |
echo "$bs Running 'export PATH=/opt/local/bin:\$PATH'." | |
export PATH=/opt/local/bin:$PATH | |
echo "$bs Appending this to your '.zshrc'." | |
echo "" >> ~/.zshrc | |
echo "export PATH=/opt/local/bin:\$PATH" >> ~/.zshrc | |
fi | |
echo "$bs All done. Log out just in case and log back in." | |
echo "$bs Bye." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment