VMware Tools工具安装脚本(CentOS & Ubuntu)
#!/bin/bash
log_info() {
echo "[INFO] $1"
echo "[INFO] $1" >> "$LOGFILE"
}
log_error() {
echo "[ERROR] $1"
echo "[ERROR] $1" >> "$LOGFILE"
exit 1
}
# Log file to record install process
LOGFILE="/var/log/env-script.log"
# Create mount point if it doesn't exist
mkdir -p /mnt/cdrom || log_error "Failed to create mount point"
# Set CD-ROM permissions
chmod 777 /dev/cdrom || log_error "Failed to set CD-ROM permissions"
# Mount the ISO image
mount -t iso9660 /dev/cdrom /mnt/cdrom || log_error "Failed to mount ISO image"
# Copy VMware Tools package
cp /mnt/cdrom/VMwareTools-10.3.25-20206839.tar.gz /usr/local/src || log_error "Failed to copy VMware Tools package"
# Change to the extraction directory
cd /usr/local/src || log_error "Cannot enter extraction directory"
# Extract VMware Tools package
tar -xf VMwareTools-10.3.25-20206839.tar.gz || log_error "Failed to extract VMware Tools package"
# Change to the extracted directory
cd vmware-tools-distrib || log_error "Cannot enter vmware-tools-distrib directory"
# Install Perl dependency
apt-get update || log_error "Failed to update package list"
apt-get install -y perl || log_error "Failed to install Perl dependency"
# Execute VMware Tools installation script
echo -e "y\n" | ./vmware-install.pl || log_error "Failed to execute VMware Tools installation script"
# Reset CD-ROM permissions
chmod 660 /dev/cdrom || log_error "Failed to reset CD-ROM permissions"
# Record success information
log_info "All steps completed."
echo "All steps completed." >> "$LOGFILE"