Re: Remove bashisms from libvirt-guests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le lundi 03 janvier 2011 22:35:48, Eric Blake a écrit :
> On 12/25/2010 12:44 PM, Laurent Léonard wrote:
> > Le lundi 20 décembre 2010 17:01:14, Eric Blake a écrit :
> >> On 12/18/2010 04:51 AM, Laurent Léonard wrote:
> >>>>> -    retval wait $virsh_pid && printf '\r%s%-12s\n' "$label" $"done"
> >>>>> +    retval wait $virsh_pid && printf '\r%s%-12s\n' "$label"
> >>>>> "`gettext \"done\"`"
> >>>> 
> >>>> Likewise: "$(gettext "done")"
> >>>> 
> >>>> But thanks for taking this on; we're getting closer to a nice
> >>>> solution.
> >>> 
> >>> I followed:
> >>> http://www.gnu.org/software/hello/manual/gettext/Preparing-Shell-Script
> >>> s. html but totally agree with your comments.
> >> 
> >> The gettext manual assumes that you are trying to be portable to all
> >> sorts of /bin/sh, including Solaris's horribly-dated version that lacks
> >> lots of POSIX features, hence it uses `` instead of $().  But for a
> >> Linux init script, we can safely assume a decent POSIX shell.
> > 
> > Any news about fixing those bashisms ?
> 
> I'm in favor of the ideas, but the patch isn't quite polished yet.  I've
> been a bit short on time to clean the patch up myself, and was hoping
> you would be willing to submit another version based on my comments from
> the previous round.  But given the current goal of releasing 0.8.7 in
> the very near future, I'm afraid this has missed the release deadline
> and you will have to maintain it as a backport for another release cycle.

The attached patch should match with your comments.

Thank you,
-- 
Laurent Léonard
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3d7bc8b..9d9a86f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -118,4 +118,5 @@ src/xen/xs_internal.c
 src/xenapi/xenapi_driver.c
 src/xenapi/xenapi_utils.c
 tools/console.c
+tools/libvirt-guests.init.in
 tools/virsh.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 271c11b..de5f662 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -146,6 +146,9 @@ BUILT_SOURCES += libvirt-guests.init
 
 libvirt-guests.init: libvirt-guests.init.in $(top_builddir)/config.status
 	$(AM_V_GEN)sed					\
+	    -e s!\@PACKAGE\@!@PACKAGE@!g		\
+	    -e s!\@bindir\@!@bindir@!g			\
+	    -e s!\@localedir\@!@localedir@!g		\
 	    -e s!\@localstatedir\@!@localstatedir@!g	\
 	    -e s!\@sbindir\@!@sbindir@!g		\
 	    -e s!\@sysconfdir\@!@sysconfdir@!g		\
diff --git a/tools/libvirt-guests.init.in b/tools/libvirt-guests.init.in
index e28938d..ea404b7 100644
--- a/tools/libvirt-guests.init.in
+++ b/tools/libvirt-guests.init.in
@@ -32,6 +32,13 @@ libvirtd=@sbindir@/libvirtd
 test ! -r "$sysconfdir"/rc.d/init.d/functions ||
   . "$sysconfdir"/rc.d/init.d/functions
 
+. @bindir@/gettext.sh
+
+TEXTDOMAIN=@PACKAGE@
+export TEXTDOMAIN
+TEXTDOMAINDIR=@localedir@
+export TEXTDOMAINDIR
+
 URIS=default
 ON_BOOT=start
 ON_SHUTDOWN=suspend
