285 líneas
8.5 KiB
Bash
Archivo Ejecutable
285 líneas
8.5 KiB
Bash
Archivo Ejecutable
#!/bin/bash
|
|
# WoeUSB Docker Helper Script
|
|
# This script helps you easily create Windows bootable USB drives using WoeUSB in Docker
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored messages
|
|
print_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Function to list available ISOs
|
|
list_isos() {
|
|
print_info "Available ISO files in ./isos/"
|
|
if [ -z "$(ls -A isos/*.iso 2>/dev/null)" ]; then
|
|
print_warning "No ISO files found in ./isos/ directory"
|
|
echo "Please copy your Windows ISO file to the ./isos/ directory"
|
|
return 1
|
|
fi
|
|
ls -lh isos/*.iso 2>/dev/null || true
|
|
}
|
|
|
|
# Function to list USB devices
|
|
list_usb_devices() {
|
|
print_info "Available block devices:"
|
|
echo ""
|
|
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,VENDOR,MODEL | grep -E "disk|NAME"
|
|
echo ""
|
|
print_warning "⚠️ WARNING: The target device will be COMPLETELY ERASED!"
|
|
}
|
|
|
|
# Function to check if device exists
|
|
check_device() {
|
|
local device=$1
|
|
if [ ! -b "$device" ]; then
|
|
print_error "Device $device does not exist or is not a block device"
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# Function to unmount device
|
|
unmount_device() {
|
|
local device=$1
|
|
print_info "Unmounting $device partitions if mounted..."
|
|
sudo umount ${device}* 2>/dev/null || true
|
|
print_success "Device unmounted"
|
|
}
|
|
|
|
# Function to build Docker image
|
|
build_image() {
|
|
print_info "Building WoeUSB Docker image..."
|
|
docker-compose build
|
|
print_success "Docker image built successfully"
|
|
}
|
|
|
|
# Function to run WoeUSB
|
|
run_woeusb() {
|
|
local iso=$1
|
|
local device=$2
|
|
local filesystem=${3:-FAT}
|
|
|
|
# Check if ISO exists
|
|
if [ ! -f "$iso" ]; then
|
|
print_error "ISO file not found: $iso"
|
|
return 1
|
|
fi
|
|
|
|
# Get ISO filename for container path
|
|
local iso_name=$(basename "$iso")
|
|
|
|
# Update docker-compose.yml with device
|
|
print_info "Configuring Docker Compose with device $device..."
|
|
|
|
# Unmount device
|
|
unmount_device "$device"
|
|
|
|
# Run WoeUSB
|
|
print_info "Running WoeUSB..."
|
|
print_info "ISO: $iso_name"
|
|
print_info "Device: $device"
|
|
print_info "Filesystem: $filesystem"
|
|
print_info "Note: Loop devices (/dev/loop*) will be created automatically"
|
|
echo ""
|
|
|
|
docker run -it --rm --privileged \
|
|
-v "$(pwd)/isos:/isos:ro" \
|
|
-v "$(pwd)/output:/output" \
|
|
--device="$device:$device" \
|
|
woeusb:latest \
|
|
/bin/bash -c "sudo woeusb --device --target-filesystem $filesystem /isos/$iso_name $device"
|
|
|
|
print_success "Process completed!"
|
|
}
|
|
|
|
# Main menu
|
|
show_menu() {
|
|
echo ""
|
|
echo "=================================="
|
|
echo " WoeUSB Docker Helper Script"
|
|
echo "=================================="
|
|
echo ""
|
|
echo "1. List available ISO files"
|
|
echo "2. List USB devices"
|
|
echo "3. Build Docker image"
|
|
echo "4. Create bootable USB (FAT32)"
|
|
echo "5. Create bootable USB (NTFS)"
|
|
echo "6. Interactive shell"
|
|
echo "7. Exit"
|
|
echo ""
|
|
}
|
|
|
|
# Interactive mode
|
|
interactive_mode() {
|
|
while true; do
|
|
show_menu
|
|
read -p "Select an option [1-7]: " choice
|
|
|
|
case $choice in
|
|
1)
|
|
list_isos
|
|
;;
|
|
2)
|
|
list_usb_devices
|
|
;;
|
|
3)
|
|
build_image
|
|
;;
|
|
4)
|
|
list_isos
|
|
echo ""
|
|
read -p "Enter ISO filename (from ./isos/): " iso_file
|
|
list_usb_devices
|
|
echo ""
|
|
read -p "Enter target device (e.g., /dev/sdb): " target_device
|
|
|
|
if check_device "$target_device"; then
|
|
read -p "⚠️ Are you sure you want to erase $target_device? (yes/no): " confirm
|
|
if [ "$confirm" = "yes" ]; then
|
|
run_woeusb "isos/$iso_file" "$target_device" "FAT"
|
|
else
|
|
print_info "Operation cancelled"
|
|
fi
|
|
fi
|
|
;;
|
|
5)
|
|
list_isos
|
|
echo ""
|
|
read -p "Enter ISO filename (from ./isos/): " iso_file
|
|
list_usb_devices
|
|
echo ""
|
|
read -p "Enter target device (e.g., /dev/sdb): " target_device
|
|
|
|
if check_device "$target_device"; then
|
|
read -p "⚠️ Are you sure you want to erase $target_device? (yes/no): " confirm
|
|
if [ "$confirm" = "yes" ]; then
|
|
run_woeusb "isos/$iso_file" "$target_device" "NTFS"
|
|
else
|
|
print_info "Operation cancelled"
|
|
fi
|
|
fi
|
|
;;
|
|
6)
|
|
read -p "Enter device to mount (e.g., /dev/sdb) or press Enter to skip: " device
|
|
if [ -n "$device" ]; then
|
|
docker run -it --rm --privileged \
|
|
-v "$(pwd)/isos:/isos:ro" \
|
|
-v "$(pwd)/output:/output" \
|
|
--device="$device:$device" \
|
|
woeusb:latest /bin/bash
|
|
else
|
|
docker run -it --rm --privileged \
|
|
-v "$(pwd)/isos:/isos:ro" \
|
|
-v "$(pwd)/output:/output" \
|
|
woeusb:latest /bin/bash
|
|
fi
|
|
;;
|
|
7)
|
|
print_info "Goodbye!"
|
|
exit 0
|
|
;;
|
|
*)
|
|
print_error "Invalid option"
|
|
;;
|
|
esac
|
|
|
|
echo ""
|
|
read -p "Press Enter to continue..."
|
|
done
|
|
}
|
|
|
|
# Command line mode
|
|
if [ $# -eq 0 ]; then
|
|
# No arguments, run interactive mode
|
|
interactive_mode
|
|
else
|
|
# Parse command line arguments
|
|
case "$1" in
|
|
list-isos)
|
|
list_isos
|
|
;;
|
|
list-devices)
|
|
list_usb_devices
|
|
;;
|
|
build)
|
|
build_image
|
|
;;
|
|
create)
|
|
if [ $# -lt 3 ]; then
|
|
print_error "Usage: $0 create <iso-file> <device> [filesystem]"
|
|
print_error "Example: $0 create isos/windows10.iso /dev/sdb FAT"
|
|
exit 1
|
|
fi
|
|
iso_path=$2
|
|
device=$3
|
|
filesystem=${4:-FAT}
|
|
|
|
if check_device "$device"; then
|
|
print_warning "⚠️ Device $device will be COMPLETELY ERASED!"
|
|
read -p "Are you sure you want to continue? (yes/no): " confirm
|
|
if [ "$confirm" = "yes" ]; then
|
|
run_woeusb "$iso_path" "$device" "$filesystem"
|
|
else
|
|
print_info "Operation cancelled"
|
|
fi
|
|
fi
|
|
;;
|
|
shell)
|
|
device=${2:-}
|
|
if [ -n "$device" ]; then
|
|
docker run -it --rm --privileged \
|
|
-v "$(pwd)/isos:/isos:ro" \
|
|
-v "$(pwd)/output:/output" \
|
|
--device="$device:$device" \
|
|
woeusb:latest /bin/bash
|
|
else
|
|
docker run -it --rm --privileged \
|
|
-v "$(pwd)/isos:/isos:ro" \
|
|
-v "$(pwd)/output:/output" \
|
|
woeusb:latest /bin/bash
|
|
fi
|
|
;;
|
|
help|--help|-h)
|
|
echo "WoeUSB Docker Helper Script"
|
|
echo ""
|
|
echo "Usage:"
|
|
echo " $0 # Interactive mode"
|
|
echo " $0 list-isos # List available ISO files"
|
|
echo " $0 list-devices # List available USB devices"
|
|
echo " $0 build # Build Docker image"
|
|
echo " $0 create <iso> <device> [filesystem] # Create bootable USB"
|
|
echo " $0 shell [device] # Open interactive shell"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 create isos/windows10.iso /dev/sdb FAT"
|
|
echo " $0 create isos/windows11.iso /dev/sdb NTFS"
|
|
echo " $0 shell /dev/sdb"
|
|
;;
|
|
*)
|
|
print_error "Unknown command: $1"
|
|
echo "Run '$0 help' for usage information"
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|