install_vmtools.sh
· 1.2 KiB · Bash
Ham
#!/bin/bash
set -e
# Define variables
ISO_URL="http://172.29.48.5/VMTOOLS/3.2.0/SMTX_VMTOOLS-3.2.0-2501210639.iso"
ISO_FILE="/tmp/vmtools.iso"
MOUNT_POINT="/mnt/wuke-vmtools"
# 1. Install required packages
if command -v yum >/dev/null 2>&1; then
echo "Installing dependencies using yum..."
yum install -y tar bzip2
elif command -v apt >/dev/null 2>&1; then
echo "Installing dependencies using apt..."
apt update
apt install -y tar bzip2
else
echo "Unsupported OS: yum or apt not found."
exit 1
fi
# 2. Download the ISO file
echo "Downloading VMTools ISO..."
curl -o "$ISO_FILE" "$ISO_URL"
# 3. Check if /mnt/wuke-vmtools exists
if [ -d "$MOUNT_POINT" ]; then
echo "Directory $MOUNT_POINT exists, removing..."
umount "$MOUNT_POINT" || true
rm -rf "$MOUNT_POINT"
fi
echo "Creating directory $MOUNT_POINT..."
mkdir -p "$MOUNT_POINT"
# 4. Mount the ISO
echo "Mounting ISO file to $MOUNT_POINT..."
mount -o loop "$ISO_FILE" "$MOUNT_POINT"
# 5. Execute the installation script
echo "Running VMTools installation script..."
bash "$MOUNT_POINT/SMTX_VM_TOOLS_INSTALL.sh"
# 6. Cleanup
echo "Cleaning up temporary files..."
umount "$MOUNT_POINT" || true
rm -f "$ISO_FILE"
rm -rf "$MOUNT_POINT"
echo "Installation and cleanup completed."
| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | # Define variables |
| 5 | ISO_URL="http://172.29.48.5/VMTOOLS/3.2.0/SMTX_VMTOOLS-3.2.0-2501210639.iso" |
| 6 | ISO_FILE="/tmp/vmtools.iso" |
| 7 | MOUNT_POINT="/mnt/wuke-vmtools" |
| 8 | |
| 9 | # 1. Install required packages |
| 10 | if command -v yum >/dev/null 2>&1; then |
| 11 | echo "Installing dependencies using yum..." |
| 12 | yum install -y tar bzip2 |
| 13 | elif command -v apt >/dev/null 2>&1; then |
| 14 | echo "Installing dependencies using apt..." |
| 15 | apt update |
| 16 | apt install -y tar bzip2 |
| 17 | else |
| 18 | echo "Unsupported OS: yum or apt not found." |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | # 2. Download the ISO file |
| 23 | echo "Downloading VMTools ISO..." |
| 24 | curl -o "$ISO_FILE" "$ISO_URL" |
| 25 | |
| 26 | # 3. Check if /mnt/wuke-vmtools exists |
| 27 | if [ -d "$MOUNT_POINT" ]; then |
| 28 | echo "Directory $MOUNT_POINT exists, removing..." |
| 29 | umount "$MOUNT_POINT" || true |
| 30 | rm -rf "$MOUNT_POINT" |
| 31 | fi |
| 32 | |
| 33 | echo "Creating directory $MOUNT_POINT..." |
| 34 | mkdir -p "$MOUNT_POINT" |
| 35 | |
| 36 | # 4. Mount the ISO |
| 37 | echo "Mounting ISO file to $MOUNT_POINT..." |
| 38 | mount -o loop "$ISO_FILE" "$MOUNT_POINT" |
| 39 | |
| 40 | # 5. Execute the installation script |
| 41 | echo "Running VMTools installation script..." |
| 42 | bash "$MOUNT_POINT/SMTX_VM_TOOLS_INSTALL.sh" |
| 43 | |
| 44 | # 6. Cleanup |
| 45 | echo "Cleaning up temporary files..." |
| 46 | umount "$MOUNT_POINT" || true |
| 47 | rm -f "$ISO_FILE" |
| 48 | rm -rf "$MOUNT_POINT" |
| 49 | |
| 50 | echo "Installation and cleanup completed." |