[lxc-devel] [lxd-pkg-ubuntu/dpm-focal] Proper handling for WSL upgrade 2

sirredbeard on Github lxc-bot at linuxcontainers.org
Fri Apr 17 18:08:10 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200417/e7c60721/attachment.bin>
-------------- next part --------------
From 85e77b5e9574a0a421ca2a1e2c2fec54849c40ea Mon Sep 17 00:00:00 2001
From: "Jinming Wu, Patrick" <me at patrickwu.space>
Date: Fri, 17 Apr 2020 09:40:43 +0800
Subject: [PATCH 1/7] Properly handling for WSL upgrade

Signed-off-by: Jinming Wu, Patrick <me at patrickwu.space>
---
 debian/lxd.preinst | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index aede3e04..20aa071b 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -23,6 +23,12 @@ case "$1" in
         COUNT=0
         SKIP=false
         while :; do
+            if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ]; then
+                echo "===> WSL detected; Skipping migration"
+                SKIP=true
+                break
+            fi
+
             snap info lxd >/dev/null 2>&1 && break
 
             db_fset lxd/snap-no-connectivity seen false

From 4ad925d827785ea2ee5d0f0e3908b9638aa8d774 Mon Sep 17 00:00:00 2001
From: "Jinming Wu, Patrick" <me at patrickwu.space>
Date: Fri, 17 Apr 2020 23:18:08 +0800
Subject: [PATCH 2/7] Change using the alternative method

Signed-off-by: Jinming Wu, Patrick <me at patrickwu.space>
---
 debian/lxd.preinst | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index 20aa071b..e7179d35 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -23,8 +23,14 @@ case "$1" in
         COUNT=0
         SKIP=false
         while :; do
-            if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ]; then
-                echo "===> WSL detected; Skipping migration"
+            if [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ] \ 
+                || [ ! -e "/run/snapd.socket" ] \
+                && [ ! "$(ls -A /var/lib/lxd/containers)" ] \
+                && [ ! "$(ls -A /var/lib/lxd/images)" ] \
+                && [ ! "$(ls -A /var/lib/lxd/networks)" ] \
+                && [ ! "$(ls -A /var/lib/lxd/storage-pools)" ]
+            then
+                echo "===> System doesn't have working snapd and LXD was never used, skipping"
                 SKIP=true
                 break
             fi

From 3308ab5cd06195f03b8b5aea57afcaaaa80b2030 Mon Sep 17 00:00:00 2001
From: "Jinming Wu, Patrick" <me at patrickwu.space>
Date: Fri, 17 Apr 2020 23:43:57 +0800
Subject: [PATCH 3/7] Further fixes on syntax

Signed-off-by: Jinming Wu, Patrick <me at patrickwu.space>
---
 debian/lxd.preinst | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index e7179d35..2dc15f05 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -23,12 +23,12 @@ case "$1" in
         COUNT=0
         SKIP=false
         while :; do
-            if [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ] \ 
-                || [ ! -e "/run/snapd.socket" ] \
-                && [ ! "$(ls -A /var/lib/lxd/containers)" ] \
-                && [ ! "$(ls -A /var/lib/lxd/images)" ] \
-                && [ ! "$(ls -A /var/lib/lxd/networks)" ] \
-                && [ ! "$(ls -A /var/lib/lxd/storage-pools)" ]
+            if ( [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ] ) \
+                || ( [ ! -e "/run/snapd.socket" ] \
+                && [ -z "$(ls -A /var/lib/lxd/containers)" ] \
+                && [ -z "$(ls -A /var/lib/lxd/images)" ] \
+                && [ -z "$(ls -A /var/lib/lxd/networks)" ] \
+                && [ -z "$(ls -A /var/lib/lxd/storage-pools)" ] )
             then
                 echo "===> System doesn't have working snapd and LXD was never used, skipping"
                 SKIP=true

From 28e93db865d25a1cd5a1c4c7cc4cd5328a7c68ef Mon Sep 17 00:00:00 2001
From: "Jinming Wu, Patrick" <me at patrickwu.space>
Date: Sat, 18 Apr 2020 00:11:29 +0800
Subject: [PATCH 4/7] Further handling for not existing folder

Signed-off-by: Jinming Wu, Patrick <me at patrickwu.space>
---
 debian/lxd.preinst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index 2dc15f05..090dec68 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -25,10 +25,10 @@ case "$1" in
         while :; do
             if ( [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ] ) \
                 || ( [ ! -e "/run/snapd.socket" ] \
-                && [ -z "$(ls -A /var/lib/lxd/containers)" ] \
-                && [ -z "$(ls -A /var/lib/lxd/images)" ] \
-                && [ -z "$(ls -A /var/lib/lxd/networks)" ] \
-                && [ -z "$(ls -A /var/lib/lxd/storage-pools)" ] )
+                && [ -z "$(ls -A /var/lib/lxd/containers >/dev/null 2>&1)" ] \
+                && [ -z "$(ls -A /var/lib/lxd/images >/dev/null 2>&1)" ] \
+                && [ -z "$(ls -A /var/lib/lxd/networks >/dev/null 2>&1)" ] \
+                && [ -z "$(ls -A /var/lib/lxd/storage-pools >/dev/null 2>&1)" ] )
             then
                 echo "===> System doesn't have working snapd and LXD was never used, skipping"
                 SKIP=true

From 6ff57876c0a1cc146b1638831bf17dc009983664 Mon Sep 17 00:00:00 2001
From: "Jinming Wu, Patrick" <me at patrickwu.space>
Date: Sat, 18 Apr 2020 00:58:29 +0800
Subject: [PATCH 5/7] check in functions

Signed-off-by: Jinming Wu, Patrick <me at patrickwu.space>
---
 debian/lxd.preinst | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index 090dec68..11983a22 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -1,6 +1,20 @@
 #!/bin/sh
 set -e
 
+function snapd_lxd_checker {
+    if [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ]; then
+        return 0
+    elif ( [ ! -e "/run/snapd.socket" ] \
+    && [ -z "$(ls -A /var/lib/lxd/containers >/dev/null 2>&1)" ] \
+    && [ -z "$(ls -A /var/lib/lxd/images >/dev/null 2>&1)" ] \
+    && [ -z "$(ls -A /var/lib/lxd/networks >/dev/null 2>&1)" ] \
+    && [ -z "$(ls -A /var/lib/lxd/storage-pools >/dev/null 2>&1)" ] ); then
+        return 0
+    else
+        return 1
+    fi
+}
+
 case "$1" in
     install|upgrade)
         . /usr/share/debconf/confmodule
@@ -23,13 +37,7 @@ case "$1" in
         COUNT=0
         SKIP=false
         while :; do
-            if ( [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ] ) \
-                || ( [ ! -e "/run/snapd.socket" ] \
-                && [ -z "$(ls -A /var/lib/lxd/containers >/dev/null 2>&1)" ] \
-                && [ -z "$(ls -A /var/lib/lxd/images >/dev/null 2>&1)" ] \
-                && [ -z "$(ls -A /var/lib/lxd/networks >/dev/null 2>&1)" ] \
-                && [ -z "$(ls -A /var/lib/lxd/storage-pools >/dev/null 2>&1)" ] )
-            then
+            if snapd_lxd_checker ; then
                 echo "===> System doesn't have working snapd and LXD was never used, skipping"
                 SKIP=true
                 break

From e2e3bad5830add80674e30dc2b5d980e89c6bf61 Mon Sep 17 00:00:00 2001
From: "Jinming Wu, Patrick" <me at patrickwu.space>
Date: Sat, 18 Apr 2020 01:25:28 +0800
Subject: [PATCH 6/7] more specific fix

Signed-off-by: Jinming Wu, Patrick <me at patrickwu.space>
---
 debian/lxd.preinst | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index 11983a22..895361d1 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -4,12 +4,41 @@ set -e
 function snapd_lxd_checker {
     if [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ]; then
         return 0
-    elif ( [ ! -e "/run/snapd.socket" ] \
-    && [ -z "$(ls -A /var/lib/lxd/containers >/dev/null 2>&1)" ] \
-    && [ -z "$(ls -A /var/lib/lxd/images >/dev/null 2>&1)" ] \
-    && [ -z "$(ls -A /var/lib/lxd/networks >/dev/null 2>&1)" ] \
-    && [ -z "$(ls -A /var/lib/lxd/storage-pools >/dev/null 2>&1)" ] ); then
-        return 0
+    elif [ ! -e "/run/snapd.socket" ]; then
+        CHECKERCOUNT=0
+        if [ -d "/var/lib/lxd/containers" ] ; then 
+            if [ -z "$(ls -A /var/lib/lxd/containers)" ]; then
+                CHECKERCOUNT=$((CHECKERCOUNT+1))
+            fi
+        else
+            CHECKERCOUNT=$((CHECKERCOUNT+1))
+        fi
+        if [ -d "/var/lib/lxd/images" ] ; then 
+            if [ -z "$(ls -A /var/lib/lxd/images)" ]; then
+                CHECKERCOUNT=$((CHECKERCOUNT+1))
+            fi
+        else
+            CHECKERCOUNT=$((CHECKERCOUNT+1))
+        fi
+        if [ -d "/var/lib/lxd/networks" ] ; then 
+            if [ -z "$(ls -A /var/lib/lxd/networks)" ]; then
+                CHECKERCOUNT=$((CHECKERCOUNT+1))
+            fi
+        else
+            CHECKERCOUNT=$((CHECKERCOUNT+1))
+        fi
+        if [ -d "/var/lib/lxd/storage-pools" ] ; then 
+            if [ -z "$(ls -A /var/lib/lxd/storage-pools)" ]; then
+                CHECKERCOUNT=$((CHECKERCOUNT+1))
+            fi
+        else
+            CHECKERCOUNT=$((CHECKERCOUNT+1))
+        fi
+        if [ "$CHECKERCOUNT" -eq 4 ]; then
+            return 0
+        else
+            return 1
+        fi
     else
         return 1
     fi

From 63f1bca427de69522c6db0f264fa7c363c9aeefe Mon Sep 17 00:00:00 2001
From: Hayden <hayden.barnes at canonical.com>
Date: Fri, 17 Apr 2020 14:07:29 -0400
Subject: [PATCH 7/7] Change snapd_lxd_checker to snapd_lxd_checker() for
 normal shell style

---
 debian/lxd.preinst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index 895361d1..3c2f482c 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -1,7 +1,7 @@
 #!/bin/sh
 set -e
 
-function snapd_lxd_checker {
+function snapd_lxd_checker() {
     if [ ! -e "/run/snapd.socket" ] && [ ! -e "/var/lib/lxd/server.crt" ]; then
         return 0
     elif [ ! -e "/run/snapd.socket" ]; then


More information about the lxc-devel mailing list