Skip to content
Snippets Groups Projects
Commit 6e20975d authored by ulisse's avatar ulisse
Browse files

vbox2template working version

parent 54b73724
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,6 @@ usage_vm-setup () { ...@@ -48,6 +48,6 @@ usage_vm-setup () {
usage_vbox2template () { usage_vbox2template () {
echo >&2 "$@" echo >&2 "$@"
echo "Usage: $0 <vm.vbox>" echo "Usage: $0 <vm.vbox> <vm id>"
exit 1 exit 1
} }
This diff is collapsed.
File moved
This diff is collapsed.
This diff is collapsed.
...@@ -13,28 +13,44 @@ SRC_DIR="$(dirname $(readlink -f $0))" ...@@ -13,28 +13,44 @@ SRC_DIR="$(dirname $(readlink -f $0))"
#include common code #include common code
. ${SRC_DIR}/settings/common . ${SRC_DIR}/settings/common
[ "$#" -eq 1 ] || usage_vbox2template "Error: template file required." [ "$#" -eq 2 ] || usage_vbox2template "Error: missing arguments."
VM_ID=$1 IN_FILE=$1
VM_ID=$2
# include settings # include settings
. $SRC_DIR/settings/settings . $SRC_DIR/settings/settings
TPL_FILE="$1"-tpl.vbox # override settings variables
TMP_DIR="/var/tmp/vbox-user"
#IMG_HOME="/opt/test"
#SF_LINUX_TARGET="/home/target"
#SF_MEDIA_TARGET="/media/usb"
TPL_FILE=`basename -s .vbox ${IN_FILE}`-tpl.vbox
# prepare template # prepare template
cp "$1" "${TPL_FILE}" cp "$1" "${TPL_FILE}"
sed -i 's:\(Machine.*snapshotFolder="\)\([^"]*\)\("\):\1'"`echo "${TMP_DIR}"`"'\3:g' "${TPL_FILE}" # SharedFolder
sed -i 's:\(SharedFolder.*name="'"`echo "${SF_LINUX_NAME}"`"'".*hostPath="\)\([^"]*\)\("\):\1'"`echo "${SF_LINUX_TARGET}"`"'\3:g' "${TPL_FILE}" #sed -i 's:\(SharedFolder.*name="'"`echo "${SF_LINUX_NAME}"`"'".*hostPath="\)\([^"]*\)\("\):\1'"`echo "${SF_LINUX_TARGET}"`"'\3:g' "${TPL_FILE}"
sed -i 's:\(SharedFolder.*name="'"`echo "${SF_MEDIA_NAME}"`"'".*hostPath="\)\([^"]*\)\("\):\1'"`echo "${SF_MEDIA_TARGET}"`"'\3:g' "${TPL_FILE}" perl -pi -e 's:(SharedFolder.*name="'"`echo "${SF_LINUX_NAME}"`"'".*hostPath=")(.*?)("):$1'"`echo "${SF_LINUX_TARGET}"`"'$3:g' "${TPL_FILE}"
sed -i 's:\(MACAddress="\)\([^"]*\)\("\):\1'"`echo ""`"'\3:g' "${TPL_FILE}" #sed -i 's:\(SharedFolder.*name="'"`echo "${SF_MEDIA_NAME}"`"'".*hostPath="\)\([^"]*\)\("\):\1'"`echo "${SF_MEDIA_TARGET}"`"'\3:g' "${TPL_FILE}"
#perl -pi -e 's:\(stateFile="\)\(.*?/\)":\1'"`echo "${IMG_HOME}/"`"'\3:g' "${TPL_FILE}" perl -pi -e 's:(SharedFolder.*name="'"`echo "${SF_MEDIA_NAME}"`"'".*hostPath=")(.*?)("):$1'"`echo "${SF_MEDIA_TARGET}"`"'$3:g' "${TPL_FILE}"
perl -pi -e 's:\(stateFile="\)\(.*?/\)":\1'"`echo "${IMG_HOME}/"`"'\3:g' "${TPL_FILE}"
# Machine snapshotFolder
perl -pi -e 's:(Machine.*?snapshotFolder=")(.+?)("):$1'`echo "${TMP_DIR}"`'$3:g' "${TPL_FILE}"
# MACAddress
perl -pi -e 's:(MACAddress=")(.+?)("):$1'`echo ""`'$3:g' "${TPL_FILE}"
# stateFile
#perl -pi -e 's:(stateFile=")(.*)(/)(.*\.sav)("):$1'`echo "${IMG_HOME}/${VM_ID}/"`'$4$5:g' "${TPL_FILE}"
perl -pi -e 's:(stateFile=")([/]+.*[/]+)(.*?\.sav"):$1'`echo "${IMG_HOME}/${VM_ID}/"`'$3:g' "${TPL_FILE}"
#if [ "${DIFF_DISK_FILE}" != "" ]; then # HardDisks
# sed -i 's@\(HardDisk.*location="\)\([^"]*diff_[^"]*\)\("\)@\1'"`echo "${TMP_DIR}/${DIFF_DISK_FILE}"`"'\3@g' "${TPL_FILE}" perl -pi -e 's:(HardDisk.*?location=")([/]+.*[/]+)(.*?\.vdi"):$1'`echo "${IMG_HOME}/${VM_ID}/"`'$3:g' "${TPL_FILE}"
#fi echo "Please check harddisks locations:"
perl -ln -e 'BEGIN{undef $/} while (/<HardDisks>(.*?)<\/HardDisks>/sg){print $1}' "${TPL_FILE}"
exit 0 exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment