Skip to content

Instantly share code, notes, and snippets.

@danipolo
Last active September 4, 2016 20:09
Show Gist options
  • Save danipolo/ede9eb940ae1ada0a99e680a1fd1db1c to your computer and use it in GitHub Desktop.
Save danipolo/ede9eb940ae1ada0a99e680a1fd1db1c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Docker installation script for Ubuntu 16.04 on OVH
# After running the script reboot and check whether docker is running.
# First of all, we check if the user is root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# update and add sudo and certficiates support
apt-get update
apt-get upgrade -y
apt-get install sudo apt-transport-https ca-certificates --yes
echo "Updating Server name"
read -e -p "New server name (like srv.company.tld) : " server_name
if [[ "$server_name" != "" ]]; then
echo $server_name > /etc/hostname
IP=$(ip addr show | grep eth0 | grep inet | tr -s " " | cut -f3 -d " " | cut -f1 -d "/")
hosts_ip=$(grep -q $IP /etc/hosts)
if [[ "$hosts_ip" != "" ]]; then
sed -i "s/$IP.*/$IP $server_name/" /etc/hosts
else
echo "$IP $server_name" >> /etc/hosts
fi
hostname $server_name
/etc/init.d/hostname.sh
fi
# Creating multiple users
create_user=true
while $create_user; do
read -e -p "Create a new SUDO user? [y/N] : " new_user
if [[ ("$new_user" == "y" || "$new_user" == "Y") ]]; then
read -e -p "Username : " user_name
adduser $user_name
usermod -a -G sudo $user_name
else
create_user=false
fi
done
# SSH Server
echo "Improving security on SSH"
echo " * Removing Root Login"
sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config
/etc/init.d/ssh restart
read -e -p "Force update the server? [Y/n] : " force_update
if [[ ("$force_update" == "y" || "$force_update" == "Y" || "$force_update" == "") ]]; then
apt-get --yes update && apt-get --yes upgrade && apt-get dist-upgrade
fi
read -e -p "Automate installation of new upgrades? [Y/n] : " install_unattended
if [[ ("$install_unattended" == "y" || "$install_unattended" == "Y" || "$install_unattended" == "") ]]; then
apt-get --yes install unattended-upgrades
fi
read -e -p "Install Fail2ban? [Y/n] : " install_fail2ban
if [[ ("$install_fail2ban" == "y" || "$install_fail2ban" == "Y" || "$install_fail2ban" == "") ]]; then
apt-get --yes install fail2ban
fi
echo "Add NFS Support"
apt-get install nfs-common nfs-kernel-server -y
depmod
modprobe nfs
modprobe nfsd
echo "Install docker"
export DEBIAN_FRONTEND=noninteractive
# Update your APT package index.
sudo apt-get -y update
# Add the new GPG key.
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
# Add docker.list
sudo echo "deb https://apt.dockerproject.org/repo ubuntu-xenial experimental" > /etc/apt/sources.list.d/docker.list
# Update your APT package index.
sudo apt-get -y update
# Purge the old repo if it exists.
sudo apt-get purge lxc-docker
# Verify that APT is pulling from the right repository.
sudo apt-cache policy docker-engine
# Install the recommended package.
sudo apt-get -y install linux-image-extra-$(uname -r)
# Ubuntu 14.04 or 12.04, apparmor is required.
sudo apt-get -y install apparmor
# Install Docker.
sudo apt-get -y install docker-engine
# Start the docker daemon.
sudo service docker start
# Install PIP for docker compose
sudo apt-get install python-pip
sudo pip install docker-compose
echo "FINISHED"
# Outputs
uname -r
docker -v
docker-compose -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment