Skip to content

Commit

Permalink
vmtools.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Dec 13, 2024
1 parent cea4b18 commit 141121a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,18 @@ source "vmware-iso" "controller" {
http_directory = "kickstart"
iso_checksum = "${var.iso_checksum}"
iso_urls = ["${var.iso_url1}", "${var.iso_url2}"]
output_directory = "output-vmware-iso"
output_directory = "output-images"
shutdown_command = "echo 'vagrant' | sudo -S /sbin/shutdown -h 0"
ssh_password = "vagrant"
ssh_username = "root"
ssh_username = "vagrant"
ssh_wait_timeout = "10000s"
tools_upload_flavor = "linux"
vm_name = "controller"
vmdk_name = "controller"
vmx_data = {
"svga.autodetect" = true
"usb_xhci.present" = true
}
}

# https://developer.hashicorp.com/packer/plugins/builders/hyperv/iso
Expand Down Expand Up @@ -208,10 +212,15 @@ build {
sources = ["source.azure-arm.controller", "source.hyperv-iso.controller", "source.virtualbox-iso.controller", "source.vmware-iso.controller"]

provisioner "shell" {
except = ["azure-arm.controller"]
except = ["azure-arm.controller"]
execute_command = "bash '{{ .Path }}'"
script = "vagrant.sh"
}
provisioner "shell" {
except = ["azure-arm.controller"]
execute_command = "bash '{{ .Path }}'"
script = "vmtools.sh"
}
provisioner "shell" {
execute_command = "echo 'vagrant' | {{ .Vars }} sudo -S -E bash '{{ .Path }}'"
scripts = ["controller.sh"]
Expand Down
50 changes: 50 additions & 0 deletions vmtools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh -eux

# set a default HOME_DIR environment variable if not set
HOME_DIR=/root

case "$PACKER_BUILDER_TYPE" in

virtualbox-iso|virtualbox-ovf)
yum install -y bzip2 tar gcc make perl cpp libstdc++-devel kernel-devel kernel-headers

mkdir -p /tmp/vbox /run/vboxadd
chown vboxadd /run/vboxadd
chmod 700 /run/vboxadd
mount -o loop $HOME_DIR/VBoxGuestAdditions.iso /tmp/vbox;
sh /tmp/vbox/VBoxLinuxAdditions.run \
|| echo "VBoxLinuxAdditions.run exited $? and is suppressed." \
"For more read https://www.virtualbox.org/ticket/12479";
umount /tmp/vbox;
rm -rf /tmp/vbox;
rm -f $HOME_DIR/*.iso;

yum -y erase gcc make perl cpp libstdc++-devel kernel-devel kernel-headers
yum -y clean all

## https://access.redhat.com/site/solutions/58625 (subscription required)
# add 'single-request-reopen' so it is included when /etc/resolv.conf is generated
echo 'RES_OPTIONS="single-request-reopen"' >> /etc/sysconfig/network
service network restart
echo 'Slow DNS fix applied (single-request-reopen)'

;;

vmware-iso|vmware-vmx)
yum install -y perl fuse-utils
mkdir -p /tmp/vmware
mkdir -p /tmp/vmware-archive
mount -o loop $HOME_DIR/linux.iso /tmp/vmware
tar xzf /tmp/vmware/VMwareTools-*.tar.gz -C /tmp/vmware-archive
/tmp/vmware-archive/vmware-tools-distrib/vmware-install.pl --default
umount /tmp/vmware;
rm -rf /tmp/vmware;
rm -rf /tmp/vmware-archive;
rm -f $HOME_DIR/*.iso;
;;

*)
echo "No guest additions implemented for ${PACKER_BUILDER_TYPE}"
;;

esac

0 comments on commit 141121a

Please sign in to comment.