Files
easyqemu/install.sh
2026-01-07 02:01:17 +01:00

167 líneas
4.8 KiB
Bash
Archivo Ejecutable

#!/bin/bash
##############################################################################
# EasyQEMU Installation Script
##############################################################################
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
cat << 'EOF'
╔═══════════════════════════════════════════════════════════════╗
║ EasyQEMU Installation ║
╚═══════════════════════════════════════════════════════════════╝
EOF
echo ""
# Check if QEMU is installed
info "Checking for QEMU installation..."
if ! command -v qemu-system-x86_64 &> /dev/null; then
error "qemu-system-x86_64 not found"
echo ""
echo "Please install QEMU first:"
echo ""
echo " Debian/Ubuntu: sudo apt-get install qemu-system-x86 qemu-utils"
echo " Fedora/RHEL: sudo dnf install qemu-kvm qemu-img"
echo " Arch Linux: sudo pacman -S qemu"
echo ""
exit 1
fi
if ! command -v qemu-img &> /dev/null; then
error "qemu-img not found"
echo ""
echo "Please install QEMU utilities:"
echo ""
echo " Debian/Ubuntu: sudo apt-get install qemu-utils"
echo " Fedora/RHEL: sudo dnf install qemu-img"
echo " Arch Linux: sudo pacman -S qemu"
echo ""
exit 1
fi
success "QEMU is installed"
# Check KVM
info "Checking for KVM support..."
if [[ -e /dev/kvm ]]; then
if [[ -r /dev/kvm ]] && [[ -w /dev/kvm ]]; then
success "KVM is available and accessible"
else
echo -e "${YELLOW}[WARNING]${NC} KVM device exists but is not accessible"
echo "You may need to add your user to the kvm group:"
echo " sudo usermod -a -G kvm \$USER"
echo "Then log out and log back in."
fi
else
echo -e "${YELLOW}[WARNING]${NC} KVM is not available"
echo "VMs will run without hardware acceleration (slower)"
fi
# Install location
echo ""
info "Select installation type:"
echo ""
echo " 1) System-wide installation (requires sudo, installs to /usr/local/bin)"
echo " 2) User installation (installs to ~/.local/bin)"
echo " 3) Don't install, just use from current directory"
echo ""
read -p "Choose [1-3]: " -n 1 -r
echo ""
INSTALL_TYPE=$REPLY
case $INSTALL_TYPE in
1)
info "Installing system-wide..."
sudo cp easyqemu /usr/local/bin/easyqemu
sudo chmod +x /usr/local/bin/easyqemu
success "Installed to /usr/local/bin/easyqemu"
;;
2)
info "Installing for user..."
mkdir -p ~/.local/bin
cp easyqemu ~/.local/bin/easyqemu
chmod +x ~/.local/bin/easyqemu
success "Installed to ~/.local/bin/easyqemu"
# Check if ~/.local/bin is in PATH
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo ""
echo -e "${YELLOW}[WARNING]${NC} ~/.local/bin is not in your PATH"
echo "Add this line to your ~/.bashrc or ~/.zshrc:"
echo ""
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
fi
;;
3)
info "No installation performed"
success "You can run easyqemu from this directory: ./easyqemu"
;;
*)
error "Invalid choice"
exit 1
;;
esac
# Create default directories
info "Initializing EasyQEMU directories..."
mkdir -p ~/.easyqemu/{vms,volumes,configs,repository,locks}
success "Directories created in ~/.easyqemu"
# Copy configuration if it doesn't exist
if [[ ! -f ~/.easyqemu/config ]]; then
if [[ -f .easyqemu.conf ]]; then
cp .easyqemu.conf ~/.easyqemu/config
success "Configuration file created"
fi
fi
echo ""
cat << 'EOF'
╔═══════════════════════════════════════════════════════════════╗
║ Installation Complete! ║
╚═══════════════════════════════════════════════════════════════╝
Getting Started:
1. View help:
easyqemu help
2. Create your first VM:
easyqemu vm create --name myvm --memory 2048 --cpus 2
3. List VMs:
easyqemu vm list
4. View examples:
./EXAMPLES.sh
5. Read documentation:
cat README.md
For more information, visit the documentation or run 'easyqemu help'
EOF