[issue650] live-module revision 1.8
Tong Sun
bts at bts.grml.org
Fri Jan 15 21:13:17 CET 2010
Tong Sun <suntong at cpan.org> added the comment:
- add and utilize functions prog_info, prog_warning & prog_abort
- add support functions echoyellow & echored
---
bin/live-module | 75 ++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 53 insertions(+), 22 deletions(-)
diff --git a/bin/live-module b/bin/live-module
index 7eb5501..f614d74 100755
--- a/bin/live-module
+++ b/bin/live-module
@@ -30,30 +30,61 @@ debug_log()
}
# echogreen will echo $@ in green color
-# $1 = text
-#
echogreen()
{
- echo -ne "[0;32m""$@""[0;39m"
+ echo -ne "\033[1;32m""$@""\033[0;39m"
}
-# echolog
-# $1 = text to show and to write to /var/log/messages
-#
-echolog()
+# echoyellow will echo $@ in yellow color
+echoyellow()
+{
+ echo -ne "\033[1;33m""$@""\033[0;39m"
+}
+
+# echored will echo $@ in red color
+echored()
+{
+ echo -ne "\033[1;31m""$@""\033[0;39m"
+}
+
+# prog_info
+# $@ = text to show and to write to /var/log/messages
+prog_info()
{
- if [ "$1" != "" ]; then
+ if [ ${1:+T} ]; then
echogreen "* "
log "LIVECD:" "$@"
echo "$@"
fi
}
+# prog_warning
+# $@ = text to show and to write to /var/log/messages
+prog_warning()
+{
+ if [ ${1:+T} ]; then
+ echoyellow "! "
+ log "LIVECD:" "$@"
+ echo "$@"
+ fi
+}
+
+# prog_abort
+# $@ = text to show and to write to /var/log/messages
+prog_abort()
+{
+ if [ ${1:+T} ]; then
+ echored "x "
+ log "LIVECD:" "$@"
+ echo "$@"
+ fi
+}
+
# test if the script is started by root user. If not, exit
allow_only_root()
{
if [ "0$UID" -ne 0 ]; then
- echo "Only root can run $(basename $0)"; exit 1
+ prog_abort "Only root can run $(basename $0)"; exit 1
fi
}
@@ -67,7 +98,7 @@ union_insert_dir()
{
debug_log "union_insert_dir $*"
mount -n -o remount,add:1:$2=rr aufs $1
- if [ $? -ne 0 ]; then echo "can't insert module to union" >&2; return 2; fi
+ if [ $? -ne 0 ]; then prog_abort "Can't insert module to union" >&2; return 2; fi
}
mount_image ()
@@ -84,18 +115,17 @@ mount_image ()
if [ "${fstype}" = "unknown" ]
then
- panic "Unknown file system type on ${backdev} (${image})"
+ prog_abort "Unknown file system type on ${backdev} (${image})"; exit 3
fi
mkdir -p "${croot}/${imagename}"
- log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
+ prog_info "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
mount -n -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
- log_end_msg
union_insert_dir / "${croot}/${imagename}"
if [ $? -ne 0 ]; then
- echo "error inserting module to live filesystem" >&2; exit 3;
+ prog_abort "Error inserting module to live filesystem" >&2; exit 3;
fi
}
@@ -126,7 +156,7 @@ Options:
# -V, --version Show version information and exit
parameter_error() {
- echo "Try 'live-module --help' for more information."
+ prog_warning "Try 'live-module --help' for more information."
exit 1
}
@@ -204,7 +234,7 @@ while :; do
shift; break
;;
*)
- echo "Internal getopt error!" ; exit 1
+ prog_abort "Internal getopt error!" ; exit 1
;;
esac
shift
@@ -216,27 +246,27 @@ done
}
[ ${1:+T} ] || {
- echo "Missing the module file specification."
+ prog_warning "Missing the module file specification."
parameter_error
}
# ############################################################## &cs ###
# :::::::::::::::::::::::::::::::::::::::::::::::: Main script begin :::
-allow_only_root
-
# are we even using aufs union?
if [ "$(grep '^aufs / ' /proc/mounts)" = "" ]; then
- echo "not in the live mode, can't continue."
+ prog_abort "Not in the live mode, can't continue."
exit 4
fi
+allow_only_root
+
image="${1}"
imagename=$(basename "${image}")
croot=""
[ -e "$image" ] || {
- echo "The specified module file '$image' does not exist."
+ prog_abort "The specified module file '$image' does not exist."
exit 4
}
@@ -253,10 +283,11 @@ if [ "$_opt_plug" ]; then
elif [ "$_opt_pull" ]; then
remove_module
else
- echo "Missing the operation."
+ prog_abort "Missing the operation."
parameter_error
fi
+prog_info "Done."
exit 0
# ============================================================== &ss ===
--
1.5.6.5
----------
assignedto: mika
messages: 2035, 2036, 2045, 2046, 2047, 2048, 2049, 2398, 2839, 2840, 2841, 2842, 2843, 2844, 2845, 2846
nosy: mika, suntong
priority: feature
status: need-eg
title: live-module revision 1.8
_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue650>
_____________________________________
More information about the Bugs-changes
mailing list