Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #! /usr/bin/env sh
  2.  
  3. # Exit in case of error
  4. set -e
  5.  
  6. while getopts 'hn:i:' flag; do
  7. case "$flag" in
  8. h)
  9. echo "This script sets up a server with dockerswarm.rocks ideas."
  10. echo "Run this script on the main node."
  11. echo "flags:"
  12. echo '-n (hostname e.g. "dog.example.com")'
  13. echo '-i (Initialise swarm. Public IP adress required, e.g. "157.230.244.114")'
  14. exit 1
  15. ;;
  16. n)
  17. USE_HOSTNAME=$OPTARG;;
  18. i)
  19. IP=$OPTARG;;
  20. :)
  21. echo "Missing option argument for -$OPTARG" >&2;
  22. exit 1;;
  23. \?)
  24. echo "Invalid option: -$OPTARG" >&2
  25. exit 1
  26. ;;
  27. esac
  28. done
  29.  
  30. # Set up the server hostname
  31. echo $USE_HOSTNAME > /etc/hostname
  32. hostname -F /etc/hostname
  33.  
  34. # Install the latest updates
  35. apt-get update
  36. apt-get upgrade -y
  37.  
  38. # Download Docker
  39. curl -fsSL get.docker.com -o get-docker.sh
  40. # Install Docker using the stable channel (instead of the default "edge")
  41. CHANNEL=stable sh get-docker.sh
  42. # Remove Docker install script
  43. rm get-docker.sh
  44.  
  45. if [ $IP ]; then
  46. docker swarm init --advertise-addr $IP
  47. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement