Skip to content

Instantly share code, notes, and snippets.

@jasonbunk
Last active November 13, 2019 22:37
Show Gist options
  • Save jasonbunk/99d71696edd7bc7b6957f7f327985082 to your computer and use it in GitHub Desktop.
Save jasonbunk/99d71696edd7bc7b6957f7f327985082 to your computer and use it in GitHub Desktop.
setup bashrc, python virtual environment, cuda (for ubuntu 18.04 x86 desktops)
#!/bin/bash
set -ex
THISPATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# apt installs
sudo bash -c "
apt update && \
apt install -y \
git nano build-essential g++ python3 python3-pip \
autoconf automake \
expect pkg-config meld htop rsync \
curl \
clang \
libboost-system-dev libboost-thread-dev libboost-timer-dev \
libomp-dev \
speedcrunch strip-nondeterminism \
&& \
pip3 install virtualenvwrapper
"
# setup .bashrc and python virtual environment
# bashrc features:
# * "eternal bash history" (stackoverflow link)
# * virtualenvwrapper for python3
# * aliases for git and python development
if grep -Fq "Eternal bash history" ~/.bashrc; then echo " "; else \
echo "####################################################
# Eternal bash history
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT=\"[%F %T] \"
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND=\"history -a; \$PROMPT_COMMAND\"
####################################################
export WORKON_HOME=~/venv
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
####################################################
alias grep4py=\"grep -r --include=\*.py\"
alias gitrup=\"git remote update && git pull origin\"
alias rmpyc=\"rm -f *.pyc */*.pyc */*/*.pyc */*/*/*.pyc */*/*/*/*.pyc\"
" >> ~/.bashrc \
&& sed -i -E 's@^HISTSIZE=[0-9]+@#HISTSIZE=@g' .bashrc \
&& sed -i -E 's@^HISTFILESIZE=[0-9]+@#HISTFILESIZE=@g' .bashrc;
fi
# run the command that looks like export WORKON_HOME, and then the others
$(grep -F "WORKON_HOME=" ~/.bashrc | grep -F "export " | head -1)
$(grep -F "VIRTUALENVWRAPPER_PYTHON=" ~/.bashrc | grep -F "export " | head -1)
$(grep -F "virtualenvwrapper.sh" ~/.bashrc | grep -F "source " | head -1)
if cd $WORKON_HOME/py3cv3; then echo "py3cv3 exists"; else (cd $WORKON_HOME && mkvirtualenv -p /usr/bin/python3 py3cv3); fi
source $WORKON_HOME/py3cv3/bin/activate
source $WORKON_HOME/py3cv3/bin/postactivate
echo $(which python)
echo $(which python3)
echo $(which pip)
echo $(which pip3)
pip install numpy scipy matplotlib requests setuptools wheel cython
######################################################################################
# cuda stuff for ubuntu 18.04 x86
# install CUDA from nvidia website, choosing "deb (local)"
# https://developer.nvidia.com/cuda-downloads
if $(find /usr/local/cuda/lib64/ -type f -iname "libcu*" | grep -q "."); then
echo "looks like cuda is installed ok";
else
wget -nc --continue https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin -P $THISPATH
wget --continue http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-ubuntu1804-10-1-local-10.1.243-418.87.00_1.0-1_amd64.deb -P $THISPATH
sudo bash -c "
cp $THISPATH/cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
dpkg -i $THISPATH/cuda-repo-ubuntu1804-10-1-local-10.1.243-418.87.00_1.0-1_amd64.deb && \
apt-key add /var/cuda-repo-10-1-local-10.1.243-418.87.00/7fa2af80.pub && \
apt-get update && apt-get -y install cuda
"
fi
if $(find /usr/local/cuda/lib64/ -type f -iname "libcudnn*" | grep -q "."); then
echo "looks like cudnn is installed ok";
else
xdg-open https://developer.nvidia.com/rdp/cudnn-download
echo "sudo tar -xf ~/Downloads/cudnn-*.tgz -C /usr/local/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment