feat: Refactor platform code (#103)

This commit is contained in:
Kroese 2024-05-09 11:17:34 +02:00 committed by GitHub
parent 9b780e5552
commit 05c21f3316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 32 deletions

View file

@ -246,6 +246,19 @@ docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --cap-add NET_
Please note that in this mode, the container and Windows will each have their own separate IPs. The container will keep the macvlan IP, and Windows will use the DHCP IP.
* ### How do I add multiple disks?
To create additional disks, modify your compose file like this:
```yaml
environment:
DISK2_SIZE: "32G"
DISK3_SIZE: "64G"
volumes:
- /home/example:/storage2
- /mnt/data/example:/storage3
```
* ### How do I pass-through a disk?
It is possible to pass-through disk devices directly by adding them to your compose file in this way:

View file

@ -279,7 +279,7 @@ verifyFile() {
local check="$4"
if [ -n "$size" ] && [[ "$total" != "$size" ]] && [[ "$size" != "0" ]]; then
warn "The downloaded file has an invalid size: $total bytes, while expected value was: $size bytes. Please report this at $SUPPORT/issues"
warn "The downloaded file has an unexpected size: $total bytes, while expected value was: $size bytes. Please report this at $SUPPORT/issues"
fi
local hash=""
@ -394,10 +394,9 @@ downloadImage() {
tried="y"
if getESD "$TMP/esd" "$version"; then
local prev="$ISO"
ISO="${ISO%.*}.esd"
downloadFile "$ISO" "$ESD" "$ESD_SUM" "$ESD_SIZE" "$desc" && return 0
ISO="$prev"
ISO="$iso"
fi
fi
@ -626,41 +625,27 @@ selectVersion() {
detectVersion() {
local xml="$1"
local id=""
local arch=""
local id arch
local tag="ARCH"
local platform="x64"
local compat="$platform"
arch=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml")
case "${arch,,}" in
"0" )
platform="x86"
if [[ "${PLATFORM,,}" != "x64" ]]; then
error "You cannot boot $platform images on a $PLATFORM cpu!" && exit 67
fi
;;
"9" )
platform="x64"
if [[ "${PLATFORM,,}" != "x64" ]]; then
error "You cannot boot $platform images on a $PLATFORM cpu!" && exit 67
fi
;;
"12" )
platform="arm64"
if [[ "${PLATFORM,,}" != "arm64" ]]; then
error "You cannot boot ${platform^^} images on a $PLATFORM cpu!" && exit 67
fi
;;
"0" ) platform="x86"; compat="x64" ;;
"9" ) platform="x64"; compat="$platform" ;;
"12" )platform="arm64"; compat="$platform" ;;
esac
if [[ "${compat,,}" != "${PLATFORM,,}" ]]; then
error "You cannot boot ${platform^^} images on a $PLATFORM cpu!"
exit 67
fi
id=$(selectVersion "DISPLAYNAME" "$xml" "$platform")
[ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0
id=$(selectVersion "PRODUCTNAME" "$xml" "$platform")
[ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0
id=$(selectVersion "NAME" "$xml" "$platform")
[ -z "$id" ] && id=$(selectVersion "PRODUCTNAME" "$xml" "$platform")
[ -z "$id" ] && id=$(selectVersion "NAME" "$xml" "$platform")
[ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0
return 0
@ -674,8 +659,8 @@ detectImage() {
XML=""
if [ -z "$DETECTED" ] && [[ "${version,,}" != "http"* ]]; then
[ -z "$CUSTOM" ] && DETECTED="$version"
if [ -z "$DETECTED" ] && [ -z "$CUSTOM" ]; then
[[ "${version,,}" != "http"* ]] && DETECTED="$version"
fi
if [ -n "$DETECTED" ]; then