Skip to content

Instantly share code, notes, and snippets.

@Koasing
Last active August 11, 2019 01:03
Show Gist options
  • Save Koasing/9be97cca5c2e920c5b52c9f4753b77bc to your computer and use it in GitHub Desktop.
Save Koasing/9be97cca5c2e920c5b52c9f4753b77bc to your computer and use it in GitHub Desktop.
ubuntu 1804 + nvidia driver + cuda + cudnn + docker + miniconda
# check PID
if [[ $EUID -ne 0 ]]; then
echo "Not a superuser... run with sudo."
exit 1
fi
# some magic values
SSH_PORT=42222
MACHINE_DIST="ubuntu"$(lsb_release -sr | sed -e "s/\.//g")
MACHINE_ARCH=$(uname -m)
# check file before process begin
if ! dpkg -l "cuda-repo-*" >/dev/null && [ ! -e cuda-repo-${MACHINE_DIST}_*_amd64.deb ]; then
echo "CUDA Repo is not found and installer file is not found. Please download from website below."
echo "https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=${MACHINE_ARCH}&target_distro=$(lsb_release -si)&target_version=${MACHINE_DIST}&target_type=debnetwork"
exit 1
fi
# install essential packages
apt update
apt upgrade -y
apt install -y ssh ufw build-essential add-apt-key apt-transport-https ca-certificates curl software-properties-common
# change ssh port
sed -i "s/^#Port 22$/Port ${SSH_PORT}/g" /etc/ssh/sshd_config
systemctl restart ssh
# check reboot required
if [[ -e /var/run/reboot-required ]]; then
echo "Package updated. System restart required. exit"
exit 0
fi
# test cuda repo
if ! dpkg -l "cuda-repo-*" >/dev/null; then
if [ -e cuda-repo-${MACHINE_DIST}_*_amd64.deb ]; then
dpkg -i cuda-repo-${MACHINE_DIST}_*_amd64.deb
else
echo "CUDA Repo is not found and installer file is not found. Please download from website below."
echo "https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=${MACHINE_ARCH}&target_distro=$(lsb_release -si)&target_version=${MACHINE_DIST}&target_type=debnetwork"
exit 1
fi
fi
# test cudnn repo
if ! dpkg -l "nvidia-machine-learning-repo-*" >/dev/null; then
wget http://developer.download.nvidia.com/compute/machine-learning/repos/${MACHINE_DIST}/${MACHINE_ARCH}/nvidia-machine-learning-repo-${MACHINE_DIST}_1.0.0-1_amd64.deb
if [ -e nvidia-machine-learning-repo-${MACHINE_DIST}_1.0.0-1_amd64.deb ]; then
dpkg -i nvidia-machine-learning-repo-${MACHINE_DIST}_1.0.0-1_amd64.deb
else
echo "cuDNN Repo is not found and installer file is not found. Please download from website below."
echo "http://developer.download.nvidia.com/compute/machine-learning/repos/${MACHINE_DIST}/${MACHINE_ARCH}/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb"
exit 1
fi
fi
apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/${MACHINE_DIST}/${MACHINE_ARCH}/7fa2af80.pub
apt update
apt install -y cuda libcudnn7
# add docker-ce
curl -s -L https://download.docker.com/linux/ubuntu/gpg | apt-key add -
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
# add nvidia-docker2 (deprecated but install anyway)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu$(lsb_release -sr)/nvidia-docker.list > /etc/apt/sources.list.d/nvidia-docker.list
apt update
apt install -y docker-ce docker-ce-cli containerd.io nvidia-docker2
adduser $SUDO_USER docker
# install portainer
systemctl restart docker
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
# enable firewall
if [ -e ip_allow.txt ]; then
ufw enable
while read -r REMOTE_IP LOCAL_PORT
do
ufw allow from ${REMOTE_IP} to any port ${LOCAL_PORT}
done < "ip_allow.txt"
else
echo "No ip_allow.txt found... firewall disabled."
echo "To enable firewall, type \"ufw enable\""
echo "then add rules, type \"ufw allow from {REMOTE_IP} to any port {LOCAL_PORT}\""
fi
# install miniconda
if [ ! -e Miniconda3-latest-Linux-x86_64.sh ]; then
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
fi
bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/Anaconda
echo "Initial setup finished. System restart recommended."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment