#!/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 "> 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