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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
#!/bin/bash
################################################################################
## Creates vmware and vbox (script creation for vbox is not implented yet)
## runscripts from xmlfiles.
## Use template file runvmware-v2 for executeables
##
##
## Structure:
## ${vmdir}/$image.xml configurationfile
## ${vmdir}/$image.vmdk vmware image file
## ${vmdir}/$image.vbox vbox image file
## ${vmdir}/runscripts/$pool/*.vmware vmware runscript
## ${vmdir}/runscripts/$pool/*.vbox virtualbox runscript
## ${vmdir}/xdialog-files/$pool/*.xdialog xdialog menu entrys
## ${vmdir}/xdmsession/$pool/*.desktop .desktop files for xdm,
## if xdm = true in xml
## ${vmdir}/templates/runvmware-v2 image exec template script
################################################################################
#TODO: check first if this xml file should be used, if not jump out of the
# while loop. reducee checks and resources
# Just needed if vmdir is somewhere else
vmdir="." && cd ${vmdir}
# were is vmdir, after we mountet this folder?
vmexecdir="/var/lib/vmware"
# template for runvmware
templatevmware="${vmdir}/templates/runvmware-v2"
# delete all priority files
rm -rf ${vmdir}/xdialog-files/${i}/[0-9]_*.vmware
# Take all xml files and work with them
for xml in *.xml;do
# converts the XML file to utf-8, whyever we need that
# inefficient here, because we don't need utf-8 for every xml file
# but most secure place. Else the structure gets screwed.
#TODO: perhaps we can kick out the whole UTF-8 shit, if the admins
# are not able to give us the correct format, we shouldnt fix it
iconv -c -f utf-8 -t utf-8 < ${xml} > ${xml}.utf
##############################################################################
## get needed information from xml file and check them if needed
##############################################################################
# get image name
image=$(grep -i "<image_name param=\"" ${xml} | awk -F "\"" '{ print $2 }')
# Test if correct defined
image_type=$(echo ${image}|sed 's%.*\.%%')
if [ "${image_type}" != "vmdk" -a "${image_type}" != "vdi" ]; then
# TODO: Test
echo "PANIC, image is not correct defined in ${xml}."
echo "Image has to end with vdi or vmdk!"
fi
# Test if image is available
if [ ! -f ../${image} ]; then
echo "PANIC, image defined in ${xml} not available"
fi
# get information if the current image should be used
# active when active=1 image, else disabled
active=$(grep -i "<active param=\"true\"" ${xml} | wc -l)
#TODO: perhaps we should force an active flag, too
# get list where the current image should be used
pools=$(grep -i "<pools param=\"" ${xml} | awk -F "\"" '{ print $2 }')
# we need the pool configuration
if ! [ "${pools}" ]; then
echo "PANIC, pools not correct defined in ${xml}"
fi
# Virtualmachine (vmware or virtualbox)?
vm=$(grep -i "<virtualmachine param=\"" ${xml} | awk -F "\"" '{ print $2 }')
# Test if correct defined
if [ "${vm}" != "vbox" -a "${vm}" != "vmware" ]; then
echo "PANIC, virtualmachine not correct defined in ${xml}"
fi
# Test if vbox and wrong image
if [ "${vm}" = "vbox" -a "${image_type}" != "vdi" ]; then
# TODO: Test
echo "PANIC, virtualmachine vbox cant use image type defined in ${xml}"
fi
# Test if vmware and wrong image
if [ "${vm}" = "vmware" -a "${image_type}" != "vmdk" ]; then
# TODO: Test
echo "PANIC, virtualmachine vmware cant use image type defined in ${xml}"
fi
# Connectiontype of vm (nat or bridged)?
network=$(grep -i "<network param=\"" ${xml} | awk -F "\"" '{ print $2 }')
# Test if correct defined
if [ "${network}" != "nat" -a "${network}" != "bridged" ]; then
# TODO: test
echo "PANIC, network connection not correct defined in ${xml}"
fi
# os running in vmware?
os=$(grep -i "<os param=\"" ${xml} | awk -F "\"" '{ print $2 }')
if [ "${os}" != "Linux" -a "${os}" != "winxppro" -a "${os}" != "Windows 2000" ]; then
# TODO: test
echo "PANIC, OS in virtual machine not correct defined in ${xml}"
fi
# get short image description
short_description=$(grep "short_description param=\"" ${xml}.utf |
sed -e "s%&.*;%; %g" | awk -F "\"" '{print $2}')
# if ${short_description} not defined use ${image}
short_description=${short_description:-"${image}"}
# Get the long image description
long_description=$(grep "long_description param=\"" ${xml}.utf |
sed -e "s%&.*;%; %g" | awk -F "\"" '{print $2}')
# Informations if we need for XDM
xdm=$(grep "xdm param=\"" ${xml} | awk -F "\"" '{print $2}')
# Test if correct defined
if [ "${xdm}" != "true" -a "${xdm}" != "false" ]; then
# TODO: test
echo "PANIC, XDM usage not correct defined in ${xml}"
fi
# Get priority, use it for important Images in Xdialog
priority=$(grep "priority param=\"" ${xml} | awk -F "\"" '{print $2}')
##############################################################################
## main part,
##############################################################################
# Main part, creates desktopentrys and image run scripts
# TODO: Perhaps its better if we put runscripts, xdmsessions and
# xdialog-files in one big folder with subfolder runscripts,
# xdmsessions, xdialog-files
# check if ${vmdir}/runscripts/ is available
if [ ! -d ${vmdir}/runscripts ]; then
mkdir ${vmdir}/runscripts
fi
# check if ${vmdir}/xdmsessions/ for .desktop files is available
if [ ! -d ${vmdir}/xdmsessions ]; then
mkdir ${vmdir}/xdmsessions
fi
# check if ${vmdir}/xdmsessions/ for .desktop files is available
if [ ! -d ${vmdir}/xdialog-files ]; then
mkdir ${vmdir}/xdialog-files
fi
# work with the different pools and...
for i in ${pools}; do
# ... make sure we have the different pool directorys, else create it
if [ ! -d ${vmdir}/runscripts/${i} ]; then
mkdir -p ${vmdir}/runscripts/${i}
fi
if [ ! -d ${vmdir}/xdmsessions/${i} ]; then
mkdir -p ${vmdir}/xdmsessions/${i}
fi
if [ ! -d ${vmdir}/xdialog-files/${i} ]; then
mkdir -p ${vmdir}/xdialog-files/${i}
fi
# ... remove startscript, xdmsessions and Xdialog files if it isn't active.
if [ ${active} -ne 1 ]; then
if [ -f ${vmdir}/runscripts/*/${image}.vmware \
-o -f runscripts/*/${image}.virtualbox ]; then
rm -rf ${vmdir}/runscripts/*/${image}.*
rm -rf ${vmdir}/xdmsessions/*/${image}.desktop
rm -rf ${vmdir}/xdialog-files/*/${image}.xdialog
fi
fi
# ... create desktopentry
if [ ${active} -eq 1 -a ${xdm} = "true" ]; then
# create desktopentry
#echo -e "\nCreating xdm entry for ${image} and pool ${i}\n"
# create the desktopentry
#TODO: change it with < EOF, >> isnt nice for so much lines
echo "Desktop entry for ${image}" \
>> ${vmdir}/xdmsessions/${i}/${image}.desktop
echo "[Desktop Entry]" > ${vmdir}/xdmsessions/${i}/${image}.desktop
echo "X-SuSE-translate=true" \
>> ${vmdir}/xdmsessions/${i}/${image}.desktop
echo "Encoding=UTF-8" >> ${vmdir}/xdmsessions/${i}/${image}.desktop
echo "Type=XSession" >> ${vmdir}/xdmsessions/${i}/${image}.desktop
#TODO: Fix path
if [ "${vm}" = "vmware" ];then
echo "Exec=${vmexecdir}/runscripts/${i}/${image}.vmware" \
>> ${vmdir}/xdmsessions/${i}/${image}.desktop
else # it will be virtualbox
echo "Exec=${vmexecdir}/runscripts/${i}/${image}.virtualbox" \
>> ${vmdir}/xdmsessions/${i}/${image}.desktop
fi
echo "Name=${short_description}" \
>> ${vmdir}/xdmsessions/${i}/${image}.desktop
echo "Comment=${comment}" >> ${vmdir}/xdmsessions/${i}/${image}.desktop
#TODO: I dont like SLXGrp as variable herein, why we need it here?
#echo "SLXGrp=${pools}" >> ${vmdir}/xdmsessions/${i}/${image}.desktop
#TODO: do we need XDM configuration? -> Chemie pool
#echo "XDM=${xdm}" >> ${vmdir}/xdmsessions/${i}/${image}.desktop
fi
# If we have vmware, build executeable from template and
# Xdialog menu entrys
if [ "${vm}" = "vmware" -a "${active}" -eq 1 ]; then
# virtualmachine executable form template
sed -e "s/imagename=\"CHANGEIT\"/imagename=\"${image}\"/" \
-e "s%displayname=\"CHANGEIT\"%displayname=\"${short_description}\"%" \
-e "s/vmostype=\"CHANGEIT\"/vmostype=\"${os}\"/" \
-e "s/network=\"CHANGEIT\"/network=\"${network}\"/" \
${templatevmware} \
> ${vmdir}/runscripts/${i}/${image}.vmware
chmod 755 ${vmdir}/runscripts/${i}/${image}.vmware
# Xdialog menu entrys
echo -e "\"${vmexecdir}/runscripts/${i}/${image}.vmware\" \\
\"${short_description}\" \\
\"${long_description}\" \\" \
> ${vmdir}/xdialog-files/${i}/${image}.xdialog
# If we have a priority defined we rename the file
if [ ${priority} ]; then
mv ${vmdir}/xdialog-files/${i}/${image}.xdialog \
${vmdir}/xdialog-files/${i}/${priority}_${image}.xdialog
fi
# if we have virtualbox, part here can only be vbox cause check above
# TODO: i dont like this construction, fix it later
else
if [ "${active}" -eq 0 ];then
echo "${image} isnt enabled"
else
echo "Currently Virtualbox isn't implented"
fi
fi
done
done
# test if we still have this xml file, else we can delete the old entry
for i in xdmsessions/*/*.desktop; do
# get the name, cut all the folder information and file prefix off
name=$(echo ${i} |sed 's/.*\///' | sed 's/.vmdk.desktop//' | sed 's/.vbox.desktop//' | sed 's/^[0-9]_//')
# if not available as xml delete it
if [ ! -f ${name}.xml ]; then
echo "delete file ./${i}, no matching xml found"
rm -rf ${i}
fi
done
# test if we still have this xml file, else we can delete the old entry
for i in xdialog-files/*/*.xdialog; do
# get the name, cut all the folder information and file prefix off
name=$(echo ${i} |sed 's/.*\///' | sed 's/.vmdk.xdialog//' | sed 's/.vbox.xdialog//' | sed 's/^[0-9]_//')
# if not available as xml delete it
if [ ! -f ${name}.xml ]; then
echo "delete file ./${i}, no matching xml found"
rm -rf ${i}
fi
done
# Building Xdialog executable for each pool
for i in ${vmdir}/xdialog-files/*; do
cp ${vmdir}/templates/xdialog.sh ${i}
cat ${i}/*.xdialog >> ${i}/xdialog.sh
#closing bracket as last line invoked with \
echo ")" >> ${i}/xdialog.sh
chmod 755 ${i}/xdialog.sh
done
# Delete all .utf files, we dont need them anymore
rm -f *.xml.utf
|