提交 a9e31a47 编写于 作者: L Laurent Léonard 提交者: Eric Blake

libvirt-guests: remove bashisms

* tools/libvirt-guests.init.sh: Use only POSIX shell features, which
includes using gettext.sh for translation rather than $"".
* tools/Makefile.am (libvirt-guests.init): Supply a few more substitutions.
* po/POTFILES.in: Mark that libvirt-guests.init needs translation.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 8ea5bcca
...@@ -118,4 +118,5 @@ src/xen/xs_internal.c ...@@ -118,4 +118,5 @@ src/xen/xs_internal.c
src/xenapi/xenapi_driver.c src/xenapi/xenapi_driver.c
src/xenapi/xenapi_utils.c src/xenapi/xenapi_utils.c
tools/console.c tools/console.c
tools/libvirt-guests.init.in
tools/virsh.c tools/virsh.c
...@@ -146,9 +146,12 @@ BUILT_SOURCES += libvirt-guests.init ...@@ -146,9 +146,12 @@ BUILT_SOURCES += libvirt-guests.init
libvirt-guests.init: libvirt-guests.init.in $(top_builddir)/config.status libvirt-guests.init: libvirt-guests.init.in $(top_builddir)/config.status
$(AM_V_GEN)sed \ $(AM_V_GEN)sed \
-e s!\@localstatedir\@!@localstatedir@!g \ -e 's!\@PACKAGE\@!$(PACKAGE)!g' \
-e s!\@sbindir\@!@sbindir@!g \ -e 's!\@bindir\@!$(bindir)!g' \
-e s!\@sysconfdir\@!@sysconfdir@!g \ -e 's!\@localedir\@!$(localedir)!g' \
-e 's!\@localstatedir\@!$(localstatedir)!g' \
-e 's!\@sbindir\@!$(sbindir)!g' \
-e 's!\@sysconfdir\@!$(sysconfdir)!g' \
< $< > $@-t && \ < $< > $@-t && \
chmod a+x $@-t && \ chmod a+x $@-t && \
mv $@-t $@ mv $@-t $@
......
...@@ -24,20 +24,27 @@ ...@@ -24,20 +24,27 @@
# See http://libvirt.org # See http://libvirt.org
# #
sysconfdir=@sysconfdir@ sysconfdir="@sysconfdir@"
localstatedir=@localstatedir@ localstatedir="@localstatedir@"
libvirtd=@sbindir@/libvirtd libvirtd="@sbindir@"/libvirtd
# Source function library. # Source function library.
test ! -r "$sysconfdir"/rc.d/init.d/functions || test ! -r "$sysconfdir"/rc.d/init.d/functions ||
. "$sysconfdir"/rc.d/init.d/functions . "$sysconfdir"/rc.d/init.d/functions
# Source gettext library.
# Make sure this file is recognized as having translations: _("dummy")
. "@bindir@"/gettext.sh
export TEXTDOMAIN="@PACKAGE@" TEXTDOMAINDIR="@localedir@"
URIS=default URIS=default
ON_BOOT=start ON_BOOT=start
ON_SHUTDOWN=suspend ON_SHUTDOWN=suspend
SHUTDOWN_TIMEOUT=0 SHUTDOWN_TIMEOUT=0
test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests test -f "$sysconfdir"/sysconfig/libvirt-guests &&
. "$sysconfdir"/sysconfig/libvirt-guests
LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests
...@@ -129,7 +136,8 @@ start() { ...@@ -129,7 +136,8 @@ start() {
[ -f "$LISTFILE" ] || { started; return 0; } [ -f "$LISTFILE" ] || { started; return 0; }
if [ "x$ON_BOOT" != xstart ]; then 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" rm -f "$LISTFILE"
started started
return 0 return 0
...@@ -144,20 +152,20 @@ start() { ...@@ -144,20 +152,20 @@ start() {
fi fi
done done
if ! $configured; then if ! $configured; then
echo $"Ignoring guests on $uri URI" eval_gettext "Ignoring guests on \$uri URI"; echo
continue continue
fi fi
echo $"Resuming guests on $uri URI..." eval_gettext "Resuming guests on \$uri URI..."; echo
for guest in $list; do for guest in $list; do
name=$(guest_name $uri $guest) name=$(guest_name $uri $guest)
echo -n $"Resuming guest $name: " eval_gettext "Resuming guest \$name: "
if guest_is_on $uri $guest; then if guest_is_on $uri $guest; then
if $guest_running; then if $guest_running; then
echo $"already active" gettext "already active"; echo
else else
retval run_virsh $uri start "$name" >/dev/null && \ retval run_virsh $uri start "$name" >/dev/null && \
echo $"done" gettext "done"; echo
fi fi
fi fi
done done
...@@ -173,8 +181,8 @@ suspend_guest() ...@@ -173,8 +181,8 @@ suspend_guest()
guest=$2 guest=$2
name=$(guest_name $uri $guest) name=$(guest_name $uri $guest)
label=$"Suspending $name: " label=$(eval_gettext "Suspending \$name: ")
echo -n "$label" printf %s "$label"
run_virsh $uri managedsave $guest >/dev/null & run_virsh $uri managedsave $guest >/dev/null &
virsh_pid=$! virsh_pid=$!
while true; do while true; do
...@@ -188,7 +196,7 @@ suspend_guest() ...@@ -188,7 +196,7 @@ suspend_guest()
printf '\r%s%-12s ' "$label" "..." printf '\r%s%-12s ' "$label" "..."
fi fi
done 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() shutdown_guest()
...@@ -197,13 +205,13 @@ shutdown_guest() ...@@ -197,13 +205,13 @@ shutdown_guest()
guest=$2 guest=$2
name=$(guest_name $uri $guest) name=$(guest_name $uri $guest)
label=$"Shutting down $name: " label=$(eval_gettext "Shutting down \$name: ")
echo -n "$label" printf %s "$label"
retval run_virsh $uri shutdown $guest >/dev/null || return retval run_virsh $uri shutdown $guest >/dev/null || return
timeout=$SHUTDOWN_TIMEOUT timeout=$SHUTDOWN_TIMEOUT
while [ $timeout -gt 0 ]; do while [ $timeout -gt 0 ]; do
sleep 1 sleep 1
timeout=$[timeout - 1] timeout=$((timeout - 1))
guest_is_on $uri $guest || return guest_is_on $uri $guest || return
$guest_running || break $guest_running || break
printf '\r%s%-12d ' "$label" $timeout printf '\r%s%-12d ' "$label" $timeout
...@@ -211,9 +219,10 @@ shutdown_guest() ...@@ -211,9 +219,10 @@ shutdown_guest()
if guest_is_on $uri $guest; then if guest_is_on $uri $guest; then
if $guest_running; 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 else
printf '\r%s%-12s\n' "$label" $"done" printf '\r%s%-12s\n' "$label" "$(gettext "done")"
fi fi
fi fi
} }
...@@ -226,7 +235,8 @@ stop() { ...@@ -226,7 +235,8 @@ stop() {
if [ "x$ON_SHUTDOWN" = xshutdown ]; then if [ "x$ON_SHUTDOWN" = xshutdown ]; then
suspending=false suspending=false
if [ $SHUTDOWN_TIMEOUT -le 0 ]; then 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 RETVAL=6
return return
fi fi
...@@ -234,10 +244,10 @@ stop() { ...@@ -234,10 +244,10 @@ stop() {
: >"$LISTFILE" : >"$LISTFILE"
for uri in $URIS; do 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 if [ "x$uri" = xdefault ] && [ ! -x "$libvirtd" ]; then
echo $"libvirtd not installed; skipping this URI." gettext "libvirtd not installed; skipping this URI."; echo
continue continue
fi fi
...@@ -246,11 +256,11 @@ stop() { ...@@ -246,11 +256,11 @@ stop() {
empty=true empty=true
for uuid in $list; do for uuid in $list; do
$empty || printf ", " $empty || printf ", "
echo -n $(guest_name $uri $uuid) printf %s "$(guest_name $uri $uuid)"
empty=false empty=false
done done
if $empty; then if $empty; then
echo $"no running guests." gettext "no running guests."; echo
else else
echo echo
echo $uri $list >>"$LISTFILE" echo $uri $list >>"$LISTFILE"
...@@ -260,9 +270,9 @@ stop() { ...@@ -260,9 +270,9 @@ stop() {
while read uri list; do while read uri list; do
if $suspending; then if $suspending; then
echo $"Suspending guests on $uri URI..." eval_gettext "Suspending guests on \$uri URI..."; echo
else else
echo $"Shutting down guests on $uri URI..." eval_gettext "Shutting down guests on \$uri URI..."; echo
fi fi
for guest in $list; do for guest in $list; do
...@@ -290,13 +300,13 @@ gueststatus() { ...@@ -290,13 +300,13 @@ gueststatus() {
# since there is no external daemon process matching this init script. # since there is no external daemon process matching this init script.
rh_status() { rh_status() {
if [ -f "$LISTFILE" ]; then if [ -f "$LISTFILE" ]; then
echo $"stopped, with saved guests" gettext "stopped, with saved guests"; echo
RETVAL=3 RETVAL=3
else else
if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then
echo $"started" gettext "started"; echo
else else
echo $"stopped, with no saved guests" gettext "stopped, with no saved guests"; echo
fi fi
RETVAL=0 RETVAL=0
fi fi
...@@ -305,7 +315,9 @@ rh_status() { ...@@ -305,7 +315,9 @@ rh_status() {
# usage [val] # usage [val]
# Display usage string, then exit with VAL (defaults to 2). # Display usage string, then exit with VAL (defaults to 2).
usage() { 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} exit ${1-2}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册