From d4d57bd976f45cff47e99f0daddc1aaeb19699ae Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Wed, 6 Jan 2021 16:50:52 +0100
Subject: [PATCH] docker/l3d#72 Implement "l3d info"

---
 Dockerfile                    |  1 +
 run/Dockerfile                |  2 +-
 run/scripts/help              |  2 +-
 run/scripts/l3dcurrentversion |  3 +++
 run/scripts/l3dnewversion     |  7 +++++++
 run/scripts/run               |  2 +-
 run/scripts/selfupdate        |  6 +++---
 run/scripts/start             |  3 ++-
 run/scripts/update            |  4 ++--
 run/scripts/version           | 14 ++++++--------
 10 files changed, 27 insertions(+), 17 deletions(-)
 create mode 100755 run/scripts/l3dcurrentversion
 create mode 100755 run/scripts/l3dnewversion

diff --git a/Dockerfile b/Dockerfile
index d1ee73e..fdd96b5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,6 +17,7 @@ ADD start.sh /usr/local/bin/.start
 ADD configIdea.sh /usr/local/bin/.configIdea
 ADD l3dComposer.php /usr/local/bin/.l3dComposer.php
 ADD run/scripts/info /usr/local/bin/l3d
+ADD run/scripts/version /usr/local/bin/version
 
 RUN echo "Install dorgflow" && \
     cd /var/opt && \
diff --git a/run/Dockerfile b/run/Dockerfile
index de57d32..99fa403 100644
--- a/run/Dockerfile
+++ b/run/Dockerfile
@@ -25,6 +25,6 @@ RUN apk add bash curl jq && \
     ln -s /lib/libgcc_s.so.1 /usr/glibc-compat/lib/ && \
     wget -q https://github.com/docker/compose/releases/download/${compose_version}/docker-compose-`uname -s`-`uname -m` -O /usr/local/bin/docker-compose && \
     chmod +x /usr/local/bin/docker-compose && \
-    sed -i -e "s/'{{ version }}'/${VERSION}/g" /usr/local/bin/run
+    sed -i -e "s/'{{ version }}'/${VERSION}/g" /usr/local/bin/l3dcurrentversion
 
 ENTRYPOINT /bin/sh
diff --git a/run/scripts/help b/run/scripts/help
index d3b794b..f2b8ab2 100755
--- a/run/scripts/help
+++ b/run/scripts/help
@@ -3,7 +3,7 @@
 echo "L3D - LakeDropsDrupalDev"
 echo "========================="
 echo ""
-echo "Version: ${VERSION}"
+echo "Version: ${L3DVERSION}"
 echo "Support: https://gitlab.lakedrops.com/docker/l3d"
 echo ""
 echo "Usage:   l3d [ help | version | selfupdate [VERSION] | update | reset | PROJECTNAME | delete PROJECTNAME ] | list"
diff --git a/run/scripts/l3dcurrentversion b/run/scripts/l3dcurrentversion
new file mode 100755
index 0000000..14885ca
--- /dev/null
+++ b/run/scripts/l3dcurrentversion
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+export L3DVERSION='{{ version }}'
diff --git a/run/scripts/l3dnewversion b/run/scripts/l3dnewversion
new file mode 100755
index 0000000..a0aa0e3
--- /dev/null
+++ b/run/scripts/l3dnewversion
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+NEWVERSION=$(curl -s "https://gitlab.lakedrops.com/api/v4/projects/282/repository/tags?order_by=updated&search=^v" | jq -r .[0].name)
+if [[ "$NEWVERSION" == "$L3DVERSION" ]]; then
+  return
+fi
+printf "%s" $NEWVERSION
diff --git a/run/scripts/run b/run/scripts/run
index 4cff91d..191c7a1 100755
--- a/run/scripts/run
+++ b/run/scripts/run
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-export VERSION='{{ version }}'
+/usr/local/bin/l3dcurrentversion
 
 COMMAND=start
 if [[ -n "$1" ]]; then
diff --git a/run/scripts/selfupdate b/run/scripts/selfupdate
index 33c391d..2d7420b 100755
--- a/run/scripts/selfupdate
+++ b/run/scripts/selfupdate
@@ -3,10 +3,10 @@
 if [[ -n $1 ]]; then
   NEWVERSION=$1
 else
-  NEWVERSION=$(curl -s "https://gitlab.lakedrops.com/api/v4/projects/282/repository/tags?order_by=updated&search=^v" | jq -r .[0].name)
+  NEWVERSION=$(/usr/local/bin/l3dcurrentversion)
 fi
 
-if [[ "$NEWVERSION" == "$VERSION" ]]; then
+if [[ "$NEWVERSION" == "" ]]; then
   echo "No new version available"
   exit
 fi
@@ -20,7 +20,7 @@ fi
 
 echo "Self update to version ${NEWVERSION} succeeded!"
 
-export VERSION=${NEWVERSION}
+export L3DVERSION=${NEWVERSION}
 export L3D_FORCE_UPDATE=0
 /usr/local/bin/reset
 
diff --git a/run/scripts/start b/run/scripts/start
index c3a32e0..e7fd7a0 100755
--- a/run/scripts/start
+++ b/run/scripts/start
@@ -40,6 +40,7 @@ function startContainer {
         --hostname ${COMPOSE_PROJECT_NAME}-l3d \
         --user ${USERID}:${GROUPID} \
         --group-add ${GROUPIDS// / --group-add } \
+        --env L3DVERSION=${L3DVERSION} \
         --env L3DSHELL=${L3DSHELL} \
         --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} \
         --env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE} \
@@ -56,7 +57,7 @@ function startContainer {
         --volume ${HOMEDIR}:${HOMEDIR} \
         --workdir /drupal \
         --restart unless-stopped \
-        registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION}
+        registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION}
     fi
     docker exec -it \
       --env HOMEDIR=${HOMEDIR} \
diff --git a/run/scripts/update b/run/scripts/update
index ba662e8..4c1d4ca 100755
--- a/run/scripts/update
+++ b/run/scripts/update
@@ -24,7 +24,7 @@ function cleanup {
       removecontainer $IMAGEID
     done
   else
-    IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION} | head -1)
+    IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION} | head -1)
     removecontainer $IMAGEID rmi
   fi
   docker image ls -q registry.lakedrops.com/docker/node > /tmp/reset.lst
@@ -43,7 +43,7 @@ if [[ -n ${PHP_VERSION} ]]; then
       exit
     fi
     echo "Updating the image ..."
-    STATUS=$(docker pull registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION})
+    STATUS=$(docker pull registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION})
     if [[ "$STATUS" == *"Status: Image is up to date"* ]]; then
       echo "Already up to date"
     else
diff --git a/run/scripts/version b/run/scripts/version
index 5e6c41f..66ebd6c 100755
--- a/run/scripts/version
+++ b/run/scripts/version
@@ -1,12 +1,10 @@
 #!/bin/bash
 
-echo "Version: ${VERSION}"
+echo "Version: ${L3DVERSION}"
 
-NEWVERSION=$(curl -s "https://gitlab.lakedrops.com/api/v4/projects/282/repository/tags?order_by=updated&search=^v" | jq -r .[0].name)
-if [[ "$NEWVERSION" == "$VERSION" ]]; then
-  return
+NEWVERSION=$(/usr/local/bin/l3dcurrentversion)
+if [[ "$NEWVERSION" != "" ]]; then
+  echo ""
+  echo "A new version is available: $NEWVERSION"
+  echo "      run 'l3d selfupdate'"
 fi
-
-echo ""
-echo "A new version is available: $NEWVERSION"
-echo "      run 'l3d selfupdate'"
-- 
GitLab