+##
+## Check whether a connection to HOSTNAME ($1) on PORT ($2) is possible
+##
+connect_to_port () {
+ HOST="$1"
+ PORT="$2"
+ VERIFY=$(date +%s | sha256sum | base64 | head -c 20)
+ if ! [ -x "$(command -v nc)" ]; then
+ echo "In order to check the connection to $HOST:$PORT we need to open a socket using netcat."
+ echo However netcat is not installed on your system. You can continue without this check
+ echo or abort the setup, install netcat and try again.
+ while true; do
+ read -p "Would you like to continue without this check? [yn] " yn
+ case $yn in
+ [Yy]*) return 2 ;;
+ [Nn]*) exit ;;
+ *) echo "Please answer y or n." ;;
+ esac
+ done
+ else
+ echo -e "HTTP/1.1 200 OK\n\n $VERIFY" | nc -w 4 -l -p $PORT >/dev/null 2>&1 &
+ if curl --proto =http -s $HOST:$PORT --connect-timeout 3 | grep $VERIFY >/dev/null 2>&1; then
+ return 0
+ else
+ curl --proto =http -s localhost:$PORT >/dev/null 2>&1
+ return 1
+ fi
+ fi
+}
+
+check_IP_match() {
+ HOST="$1"
+ echo
+ echo Checking your domain name . . .
+ connect_to_port $HOST 443; ec=$?
+ case $ec in
+ 0)
+ echo "Connection to $HOST succeeded."
+ ;;
+ 1)
+ echo "WARNING: Port 443 of computer does not appear to be accessible using hostname: $HOST."
+ if connect_to_port $HOST 80; then
+ echo
+ echo SUCCESS: A connection to port 80 succeeds!
+ echo This suggests that your DNS settings are correct,
+ echo but something is keeping traffic to port 443 from getting to your server.
+ echo Check your networking configuration to see that connections to port 443 are allowed.
+ else
+ echo "WARNING: Connection to http://$HOST (port 80) also fails."
+ echo
+ echo "This suggests that $HOST resolves to some IP address that does not reach this "
+ echo machine where you are installing discourse.
+ fi
+ echo
+ echo "The first thing to do is confirm that $HOST resolves to the IP address of this server."
+ echo You usually do this at the same place you purchased the domain.
+ echo
+ echo If you are sure that the IP address resolves correctly, it could be a firewall issue.
+ echo A web search for \"open ports YOUR CLOUD SERVICE\" might help.
+ echo
+ echo This tool is designed only for the most standard installations. If you cannot resolve
+ echo the issue above, you will need to edit containers/app.yml yourself and then type
+ echo
+ echo ./launcher rebuild app
+ echo
+ exit 1
+ ;;
+ 2)
+ echo "Continuing without port check."
+ ;;
+ esac
+}
+
+##
+## Do we have docker?
+##
+check_and_install_docker () {
+ docker_path=`which docker.io || which docker`
+ if [ -z $docker_path ]; then
+ read -p "Docker not installed. Enter to install from https://get.docker.com/ or Ctrl+C to exit"
+ curl https://get.docker.com/ | sh
+ fi
+ docker_path=`which docker.io || which docker`
+ if [ -z $docker_path ]; then
+ echo Docker install failed. Quitting.
+ exit
+ fi
+}
+
+##
+## What are we running on
+##
+check_OS() {
+ echo `uname -s`
+}
+
+##
+## OS X available memory
+##
+check_osx_memory() {
+ echo `free -m | awk '/Mem:/ {print $2}'`
+}
+
+##
+## Linux available memory
+##
+check_linux_memory() {
+ ## some VMs report just under 1GB of RAM, so
+ ## make an exception and allow those with more
+ ## than 989MB
+ mem=`free -m --si | awk ' /Mem:/ {print $2}'`
+ if [ "$mem" -ge 990 -a "$mem" -lt 1000 ]; then
+ echo 1
+ else
+ echo `free -g --si | awk ' /Mem:/ {print $2} '`
+ fi
+}
+