FIX: Quote all strings in discourse.conf
[discourse_docker.git] / launcher
index 687557b81c7aedc64ebbd7869a66f8fceeca4d82..879d9b10a57292c5efb44ab78d32aa892d02f672 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -56,15 +56,15 @@ fi
 
 cd "$(dirname "$0")"
 
-docker_min_version='1.8.0'
-docker_rec_version='1.8.0'
+docker_min_version='17.03.1'
+docker_rec_version='17.06.2'
 git_min_version='1.8.0'
 git_rec_version='1.8.0'
 
 config_file=containers/"$config".yml
 cidbootstrap=cids/"$config"_bootstrap.cid
 local_discourse=local_discourse
-image=discourse/base:2.0.20170728
+image=discourse/base:2.0.20171204
 docker_path=`which docker.io || which docker`
 git_path=`which git`
 
@@ -90,25 +90,27 @@ else
                   awk -F: '{ print $3 }';`
 fi
 
+# From https://stackoverflow.com/a/44660519/702738
 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
+    if [[ $1 == $2 ]]; then
+        return 1
+    fi
+    local IFS=.
+    local i a=(${1%%[^0-9.]*}) b=(${2%%[^0-9.]*})
+    local arem=${1#${1%%[^0-9.]*}} brem=${2#${2%%[^0-9.]*}}
+    for ((i=0; i<${#a[@]} || i<${#b[@]}; i++)); do
+        if ((10#${a[i]:-0} < 10#${b[i]:-0})); then
             return 1
-        else
-            unset ver_a[0]
-            ver_a=("${ver_a[@]}")
-            unset ver_b[0]
-            ver_b=("${ver_b[@]}")
+        elif ((10#${a[i]:-0} > 10#${b[i]:-0})); then
+            return 0
         fi
     done
-    return 1  # They are equal
+    if [ "$arem" '<' "$brem" ]; then
+        return 1
+    elif [ "$arem" '>' "$brem" ]; then
+        return 0
+    fi
+    return 1
 }
 
 
@@ -252,12 +254,8 @@ RUBY
 
 
 set_volumes() {
-  local volopts=
-  if selinuxenabled; then
-      volopts=":Z"
-  fi
   volumes=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
-        "require 'yaml'; puts YAML.load(STDIN.readlines.join)['volumes'].map{|v| '-v ' << v['volume']['host'] << ':' << v['volume']['guest'] << '${volopts} '}.join"`
+        "require 'yaml'; puts YAML.load(STDIN.readlines.join)['volumes'].map{|v| '-v ' << v['volume']['host'] << ':' << v['volume']['guest'] << ' '}.join"`
 }
 
 set_links() {
@@ -373,7 +371,7 @@ RUBY
       if [ "$i" == "*ERROR." ]; then
         ok=0
       elif [ -n "$i" ]; then
-        labels[${#labels[@]}]=$i
+        labels[${#labels[@]}]=$(echo $i | sed s/{{config}}/${config}/g)
       fi
     done <<< "$raw"