[issue650] live-module revision 1.4
Tong Sun
bts at bts.grml.org
Fri Jan 15 21:12:47 CET 2010
Tong Sun <suntong at cpan.org> added the comment:
- add grml code header
- add function usage()
- add function parameter_error()
- add command line parameters handling
- add main dispatch
- command line parameters handling tested fine
---
bin/live-module | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 94 insertions(+), 7 deletions(-)
diff --git a/bin/live-module b/bin/live-module
index c8d9dc6..0564bf3 100755
--- a/bin/live-module
+++ b/bin/live-module
@@ -1,9 +1,18 @@
#!/bin/sh
+# Filename: live-module
+# Purpose: Insert/remove live modules into root aufs
+# Authors:
+# Initially ported from Slax to Debian by
+# Tong Sun <http://xpt.sourceforge.net/>
+# Original Slax Author:
+# Tomas M. <http://www.linux-live.org>
+# License: This file is licensed under the GPL.
+################################################################################
. /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
+# FIXME: move the functions from above line and the followings into a separated lib file
# Insert a directory tree $2 to an union specified by $1
# Top-level read-write branch is specified by it's index 0
@@ -52,15 +61,36 @@ try_remount()
# ############################################################## &cs ###
# :::::::::::::::::::::::::::::::::::::::::::::::: Subroutines begin :::
+usage() {
+ echo "
+live-module - insert/remove live modules into root aufs
+
+Usage: live-module [options] module
+
+Options:
+
+ -i, --ins insert the module into root aufs
+ -r, --rem remove the module from root aufs
+ -p, --plug plug-in the module (synonym for insert)
+ -u, --pull pull-out the module (synonym for remove)
+
+ -h, --help Print usage information and exit
+ -V, --version Show version information and exit
+"
+}
+
+parameter_error() {
+ echo "Try 'live-module --help' for more information."
+ exit 1
+}
+
# insert the module into root aufs
-insert_module ()
-{
+insert_module() {
mount_image "$image"
}
# remove the module from root aufs
-remove_module ()
-{
+remove_module() {
set -x
@@ -68,6 +98,7 @@ remove_module ()
rmdir "${croot}/${imagename}" 2>/dev/null && exit 0
# OK the previous trick didn't work. So we have a real module here.
+ # FIXME: port this after bug 506591 has been fixed: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=506591
# First, try to stop all daemons which may be started by this module
#find_n_run_scripts ${croot}/${imagename} stop deactivate
@@ -87,15 +118,71 @@ remove_module ()
rmdir "${croot}/${imagename}" # if not empty or busy, a message will be shown
}
+# ============================================================ &pclp ===
+# .................................. process command line parameters ...
+
+_opt_temp=`getopt --name live-module -o +irpuhV --long \
+ ins,rem,plug,pull,help,version \
+ -- "$@"`
+if [ $? != 0 ]; then
+ parameter_error
+fi
+eval set -- "$_opt_temp"
+
+while :; do
+ case "$1" in
+
+ # == Options
+ --ins|-i|--plug|-p) # insert the module into root aufs
+ _opt_plug=T
+ ;;
+ --rem|-r|--pull|-u) # remove the module from root aufs
+ _opt_pull=T
+ ;;
+ #
+ --help|-h) # Print usage information and exit
+ _opt_help=T
+ ;;
+ --version|-V) # Show version information and exit
+ _opt_version=T
+ ;;
+ --)
+ shift; break
+ ;;
+ *)
+ echo "Internal getopt error!" ; exit 1
+ ;;
+ esac
+ shift
+done
+
+[ "$_opt_help" ] && {
+ usage
+ exit 0
+}
+
+[ ${1:+T} ] || {
+ echo "Missing the module file specification."
+ parameter_error
+}
+
# ############################################################## &cs ###
# :::::::::::::::::::::::::::::::::::::::::::::::: Main script begin :::
-# == Main dispatch
-
image="${1}"
imagename=$(basename "${image}")
croot=""
+# == Main dispatch
+
+if [ "$_opt_plug" ]; then
+ insert_module
+elif [ "$_opt_pull" ]; then
+ remove_module
+else
+ echo "Missing the operation."
+ parameter_error
+fi
exit 0
--
1.5.6.5
----------
assignedto: mika
messages: 2035, 2036, 2045, 2046, 2047, 2048, 2049, 2398, 2839, 2840, 2841, 2842
nosy: mika, suntong
priority: feature
status: need-eg
title: live-module revision 1.4
_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue650>
_____________________________________
More information about the Bugs-changes
mailing list