[issue650] live-module revision 1.3

Tong Sun bts at bts.grml.org
Fri Jan 15 21:12:43 CET 2010


Tong Sun <suntong at cpan.org> added the comment:

- move things around
- add my code frame
- nothing else changed
---
 bin/live-module |   68 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/bin/live-module b/bin/live-module
index 56a3f52..c8d9dc6 100755
--- a/bin/live-module
+++ b/bin/live-module
@@ -3,6 +3,8 @@
 . /usr/share/initramfs-tools/scripts/functions
 . /usr/share/initramfs-tools/scripts/live
 
+# FIXME: move the above line and the following functions into a separated lib
+
 # Insert a directory tree $2 to an union specified by $1
 # Top-level read-write branch is specified by it's index 0
 # Using =rr enables aufs to optimize real readonly branches
@@ -47,33 +49,53 @@ try_remount()
    mount -t aufs -o remount,verbose,del:"${croot}/${imagename}" aufs / 2>/dev/null
 }
 
-image="${1}"
-imagename=$(basename "${image}")
-croot=""
+# ############################################################## &cs ###
+# :::::::::::::::::::::::::::::::::::::::::::::::: Subroutines begin :::
 
-mount_image "$image"
+# insert the module into root aufs
+insert_module ()
+{
+  mount_image "$image"
+}
 
-exit 0
-set -x
+# remove the module from root aufs
+remove_module ()
+{
+
+  set -x
 
-# Try to simply remove the dir first. If succeeds, finish
-rmdir "${croot}/${imagename}" 2>/dev/null && exit 0
-# OK the previous trick didn't work. So we have a real module here.
+  # Try to simply remove the dir first. If succeeds, finish
+  rmdir "${croot}/${imagename}" 2>/dev/null && exit 0
+  # OK the previous trick didn't work. So we have a real module here.
 
-# First, try to stop all daemons which may be started by this module
-#find_n_run_scripts ${croot}/${imagename} stop deactivate
+  # First, try to stop all daemons which may be started by this module
+  #find_n_run_scripts ${croot}/${imagename} stop deactivate
 
-# detach it from aufs union. This may take a long time, remounting the
-# root directory is an expensive operation.
-try_remount
+  # detach it from aufs union. This may take a long time, remounting the
+  # root directory is an expensive operation.
+  try_remount
 
 
-# if we are here, the module has been successfuly removed from aufs union
-# so now we have to umount the lzm file and then free the loop device
-LOOP=$(cat /proc/mounts | grep "${croot}/${imagename} " | cut -d " " -f 1)
-umount -n "${croot}/${imagename}" 2>/dev/null
-if [ $? -ne 0 ]; then
-   exit 4
-fi
-losetup -d "$LOOP" 2>/dev/null # sometimes it's freed by umount automatically
-rmdir "${croot}/${imagename}" # if not empty or busy, a message will be shown
+  # if we are here, the module has been successfuly removed from aufs union
+  # so now we have to umount the lzm file and then free the loop device
+  LOOP=$(cat /proc/mounts | grep "${croot}/${imagename} " | cut -d " " -f 1)
+  umount -n "${croot}/${imagename}" 2>/dev/null
+  if [ $? -ne 0 ]; then
+    exit 4
+  fi
+  losetup -d "$LOOP" 2>/dev/null # sometimes it's freed by umount automatically
+  rmdir "${croot}/${imagename}" # if not empty or busy, a message will be shown
+}
+
+# ############################################################## &cs ###
+# :::::::::::::::::::::::::::::::::::::::::::::::: Main script begin :::
+
+# == Main dispatch
+
+image="${1}"
+imagename=$(basename "${image}")
+croot=""
+
+
+exit 0
+
-- 
1.5.6.5

----------
assignedto: mika
messages: 2035, 2036, 2045, 2046, 2047, 2048, 2049, 2398, 2839, 2840, 2841
nosy: mika, suntong
priority: feature
status: need-eg
title: live-module revision 1.3

_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue650>
_____________________________________


More information about the Bugs-changes mailing list