+compare_version() {
+ declare -a ver_a
+ declare -a ver_b
+ IFS=. read -a ver_a <<< "$1"
+ IFS=. read -a ver_b <<< "$2"
+
+ while [[ -n $ver_a ]]; do
+ if (( ver_a > ver_b )); then
+ return 0
+ elif (( ver_b > ver_a )); then
+ return 1
+ else
+ unset ver_a[0]
+ ver_a=("${ver_a[@]}")
+ unset ver_b[0]
+ ver_b=("${ver_b[@]}")
+ fi
+ done
+ return 1 # They are equal
+}
+
+prereqs() {
+
+ # 1. docker daemon running?
+ test=`$docker_path info >/dev/null`
+
+ if [[ $? -ne 0 ]] ; then
+ echo "Cannot connect to the docker daemon - verify it is running and you have access"
+ exit 1
+ fi
+
+ # 2. running aufs
+ test=`$docker_path info 2> /dev/null | grep 'Driver: aufs'`
+ if [[ "$test" =~ "aufs" ]] ; then : ; else
+ echo "Your Docker installation is not using aufs, in the past we have had issues with it"
+ echo "If you are unable to bootstrap your image (or stop it) please report the issue at:"
+ echo "https://meta.discourse.org/t/discourse-docker-installation-without-aufs/15639"
+ fi
+
+ # 3. running recommended docker version
+ test=($($docker_path --version)) # Get docker version string
+ test=${test[2]//,/} # Get version alone and strip comma if exists
+
+ [[ "$test" =~ "0.12.0" ]] && echo "You are running a broken version of Docker, please upgrade ASAP. See: https://meta.discourse.org/t/the-installation-stopped-in-the-middle/16311/ for more details." && exit 1
+
+ # At least minimum version
+ if compare_version "${docker_min_version}" "${test}"; then
+ echo "ERROR: Docker version ${test} not supported, please upgrade to at least ${docker_min_version}, or recommended ${docker_rec_version}"
+ exit 1
+ fi
+
+ # Recommend best version
+ if compare_version "${docker_rec_version}" "${test}"; then
+ echo "WARNING: Docker version ${test} deprecated, recommend upgrade to ${docker_rec_version} or newer."
+ fi
+
+ # 4. able to attach stderr / out / tty
+ test=`$docker_path run -i --rm -a stdout -a stderr $image echo working`
+ if [[ "$test" =~ "working" ]] ; then : ; else
+ echo "Your Docker installation is not working correctly"
+ echo
+ echo "See: https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam"
+ exit 1
+ fi
+}
+
+if [ "$opt" != "--skip-prereqs" ] ; then
+ prereqs
+fi
+
+get_ssh_pub_key() {
+ if tty -s ; then
+ if [[ ! -e ~/.ssh/id_rsa.pub && ! -e ~/.ssh/id_dsa.pub ]] ; then
+ echo "This user has no SSH key, but a SSH key is required to access the Discourse Docker container."
+ read -p "Generate a SSH key? (Y/n) " -n 1 -r
+ if [[ $REPLY =~ ^[Nn]$ ]] ; then
+ echo
+ echo WARNING: You may not be able to log in to your container.
+ echo
+ else
+ echo
+ echo Generating SSH key
+ mkdir -p ~/.ssh && ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
+ echo
+ fi
+ fi
+ fi
+
+ ssh_pub_key="$(cat ~/.ssh/id_rsa.pub 2>/dev/null || cat ~/.ssh/id_dsa.pub)"
+}
+
+