-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxml_lib.inc
73 lines (68 loc) · 1.59 KB
/
xml_lib.inc
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
# XML_CMD=xml
XML_CMD=xmlstarlet
function setDisk() {
local ID=$1
local V=$2
if [ -z "$WTMP" ]; then
echo "WTMP not set"
exit -1
fi
# -P (or --pf) - preserve original formatting
# -S (or --ps) - preserve non-significant spaces
# -L (or --inplace) - edit file inplace
# -u "/domain/devices/disk[$ID]/source/@file" -v "$V" \
$XML_CMD ed -L \
-d "/domain/devices/disk[$ID]/source" \
-s "/domain/devices/disk[$ID]" -t elem --name source -v "" \
-i "/domain/devices/disk[$ID]/source" -t attr -name file -v "$V" \
$WTMP
echo "Setting disk #$ID to '$V'"
}
function setBoot() {
local V=$1
if [ -z "$WTMP" ]; then
echo "WTMP not set"
exit -1
fi
$XML_CMD ed -L \
-d "/domain/os/boot" \
-s "/domain/os" -t elem --name boot -v "" \
-i "/domain/os/boot" -t attr -name dev -v "$V" \
$WTMP
}
function updElVal() {
local P=$1
local V=$2
if [ -z "$WTMP" ]; then
echo "WTMP not set"
exit -1
fi
$XML_CMD ed -L \
-u "$P" -v "$V" \
$WTMP
echo "Update '$P' to '$V'"
}
function delEl() {
local P=$1
if [ -z "$WTMP" ]; then
echo "WTMP not set"
exit -1
fi
$XML_CMD ed -L \
-d "$P" \
$WTMP
echo "Remove '$P'"
}
function setElVal() {
local P=$1
local N=$2
local V=$3
if [ -z "$WTMP" ]; then
echo "WTMP not set"
exit -1
fi
$XML_CMD ed -L \
-s "$P" -t elem -n "$N" -v "$V" \
$WTMP
echo "Update '$P/$N' to '$V'"
}