summaryrefslogtreecommitdiffstats
path: root/distribution/virt/import/filetopty.sh
blob: 49473efcf3d1ce0c9ff2bcbcfc002e2e808135b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh

if [[ $# != 1 ]]; then 
	echo "Usage: $0 [guestname] "
	exit 1
fi

# if the guest isn't shutdown, shut it down.. try at least 2 times
guestup=0
i=0
while (( $i < 2 )) ; 
do 
	if virsh list | grep -w $1; then 
		guestup=1
		if ! virsh shutdown $1 ; then
			echo "problem with virsh shutdown $1"
			exit 1
		fi
		sleep 90
	fi
	let "i=${i}+1"	
done
		
if virsh list | grep -w $1; then 
	echo "the guest can't be brought down"
	exit 1
fi

if ! virsh dumpxml $1 > $1.xml ; then 
	echo "problem with virsh dumpxml $1"
	exit 1
fi

sed -n '
# if the first line copy the pattern to the hold buffer
1h
# if not the first line then append the pattern to the hold buffer
1!H
# if the last line then ...
$ {
        # copy from the hold to the pattern buffer
        g
        # do the search and replace
#    <serial type='pty'>
#      <target port='0'/>
#    </serial>
#    <console type='pty'>
#      <target port='0'/>
#    </console>
#
        s/<serial type='\''file'\''>.*<\/console>/<serial type='\''pty'\''>\
      <target port='\''0'\''\/>\
    <\/serial>\
    <console type='\''pty'\''>\
      <target port='\''0'\''\/>\
    <\/console>/g
        # print
        p
}
' $1.xml > $1.xml.tmp ;

#redefine the guest with the edited xml
if ! virsh define ./$1.xml.tmp; then 
	echo "problem with virsh define ./$1.xml.tmp"
	exit 1
fi

if [[ ${guestup} == 1 ]]; then 
	if ! virsh start $1; then 
		echo "problem restarting guest $1 "
		exit 1
	fi
	# give it some time to start up.
	sleep 90

	if ! virsh list | grep -w $1 ; then 
		echo "guest doesn't seem to be up after restart"
		exit 1
	fi
fi