Skip to content

Instantly share code, notes, and snippets.

@raikusy
Last active February 1, 2021 06:23
Show Gist options
  • Save raikusy/7db4d8576fcef92c66cc30bfdbcebc72 to your computer and use it in GitHub Desktop.
Save raikusy/7db4d8576fcef92c66cc30bfdbcebc72 to your computer and use it in GitHub Desktop.
A bash script to setup docker, docker-compose, volta, node, yarn into any ubuntu machine. (using for aws lightsail)
#!/bin/sh
command_exists() {
command -v "$@" > /dev/null 2>&1
}
user="$(id -un 2>/dev/null || true)"
sh_c='sh -c'
if [ "$user" != 'root' ]; then
if command_exists sudo; then
sh_c='sudo -E sh -c'
elif command_exists su; then
sh_c='su -c'
fi
fi
update_system() {
echo "Updating system"
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get upgrade
}
# install Volta
install_volta() {
echo "Installing Volta"
sh -c "wget -qO- https://get.volta.sh | bash"
source ~/.bashrc
# install Node
echo "Intall node & yarn"
volta install node@14
volta install yarn
}
install_docker() {
# Use the official docker install script
echo "Install Docker"
sh -c "wget -qO- https://get.docker.com/ | bash"
# Use docker without sudo
sudo usermod -aG docker ${USER}
}
# Install docker-compose
install_dc() {
COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oE "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | sort --version-sort | tail -n 1`
$sh_c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
sudo chmod +x /usr/local/bin/docker-compose
$sh_c "curl -L https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose"
# Add dco alias for docker-compose
printf "%s\n" "alias dco=docker-compose" >> ~/.bashrc
source ~/.bashrc
}
install_all() {
update_system
install_volta
install_docker
install_dc
sudo reboot
}
install_all
@raikusy
Copy link
Author

raikusy commented Jan 29, 2021

Using this script:

curl https://gist.githubusercontent.com/raikusy/7db4d8576fcef92c66cc30bfdbcebc72/raw/4311c9fdd8836d9be577a4a3213825daa6056d33/setup-aws.sh | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment