updated ubuntun, found bug

This commit is contained in:
Statik DK Smoke 2025-09-07 23:27:28 -05:00 committed by GitHub
parent cbf0fd015e
commit f193460e0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 122 additions and 76 deletions

View File

@ -1,6 +1,14 @@
#!/usr/bin/bash
# macOS KVM Installation Script for a brand-new Linux system
# Quick Install: curl -fsSL <URL> | bash
# macOS KVM Installation Script with wget/curl support
#
# Quick Install (one-liner):
# curl -fsSL https://raw.githubusercontent.com/yourusername/OSX-KVM/master/install-macos-kvm.sh | bash
#
# Usage: ./install-macos-kvm.sh [OPTIONS]
# Options:
# --use-curl Use curl instead of wget for downloads
# --help Show this help message
set -e # Exit on any error
@ -10,24 +18,21 @@ INSTALL_DIR="$HOME/OSX-KVM"
# Function to display help
show_help() {
cat <<EOF
macOS KVM Installation Script
Usage: $0 [OPTIONS]
Options:
--use-curl Use curl instead of wget for downloads
--help Show this help message
This script will:
1. Install all required packages
2. Clone the OSX-KVM repository
3. Download macOS recovery image
4. Convert BaseSystem.dmg to raw format
5. Create macOS disk image (100GB)
6. Set proper permissions for libvirt
7. Launch macOS VM
EOF
echo "macOS KVM Installation Script"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --use-curl Use curl instead of wget for downloads"
echo " --help Show this help message"
echo ""
echo "This script will:"
echo " 1. Clone the OSX-KVM repository"
echo " 2. Download macOS recovery image"
echo " 3. Convert BaseSystem.dmg to raw format"
echo " 4. Create macOS disk image (100GB)"
echo " 5. Set proper permissions for libvirt"
echo " 6. Launch macOS VM"
}
# Function to check if command exists
@ -35,25 +40,21 @@ command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to install packages via apt
install_package() {
local pkg="$1"
if ! dpkg -s "$pkg" >/dev/null 2>&1; then
echo "Installing missing package: $pkg"
sudo apt-get install -y "$pkg"
fi
}
# Function to download files
# Function to download with fallback
download_file() {
local url="$1"
local output="$2"
echo "Downloading: $url"
if [ "$USE_CURL" = true ] && command_exists curl; then
echo "Using curl for download..."
curl -L -o "$output" "$url"
elif command_exists wget; then
echo "Using wget for download..."
wget -O "$output" "$url"
elif command_exists curl; then
echo "wget not found, falling back to curl..."
curl -L -o "$output" "$url"
else
echo "Error: Neither wget nor curl found. Please install one of them."
@ -74,61 +75,64 @@ while [[ $# -gt 0 ]]; do
;;
*)
echo "Unknown option: $1"
show_help
echo "Use --help for usage information"
exit 1
;;
esac
done
echo "Updating package list..."
sudo apt-get update -y
# Check for required commands
echo "Checking system requirements..."
# Install required packages
REQUIRED_PKGS=(git wget curl python3 python3-pip qemu-system qemu-utils \
uml-utilities virt-manager libguestfs-tools p7zip-full make dmg2img \
tesseract-ocr tesseract-ocr-eng genisoimage vim net-tools screen)
for pkg in "${REQUIRED_PKGS[@]}"; do
install_package "$pkg"
done
echo "✓ All required packages installed"
# Check system commands
for cmd in git qemu-img wget curl python3 make dmg2img; do
if ! command_exists "$cmd"; then
echo "Error: $cmd is required but not installed."
if ! command_exists git; then
echo "Error: git is required but not installed."
exit 1
fi
done
fi
echo "✓ System commands verified"
if ! command_exists qemu-img; then
echo "Error: qemu-img is required but not installed."
echo "Please install qemu-utils or qemu-system package"
exit 1
fi
# Create installation directory
# Check for download capability
if ! command_exists wget && ! command_exists curl; then
echo "Error: Neither wget nor curl found."
echo "Please install wget or curl to continue."
exit 1
fi
echo "✓ System requirements check passed"
# Create installation directory if it doesn't exist
if [ -d "$INSTALL_DIR" ]; then
echo "Warning: $INSTALL_DIR exists. Backing up to ${INSTALL_DIR}.backup"
echo "Warning: $INSTALL_DIR already exists. Backing up to ${INSTALL_DIR}.backup"
mv "$INSTALL_DIR" "${INSTALL_DIR}.backup.$(date +%Y%m%d_%H%M%S)"
fi
# Clone repository
# Clone the repository
echo "Cloning OSX-KVM repository..."
git clone https://github.com/kholia/OSX-KVM.git "$INSTALL_DIR"
cd "$INSTALL_DIR"
# Setup KVM
sudo modprobe kvm
echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs >/dev/null || true
[ -f kvm_amd.conf ] && sudo cp kvm_amd.conf /etc/modprobe.d/kvm.conf
sudo apt-get install qemu-system uml-utilities virt-manager git \
wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
tesseract-ocr-eng genisoimage vim net-tools screen -y
sudo usermod -aG kvm "$(whoami)"
sudo usermod -aG libvirt "$(whoami)"
sudo usermod -aG input "$(whoami)"
sudo modprobe kvm; echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
sudo cp kvm_amd.conf /etc/modprobe.d/kvm.conf # for amd boxes only
sudo usermod -aG kvm $(whoami)
sudo usermod -aG libvirt $(whoami)
sudo usermod -aG input $(whoami)
# Download macOS recovery image
echo "Downloading macOS recovery image..."
if [ -f "fetch-macOS-v2.py" ]; then
python3 fetch-macOS-v2.py
else
echo "Warning: fetch-macOS-v2.py not found, attempting manual download..."
# Fallback download URLs for macOS recovery images
RECOVERY_URL="https://updates.cdn-apple.com/2019FallFCS/fullrestores/061-44998/B5A3E286-1C4A-11EA-99D4-864D6786AB92/BaseSystem.dmg"
download_file "$RECOVERY_URL" "BaseSystem.dmg"
fi
@ -143,36 +147,78 @@ else
exit 1
fi
# Create macOS disk image
echo "Creating macOS disk image (256GB)..."
# Create macOS disk image (100GB)
echo "Creating macOS disk image (100GB)..."
qemu-img create -f qcow2 macOS.qcow2 256G
ln -sf macOS.qcow2 mac_hdd_ng.img
echo "✓ Disk image created"
echo "✓ macOS.qcow2 created successfully"
# Set permissions for libvirt
sudo chown libvirt-qemu:libvirt-qemu macOS.qcow2 2>/dev/null || true
sudo chmod 664 macOS.qcow2 2>/dev/null || true
sudo chmod 755 "$INSTALL_DIR" 2>/dev/null || true
# Create symlink for script compatibility
echo "Creating compatibility symlink..."
ln -sf macOS.qcow2 mac_hdd_ng.img
# Fix permissions for libvirt
echo "Setting up permissions for libvirt..."
sudo chown libvirt-qemu:libvirt-qemu macOS.qcow2 2>/dev/null || {
echo "Warning: Could not change ownership to libvirt-qemu. You may need to run this manually:"
echo " sudo chown libvirt-qemu:libvirt-qemu $INSTALL_DIR/macOS.qcow2"
}
sudo chmod 664 macOS.qcow2 2>/dev/null || {
echo "Warning: Could not change permissions. You may need to run this manually:"
echo " sudo chmod 664 $INSTALL_DIR/macOS.qcow2"
}
# Fix directory permissions
sudo chmod 755 "$INSTALL_DIR" 2>/dev/null || {
echo "Warning: Could not change directory permissions. You may need to run this manually:"
echo " sudo chmod 755 $INSTALL_DIR"
}
# Make scripts executable
echo "Making scripts executable..."
chmod +x *.sh
# Build OpenCore if missing
# Check if OpenCore exists and build if necessary
if [ ! -f "OpenCore/OpenCore.qcow2" ]; then
echo "OpenCore not found, attempting to build..."
cd OpenCore || exit
[ -f "Makefile" ] && make || echo "Warning: Could not build OpenCore"
cd OpenCore
if [ -f "Makefile" ]; then
make
else
echo "Warning: Could not build OpenCore. You may need to build it manually."
fi
cd ..
fi
echo ""
echo "🎉 Installation completed successfully!"
echo ""
echo "Next steps:"
echo "1. Start macOS VM: cd $INSTALL_DIR && sudo ./OpenCore-Boot.sh"
echo "2. Use virt-manager: import XML, start VM"
echo "1. To start the macOS VM using the script:"
echo " cd $INSTALL_DIR && sudo ./OpenCore-Boot.sh"
echo ""
echo "2. To use with virt-manager:"
echo " - Import the provided libvirt XML configuration"
echo " - Start the VM through virt-manager interface"
echo ""
echo "3. During installation:"
echo " - Select 'macOS Base System' from OpenCore"
echo " - Use Disk Utility to format the 256GB drive"
echo " - Install macOS to the formatted drive"
echo ""
echo "Files created:"
echo " - BaseSystem.img (macOS installer)"
echo " - macOS.qcow2 (100GB virtual disk)"
echo " - mac_hdd_ng.img -> macOS.qcow2 (compatibility symlink)"
echo ""
# Prompt to start VM
read -p "Start macOS VM now? (y/n): " -n 1 -r
# Ask if user wants to start the VM now
read -p "Would you like to start the macOS VM now? (y/n): " -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]] && sudo ./OpenCore-Boot.sh || echo "VM can be started later"
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Starting macOS VM..."
sudo ./OpenCore-Boot.sh
else
echo "You can start the VM later by running:"
echo " cd $INSTALL_DIR && sudo ./OpenCore-Boot.sh"
fi