overlay: Lift remove implementation to overlay_remove()

Improve readability by isolating the implementation

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ie0fc7857a9d882c29d0406445afa053e3adeb591
diff --git a/overlay/overlay b/overlay/overlay
index f01f8b4..802611d 100755
--- a/overlay/overlay
+++ b/overlay/overlay
@@ -21,6 +21,28 @@
     mount -t overlay -o lowerdir="${o_lowerdir}",upperdir=${o_upperdir},workdir=${o_workdir} overlay "${o_lowerdir}"
 }
 
+overlay_remove() {
+    o_lowerdir="$1"
+    o_options="$(fstab_fs_mntopt $o_lowerdir < /proc/mounts)"
+    umount $o_lowerdir
+    if [ -z "$o_options" ]
+    then
+        echo $o_lowerdir is not an overlay
+        exit 1
+    else
+        echo "${o_options}" |
+            fstab_option_iter |
+            while read FS_MNTOPT
+            do
+                case $FS_MNTOPT in
+                    upperdir=*|workdir=*)
+                        rm -rf "$(echo $FS_MNTOPT | fstab_option_value)"
+                        ;;
+                esac
+            done
+    fi
+}
+
 if [ $# -lt 2 ]
 then
     cat $0
@@ -32,25 +54,7 @@
         overlay_add $2
         ;;
     remove)
-        o_lowerdir="$2"
-        o_options="$(fstab_fs_mntopt $o_lowerdir < /proc/mounts)"
-        umount $o_lowerdir
-        if [ -z "$o_options" ]
-        then
-            echo $o_lowerdir is not an overlay
-            exit 1
-        else
-            echo "${o_options}" |
-                fstab_option_iter |
-                while read FS_MNTOPT
-                do
-                    case $FS_MNTOPT in
-                        upperdir=*|workdir=*)
-                            rm -rf "$(echo $FS_MNTOPT | fstab_option_value)"
-                            ;;
-                    esac
-                done
-        fi
+        overlay_remove $2
         ;;
     -h|--help|*)
         cat $0