#! /usr/bin/env sh # Exit in case of error set -e while getopts 'hn:i:' flag; do case "$flag" in h) echo "This script sets up a server with dockerswarm.rocks ideas." echo "Run this script on the main node." echo "flags:" echo '-n (hostname e.g. "dog.example.com")' echo '-i (Initialise swarm. Public IP adress required, e.g. "157.230.244.114")' exit 1 ;; n) USE_HOSTNAME=$OPTARG;; i) IP=$OPTARG;; :) echo "Missing option argument for -$OPTARG" >&2; exit 1;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; esac done # Set up the server hostname echo $USE_HOSTNAME > /etc/hostname hostname -F /etc/hostname # Install the latest updates apt-get update apt-get upgrade -y # Download Docker curl -fsSL get.docker.com -o get-docker.sh # Install Docker using the stable channel (instead of the default "edge") CHANNEL=stable sh get-docker.sh # Remove Docker install script rm get-docker.sh if [ $IP ]; then docker swarm init --advertise-addr $IP fi