@@ -129,7 +136,7 @@ start() {
     [ -f "$LISTFILE" ] || { started; return 0; }
 
     if [ "x$ON_BOOT" != xstart ]; then
-        echo $"libvirt-guests is configured not to start any guests on boot"
+        gettext "libvirt-guests is configured not to start any guests on boot"; echo
         rm -f "$LISTFILE"
         started
         return 0
@@ -144,20 +151,20 @@ start() {
             fi
         done
         if ! $configured; then
-            echo $"Ignoring guests on $uri URI"
+            eval_gettext "Ignoring guests on \$uri URI"; echo
             continue
         fi
 
-        echo $"Resuming guests on $uri URI..."
+        eval_gettext "Resuming guests on \$uri URI..."; echo
         for guest in $list; do
             name=$(guest_name $uri $guest)
-            echo -n $"Resuming guest $name: "
+            eval_gettext "Resuming guest \$name: "
             if guest_is_on $uri $guest; then
                 if $guest_running; then
-                    echo $"already active"
+                    gettext "already active"; echo
                 else
                     retval run_virsh $uri start "$name" >/dev/null && \
-                    echo $"done"
+                    gettext "done"; echo
                 fi
             fi
         done
@@ -173,7 +180,7 @@ suspend_guest()
     guest=$2
 
     name=$(guest_name $uri $guest)
-    label=$"Suspending $name: "
+    label=$(eval_gettext "Suspending \$name: ")
     echo -n "$label"
     run_virsh $uri managedsave $guest >/dev/null &
     virsh_pid=$!
@@ -188,7 +195,7 @@ suspend_guest()
             printf '\r%s%-12s ' "$label" "..."
         fi
     done
-    retval wait $virsh_pid && printf '\r%s%-12s\n' "$label" $"done"
+    retval wait $virsh_pid && printf '\r%s%-12s\n' "$label" "$(gettext "done")"
 }
 
 shutdown_guest()
@@ -197,13 +204,13 @@ shutdown_guest()
     guest=$2
 
     name=$(guest_name $uri $guest)
-    label=$"Shutting down $name: "
+    label=$(eval_gettext "Shutting down \$name: ")
     echo -n "$label"
     retval run_virsh $uri shutdown $guest >/dev/null || return
     timeout=$SHUTDOWN_TIMEOUT
     while [ $timeout -gt 0 ]; do
         sleep 1
-        timeout=$[timeout - 1]
+        timeout=$((timeout - 1))
         guest_is_on $uri $guest || return
         $guest_running || break
         printf '\r%s%-12d ' "$label" $timeout
@@ -211,9 +218,9 @@ shutdown_guest()
 
     if guest_is_on $uri $guest; then
         if $guest_running; then
-            printf '\r%s%-12s\n' "$label" $"failed to shutdown in time"
+            printf '\r%s%-12s\n' "$label" "$(gettext "failed to shutdown in time")"
         else
-            printf '\r%s%-12s\n' "$label" $"done"
+            printf '\r%s%-12s\n' "$label" "$(gettext "done")"
         fi
     fi
 }
@@ -226,7 +233,7 @@ stop() {
     if [ "x$ON_SHUTDOWN" = xshutdown ]; then
         suspending=false
         if [ $SHUTDOWN_TIMEOUT -le 0 ]; then
-            echo $"Shutdown action requested but SHUTDOWN_TIMEOUT was not set"
+            gettext "Shutdown action requested but SHUTDOWN_TIMEOUT was not set"; echo
             RETVAL=6
             return
         fi
@@ -234,10 +241,10 @@ stop() {
 
     : >"$LISTFILE"
     for uri in $URIS; do
-        echo -n $"Running guests on $uri URI: "
+        eval_gettext "Running guests on \$uri URI: "
 
         if [ "x$uri" = xdefault ] && [ ! -x "$libvirtd" ]; then
-            echo $"libvirtd not installed; skipping this URI."
+            gettext "libvirtd not installed; skipping this URI."; echo
             continue
         fi
 
@@ -250,7 +257,7 @@ stop() {
                 empty=false
             done
             if $empty; then
-                echo $"no running guests."
+                gettext "no running guests."; echo
             else
                 echo
                 echo $uri $list >>"$LISTFILE"
@@ -260,9 +267,9 @@ stop() {
 
     while read uri list; do
         if $suspending; then
-            echo $"Suspending guests on $uri URI..."
+            eval_gettext "Suspending guests on \$uri URI..."; echo
         else
-            echo $"Shutting down guests on $uri URI..."
+            eval_gettext "Shutting down guests on \$uri URI..."; echo
         fi
 
         for guest in $list; do
@@ -290,13 +297,13 @@ gueststatus() {
 # since there is no external daemon process matching this init script.
 rh_status() {
     if [ -f "$LISTFILE" ]; then
-        echo $"stopped, with saved guests"
+        gettext "stopped, with saved guests"; echo
         RETVAL=3
     else
         if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then
-            echo $"started"
+            gettext "started"; echo
         else
-            echo $"stopped, with no saved guests"
+            gettext "stopped, with no saved guests"; echo
         fi
         RETVAL=0
     fi
@@ -305,7 +312,8 @@ rh_status() {
 # usage [val]
 # Display usage string, then exit with VAL (defaults to 2).
 usage() {
-    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"
+    program_name=$0
+    eval_gettext "Usage: \$program_name {start|stop|status|restart|condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"; echo
     exit ${1-2}
 }
 
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]