Skip to content

Instantly share code, notes, and snippets.

@TylerCode
Last active November 25, 2024 21:50
Show Gist options
  • Save TylerCode/f53eaa2f328296ece9958284b7db8225 to your computer and use it in GitHub Desktop.
Save TylerCode/f53eaa2f328296ece9958284b7db8225 to your computer and use it in GitHub Desktop.
installs the guest tools on Ubuntu for XCP-NG
#!/bin/bash
# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Common CD/DVD device locations
DEVICE_LOCATIONS=(
"/dev/cdrom"
"/dev/cdrom0"
"/dev/cdrom1"
"/dev/sr0"
"/dev/sr1"
"/dev/xvdd" # Common XenServer/XCP-ng device
"/dev/hdc"
"/dev/scd0"
"/dev/scd1"
)
# Common ISO file locations
ISO_LOCATIONS=(
"./guest-tools.iso"
"/root/guest-tools.iso"
"/home/*/guest-tools.iso"
"/mnt/guest-tools.iso"
)
# Create mount point
MOUNT_POINT="/mnt/xcp-ng-guest-tools"
mkdir -p "$MOUNT_POINT"
# First, try to find and mount a device
MOUNTED=0
echo "Searching for XCP-ng guest tools disc..."
for device in "${DEVICE_LOCATIONS[@]}"; do
if [ -e "$device" ]; then
echo "Trying to mount $device..."
if mount "$device" "$MOUNT_POINT" 2>/dev/null; then
if [ -f "$MOUNT_POINT/Linux/install.sh" ]; then
echo "Found XCP-ng guest tools on $device"
MOUNTED=1
break
else
umount "$MOUNT_POINT"
fi
fi
fi
done
# If no device found, try ISO files
if [ $MOUNTED -eq 0 ]; then
echo "No guest tools found in CD/DVD devices, checking for ISO files..."
ISO_PATH=""
for loc in "${ISO_LOCATIONS[@]}"; do
if ls $loc >/dev/null 2>&1; then
ISO_PATH=$(ls $loc | head -n1)
break
fi
done
if [ -n "$ISO_PATH" ]; then
echo "Found ISO at $ISO_PATH"
mount -o loop "$ISO_PATH" "$MOUNT_POINT"
MOUNTED=1
fi
fi
# If still not mounted, ask for manual input
if [ $MOUNTED -eq 0 ]; then
echo "Could not find guest tools. Please specify the device or ISO path:"
read -r SOURCE
if [ -e "$SOURCE" ]; then
if [[ "$SOURCE" == /dev/* ]]; then
mount "$SOURCE" "$MOUNT_POINT"
else
mount -o loop "$SOURCE" "$MOUNT_POINT"
fi
MOUNTED=1
else
echo "Invalid source path"
exit 1
fi
fi
# Verify mount was successful
if ! mount | grep -q "$MOUNT_POINT"; then
echo "Failed to mount guest tools"
exit 1
fi
# Update package lists
apt-get update
# Install required dependencies
apt-get install -y build-essential linux-headers-$(uname -r)
# Navigate to the Linux directory in the mounted ISO
cd "$MOUNT_POINT/Linux"
# Install the guest tools
./install.sh
# Clean up
cd /
umount "$MOUNT_POINT"
rmdir "$MOUNT_POINT"
apt-get autoremove -y
apt-get clean
# Verify installation
if [ -f /usr/sbin/xe-linux-distribution ]; then
echo "XCP-NG guest tools installation completed successfully"
echo "Please reboot your system to complete the installation"
else
echo "Installation may have failed. Please check the logs"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment