<commit_before>#!/bin/sh

# the following is the LSB init header
#
### BEGIN INIT INFO
# Provides: libvirt-guests
# Required-Start: libvirtd
# Required-Stop: libvirtd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: suspend/resume libvirt guests on shutdown/boot
# Description: This is a script for suspending active libvirt guests
#              on shutdown and resuming them on next boot
#              See http://libvirt.org
### END INIT INFO

# the following is chkconfig init header
#
# libvirt-guests:   suspend/resume libvirt guests on shutdown/boot
#
# chkconfig: 345 99 01
# description:  This is a script for suspending active libvirt guests \
#               on shutdown and resuming them on next boot \
#               See http://libvirt.org
#

sysconfdir="@sysconfdir@"
localstatedir="@localstatedir@"
libvirtd="@sbindir@"/libvirtd

# Source function library.
test ! -r "$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
ON_BOOT=start
ON_SHUTDOWN=suspend
SHUTDOWN_TIMEOUT=0

test -f "$sysconfdir"/sysconfig/libvirt-guests &&
    . "$sysconfdir"/sysconfig/libvirt-guests

LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests

RETVAL=0

retval() {
    "$@"
    if [ $? -ne 0 ]; then
        RETVAL=1
        return 1
    else
        return 0
    fi
}

run_virsh() {
    uri=$1
    shift

    if [ "x$uri" = xdefault ]; then
        conn=
    else
        conn="-c $uri"
    fi

    virsh $conn "$@" </dev/null
}

run_virsh_c() {
    ( export LC_ALL=C; run_virsh "$@" )
}

list_guests() {
    uri=$1

    list=$(run_virsh_c $uri list)
    if [ $? -ne 0 ]; then
        RETVAL=1
        return 1
    fi

    uuids=
    for id in $(echo "$list" | awk 'NR > 2 {print $1}'); do
        uuid=$(run_virsh_c $uri dominfo $id | awk '/^UUID:/{print $2}')
        if [ -z "$uuid" ]; then
            RETVAL=1
            return 1
        fi
        uuids="$uuids $uuid"
    done

    echo $uuids
}

guest_name() {
    uri=$1
    uuid=$2

    name=$(run_virsh_c $uri dominfo $uuid 2>/dev/null | \
           awk '/^Name:/{print $2}')
    [ -n "$name" ] || name=$uuid

    echo "$name"
}

guest_is_on() {
    uri=$1
    uuid=$2

    guest_running=false
    info=$(run_virsh_c $uri dominfo $uuid)<commit_msg>libvirt-guest.init: handle domain name with spaces<commit_after>#!/bin/sh

# the following is the LSB init header
#
### BEGIN INIT INFO
# Provides: libvirt-guests
# Required-Start: libvirtd
# Required-Stop: libvirtd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: suspend/resume libvirt guests on shutdown/boot
# Description: This is a script for suspending active libvirt guests
#              on shutdown and resuming them on next boot
#              See http://libvirt.org
### END INIT INFO

# the following is chkconfig init header
#
# libvirt-guests:   suspend/resume libvirt guests on shutdown/boot
#
# chkconfig: 345 99 01
# description:  This is a script for suspending active libvirt guests \
#               on shutdown and resuming them on next boot \
#               See http://libvirt.org
#

sysconfdir="@sysconfdir@"
localstatedir="@localstatedir@"
libvirtd="@sbindir@"/libvirtd

# Source function library.
test ! -r "$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
ON_BOOT=start
ON_SHUTDOWN=suspend
SHUTDOWN_TIMEOUT=0

test -f "$sysconfdir"/sysconfig/libvirt-guests &&
    . "$sysconfdir"/sysconfig/libvirt-guests

LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests

RETVAL=0

retval() {
    "$@"
    if [ $? -ne 0 ]; then
        RETVAL=1
        return 1
    else
        return 0
    fi
}

run_virsh() {
    uri=$1
    shift

    if [ "x$uri" = xdefault ]; then
        conn=
    else
        conn="-c $uri"
    fi

    virsh $conn "$@" </dev/null
}

run_virsh_c() {
    ( export LC_ALL=C; run_virsh "$@" )
}

list_guests() {
    uri=$1

    list=$(run_virsh_c $uri list)
    if [ $? -ne 0 ]; then
        RETVAL=1
        return 1
    fi

    uuids=
    for id in $(echo "$list" | awk 'NR > 2 {print $1}'); do
        uuid=$(run_virsh_c $uri dominfo $id | awk '/^UUID:/{print $2}')
        if [ -z "$uuid" ]; then
            RETVAL=1
            return 1
        fi
        uuids="$uuids $uuid"
    done

    echo $uuids
}

guest_name() {
    uri=$1
    uuid=$2

    name=$(run_virsh_c $uri dominfo $uuid 2>/dev/null | \
           sed -ne 's/^Name: *//p')
    [ -n "$name" ] || name=$uuid

    echo "$name"
}

guest_is_on() {
    uri=$1
    uuid=$2

    guest_running=false
    info=$(run_virsh_c $uri dominfo $uuid)
{'fraction_non_alphanumeric': 0.13337273443656422, 'fraction_numerical': 0.013987391646966114, 'mean_word_length': 2.6551475881929445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6317578', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1783, 'n_words': 463}