Added USB passthrough support for mac and Linux VMs
This commit is contained in:
@@ -10,6 +10,17 @@ declare ram_size="${args[--ram-size]}"
|
|||||||
declare cpu_cores="${args[--cpu-cores]}"
|
declare cpu_cores="${args[--cpu-cores]}"
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
declare share_directory="${args[--share-directory]}"
|
declare share_directory="${args[--share-directory]}"
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
declare usb="${args[--usb]}"
|
||||||
|
declare -a flags=()
|
||||||
|
|
||||||
|
if [[ -n "$usb" ]]; then
|
||||||
|
vendor_id="$(udevadm info --query=all --name="$usb" | grep ID_VENDOR_ID | awk -F= '{print $2}')"
|
||||||
|
product_id="$(udevadm info --query=all --name="$usb" | grep ID_MODEL_ID | awk -F= '{print $2}')"
|
||||||
|
flags+=("--device=/dev/bus/usb")
|
||||||
|
flags+=("-e")
|
||||||
|
flags+=(ARGUMENTS="-device usb-host,vendorid=0x${vendor_id},productid=0x${product_id}")
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n $dist ]]; then
|
if [[ -n $dist ]]; then
|
||||||
image=$dist
|
image=$dist
|
||||||
@@ -47,6 +58,7 @@ if [[ "${args[--no-gui]}" == 1 ]]; then
|
|||||||
-e "RAM_SIZE=${ram_size}G" \
|
-e "RAM_SIZE=${ram_size}G" \
|
||||||
-e "CPU_CORES=$cpu_cores" \
|
-e "CPU_CORES=$cpu_cores" \
|
||||||
-v "$share_directory:/shared" \
|
-v "$share_directory:/shared" \
|
||||||
|
"${flags[@]}" \
|
||||||
--cap-add NET_ADMIN \
|
--cap-add NET_ADMIN \
|
||||||
--stop-timeout 120 \
|
--stop-timeout 120 \
|
||||||
qemux/qemu
|
qemux/qemu
|
||||||
@@ -60,6 +72,7 @@ if [[ "${args[--no-gui]}" == 1 ]]; then
|
|||||||
-e "RAM_SIZE=${ram_size}G" \
|
-e "RAM_SIZE=${ram_size}G" \
|
||||||
-e "CPU_CORES=$cpu_cores" \
|
-e "CPU_CORES=$cpu_cores" \
|
||||||
-v "$share_directory:/shared" \
|
-v "$share_directory:/shared" \
|
||||||
|
"${flags[@]}" \
|
||||||
--cap-add NET_ADMIN \
|
--cap-add NET_ADMIN \
|
||||||
--stop-timeout 120 \
|
--stop-timeout 120 \
|
||||||
qemux/qemu
|
qemux/qemu
|
||||||
@@ -78,6 +91,7 @@ else
|
|||||||
-e "RAM_SIZE=${ram_size}G" \
|
-e "RAM_SIZE=${ram_size}G" \
|
||||||
-e "CPU_CORES=$cpu_cores" \
|
-e "CPU_CORES=$cpu_cores" \
|
||||||
-v "$share_directory:/shared" \
|
-v "$share_directory:/shared" \
|
||||||
|
"${flags[@]}" \
|
||||||
--cap-add NET_ADMIN \
|
--cap-add NET_ADMIN \
|
||||||
--stop-timeout 120 \
|
--stop-timeout 120 \
|
||||||
-d \
|
-d \
|
||||||
@@ -94,6 +108,7 @@ else
|
|||||||
-e "RAM_SIZE=${ram_size}G" \
|
-e "RAM_SIZE=${ram_size}G" \
|
||||||
-e "CPU_CORES=$cpu_cores" \
|
-e "CPU_CORES=$cpu_cores" \
|
||||||
-v "$share_directory:/shared" \
|
-v "$share_directory:/shared" \
|
||||||
|
"${flags[@]}" \
|
||||||
--cap-add NET_ADMIN \
|
--cap-add NET_ADMIN \
|
||||||
--stop-timeout 120 \
|
--stop-timeout 120 \
|
||||||
-d \
|
-d \
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ declare cpu_cores="${args[--cpu-cores]}"
|
|||||||
declare share_directory="${args[--share-directory]}"
|
declare share_directory="${args[--share-directory]}"
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
declare persistent_dir_prefix="${args[--persistent-dir-prefix]:-$version}"
|
declare persistent_dir_prefix="${args[--persistent-dir-prefix]:-$version}"
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
declare usb="${args[--usb]}"
|
||||||
|
declare -a flags=()
|
||||||
|
|
||||||
|
if [[ -n "$usb" ]]; then
|
||||||
|
vendor_id="$(udevadm info --query=all --name="$usb" | grep ID_VENDOR_ID | awk -F= '{print $2}')"
|
||||||
|
product_id="$(udevadm info --query=all --name="$usb" | grep ID_MODEL_ID | awk -F= '{print $2}')"
|
||||||
|
flags+=("--device=/dev/bus/usb")
|
||||||
|
flags+=("-e")
|
||||||
|
flags+=(ARGUMENTS="-device usb-host,vendorid=0x${vendor_id},productid=0x${product_id}")
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${args[--wipe-persistent-data]}" == 1 ]]; then
|
if [[ "${args[--wipe-persistent-data]}" == 1 ]]; then
|
||||||
declare persistent_data_dir="$HOME/.vm/mac/$persistent_dir_prefix"
|
declare persistent_data_dir="$HOME/.vm/mac/$persistent_dir_prefix"
|
||||||
@@ -40,6 +51,7 @@ if [[ "${args[--persistent]}" == 1 ]]; then
|
|||||||
-v "$share_directory:/shared" \
|
-v "$share_directory:/shared" \
|
||||||
--cap-add NET_ADMIN \
|
--cap-add NET_ADMIN \
|
||||||
--stop-timeout 120 \
|
--stop-timeout 120 \
|
||||||
|
"${flags[@]}" \
|
||||||
-d \
|
-d \
|
||||||
dockurr/macos)
|
dockurr/macos)
|
||||||
else
|
else
|
||||||
@@ -55,6 +67,7 @@ else
|
|||||||
-v "$share_directory:/shared" \
|
-v "$share_directory:/shared" \
|
||||||
--cap-add NET_ADMIN \
|
--cap-add NET_ADMIN \
|
||||||
--stop-timeout 120 \
|
--stop-timeout 120 \
|
||||||
|
"${flags[@]}" \
|
||||||
-d \
|
-d \
|
||||||
dockurr/macos)
|
dockurr/macos)
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -24,50 +24,52 @@ commands:
|
|||||||
- long: --disk-size
|
- long: --disk-size
|
||||||
help: The disk size of the VM's drive in GB
|
help: The disk size of the VM's drive in GB
|
||||||
arg: disk_size
|
arg: disk_size
|
||||||
default: "64"
|
default: '64'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --ram-size
|
- long: --ram-size
|
||||||
help: The RAM size of the VM's RAM in GB
|
help: The RAM size of the VM's RAM in GB
|
||||||
arg: ram_size
|
arg: ram_size
|
||||||
default: "4"
|
default: '4'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --cpu-cores
|
- long: --cpu-cores
|
||||||
help: The number of CPU cores the VM is allowed to use
|
help: The number of CPU cores the VM is allowed to use
|
||||||
arg: cpu_cores
|
arg: cpu_cores
|
||||||
default: "2"
|
default: '2'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --share-directory
|
- long: --share-directory
|
||||||
help: The directory to share with the VM (In Windows, this is the Network#host.lan machine)
|
help: The directory to share with the VM (In Windows, this is the Network#host.lan machine)
|
||||||
arg: share_directory
|
arg: share_directory
|
||||||
default: "."
|
default: '.'
|
||||||
completions:
|
completions:
|
||||||
- <directory>
|
- <directory>
|
||||||
- long: --usb
|
- long: --usb
|
||||||
help: The USB device to mount into the VM (i.e. '/dev/sde')
|
help: The USB device to mount into the VM (e.g. '/dev/sde')
|
||||||
arg: usb
|
arg: usb
|
||||||
validate: device_exists
|
validate: device_exists
|
||||||
|
completions:
|
||||||
|
- <directory>
|
||||||
- long: --version
|
- long: --version
|
||||||
help: The version of Windows to start
|
help: The version of Windows to start
|
||||||
arg: version
|
arg: version
|
||||||
default: "11"
|
default: '11'
|
||||||
allowed:
|
allowed:
|
||||||
- "11"
|
- '11'
|
||||||
- "11l"
|
- '11l'
|
||||||
- "11e"
|
- '11e'
|
||||||
- "10"
|
- '10'
|
||||||
- "10l"
|
- '10l'
|
||||||
- "10e"
|
- '10e'
|
||||||
- "8e"
|
- '8e'
|
||||||
- "7e"
|
- '7e'
|
||||||
- "ve"
|
- 've'
|
||||||
- "xp"
|
- 'xp'
|
||||||
- "2025"
|
- '2025'
|
||||||
- "2022"
|
- '2022'
|
||||||
- "2019"
|
- '2019'
|
||||||
- "2016"
|
- '2016'
|
||||||
- "2012"
|
- '2012'
|
||||||
- "2008"
|
- '2008'
|
||||||
- "2003"
|
- '2003'
|
||||||
|
|
||||||
- name: linux
|
- name: linux
|
||||||
help: Start a Linux VM that's available at http://localhost:8006 and via SSH on port 2222
|
help: Start a Linux VM that's available at http://localhost:8006 and via SSH on port 2222
|
||||||
@@ -108,50 +110,56 @@ commands:
|
|||||||
- long: --disk-size
|
- long: --disk-size
|
||||||
help: The disk size of the VM's drive in GB
|
help: The disk size of the VM's drive in GB
|
||||||
arg: disk_size
|
arg: disk_size
|
||||||
default: "128"
|
default: '128'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --ram-size
|
- long: --ram-size
|
||||||
help: The RAM size of the VM's RAM in GB
|
help: The RAM size of the VM's RAM in GB
|
||||||
arg: ram_size
|
arg: ram_size
|
||||||
default: "8"
|
default: '8'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --cpu-cores
|
- long: --cpu-cores
|
||||||
help: The number of CPU cores the VM is allowed to use
|
help: The number of CPU cores the VM is allowed to use
|
||||||
arg: cpu_cores
|
arg: cpu_cores
|
||||||
default: "4"
|
default: '4'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --share-directory
|
- long: --share-directory
|
||||||
help: The directory to share with the VM (Access by running 'mount -t 9p -o trans=virtio shared /mnt/shared' in the container)
|
help: The directory to share with the VM (Access by running 'mount -t 9p -o trans=virtio shared /mnt/shared' in the container)
|
||||||
arg: share_directory
|
arg: share_directory
|
||||||
default: "."
|
default: '.'
|
||||||
|
completions:
|
||||||
|
- <directory>
|
||||||
|
- long: --usb
|
||||||
|
help: The USB device to mount into the VM (e.g. '/dev/sde')
|
||||||
|
arg: usb
|
||||||
|
validate: device_exists
|
||||||
completions:
|
completions:
|
||||||
- <directory>
|
- <directory>
|
||||||
- long: --dist
|
- long: --dist
|
||||||
help: The Linux distribution to start
|
help: The Linux distribution to start
|
||||||
arg: distribution
|
arg: distribution
|
||||||
allowed:
|
allowed:
|
||||||
- "alma"
|
- 'alma'
|
||||||
- "alpine"
|
- 'alpine'
|
||||||
- "arch"
|
- 'arch'
|
||||||
- "cachy"
|
- 'cachy'
|
||||||
- "centos"
|
- 'centos'
|
||||||
- "debian"
|
- 'debian'
|
||||||
- "fedora"
|
- 'fedora'
|
||||||
- "gentoo"
|
- 'gentoo'
|
||||||
- "kali"
|
- 'kali'
|
||||||
- "kubuntu"
|
- 'kubuntu'
|
||||||
- "mint"
|
- 'mint'
|
||||||
- "manjaro"
|
- 'manjaro'
|
||||||
- "mx"
|
- 'mx'
|
||||||
- "nixos"
|
- 'nixos'
|
||||||
- "suse"
|
- 'suse'
|
||||||
- "oracle"
|
- 'oracle'
|
||||||
- "rocky"
|
- 'rocky'
|
||||||
- "slack"
|
- 'slack'
|
||||||
- "tails"
|
- 'tails'
|
||||||
- "ubuntu"
|
- 'ubuntu'
|
||||||
- "ubuntus"
|
- 'ubuntus'
|
||||||
- "xubuntu"
|
- 'xubuntu'
|
||||||
conflicts: [--image-url]
|
conflicts: [--image-url]
|
||||||
- long: --image-url
|
- long: --image-url
|
||||||
help: |-
|
help: |-
|
||||||
@@ -191,31 +199,37 @@ commands:
|
|||||||
- long: --disk-size
|
- long: --disk-size
|
||||||
help: The disk size of the VM's drive in GB
|
help: The disk size of the VM's drive in GB
|
||||||
arg: disk_size
|
arg: disk_size
|
||||||
default: "64"
|
default: '64'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --ram-size
|
- long: --ram-size
|
||||||
help: The RAM size of the VM's RAM in GB
|
help: The RAM size of the VM's RAM in GB
|
||||||
arg: ram_size
|
arg: ram_size
|
||||||
default: "4"
|
default: '4'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --cpu-cores
|
- long: --cpu-cores
|
||||||
help: The number of CPU cores the VM is allowed to use
|
help: The number of CPU cores the VM is allowed to use
|
||||||
arg: cpu_cores
|
arg: cpu_cores
|
||||||
default: "2"
|
default: '2'
|
||||||
validate: integer
|
validate: integer
|
||||||
- long: --share-directory
|
- long: --share-directory
|
||||||
help: The directory to share with the VM (Access by running 'mount -S mount_9p shared' in the container; Then it's available under Finder -> Go -> Computer)
|
help: The directory to share with the VM (Access by running 'mount -S mount_9p shared' in the container; Then it's available under Finder -> Go -> Computer)
|
||||||
arg: share_directory
|
arg: share_directory
|
||||||
default: "."
|
default: '.'
|
||||||
|
completions:
|
||||||
|
- <directory>
|
||||||
|
- long: --usb
|
||||||
|
help: The USB device to mount into the VM (e.g. '/dev/sde')
|
||||||
|
arg: usb
|
||||||
|
validate: device_exists
|
||||||
completions:
|
completions:
|
||||||
- <directory>
|
- <directory>
|
||||||
- long: --version
|
- long: --version
|
||||||
help: The version of MacOS to start
|
help: The version of MacOS to start
|
||||||
arg: version
|
arg: version
|
||||||
default: "13"
|
default: '15'
|
||||||
allowed:
|
allowed:
|
||||||
- "15"
|
- '15'
|
||||||
- "14"
|
- '14'
|
||||||
- "13"
|
- '13'
|
||||||
- "12"
|
- '12'
|
||||||
- "11"
|
- '11'
|
||||||
|
|||||||
+506
-494
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user