Skip to content

Instantly share code, notes, and snippets.

@vikas027
Created March 5, 2016 13:51
Show Gist options
  • Save vikas027/388cc2047fc07d5b4e9e to your computer and use it in GitHub Desktop.
Save vikas027/388cc2047fc07d5b4e9e to your computer and use it in GitHub Desktop.
Fix of Banno/packer-post-processor-vsphere-ova
#!/bin/bash -eux
# This script fix an issue in https://github.com/Banno/packer-post-processor-vsphere-ova/issues/
# name of my builder in packer.json is virtualbox-vsphere
dir='output-virtualbox-vsphere'
ova_file=`ls ${dir}/*.ova | awk -F"/" '{ print $2 }' | sed 's/.ova//'`
tar xvf ${dir}/${ova_file}.ova -C ${dir}
ovf_file=`ls ${dir}/*.ovf`
# Set the correct OS Version for vSphere, otherwise it gets imported as Other (32-bit) which is neither Windows nor Linux
sed -i '' 's/ovf:id="80"/ovf:id="107" vmw:osType="centos64Guest"/' ${ovf_file}
# Add Virtual CDROM
cat > /tmp/esxi-cdrom << 'EOF'
<Item ovf:required="false">
#<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
<rasd:ElementName>CD-ROM 1</rasd:ElementName>
<rasd:InstanceID>7</rasd:InstanceID>
<rasd:Parent>4</rasd:Parent>
<rasd:ResourceSubType>vmware.cdrom.remotepassthrough</rasd:ResourceSubType>
<rasd:ResourceType>15</rasd:ResourceType>
<vmw:Config ovf:required="false" vmw:key="backing.exclusive" vmw:value="false" />
</Item>
EOF
line_number=`grep -n "</System>" ${ovf_file} | awk -F":" '{ print $1 }'`
sed -i '' ''$line_number'r /tmp/esxi-cdrom' ${ovf_file}
rm -fv /tmp/esxi-cdrom
rm -fv ${dir}/${ova_file}.ova
# Generating new ${ova_file}.ova"
ovftool ${dir}/${ova_file}.ovf ${dir}/${ova_file}.ova && sleep 1
cp -v ${dir}/${ova_file}.ova /MY_STUFF/SourceTree/vagrant-packer-ansible && sleep 1
rm -fv ${dir}/*.vmdk ${dir}/*.ovf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment