From b0ffbb9c0ce511e014195e55a86de5e829f49f39 Mon Sep 17 00:00:00 2001 From: ange Date: Sun, 10 Mar 2024 21:32:43 +0100 Subject: [PATCH] feat: add create/download_isos to run.sh --- android-x86/create.sh | 15 --------------- android-x86/download_isos.sh | 5 ----- android-x86/run.sh | 10 +++++++--- arch/run.sh | 2 +- debian12/run.sh | 2 +- lib.sh | 18 ++++++++++++++++++ win2k22/create.sh | 16 ---------------- win2k22/download_isos.sh | 8 -------- win2k22/run.sh | 12 ++++++++---- 9 files changed, 35 insertions(+), 53 deletions(-) delete mode 100644 android-x86/create.sh delete mode 100755 android-x86/download_isos.sh delete mode 100644 win2k22/create.sh delete mode 100755 win2k22/download_isos.sh diff --git a/android-x86/create.sh b/android-x86/create.sh deleted file mode 100644 index cc226e3..0000000 --- a/android-x86/create.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -e -cd "$(dirname "$0")" -. ../lib.sh - -if ! [ -f android.iso ]; then - ask_yn "android.iso not found, download?" \ - && bash ./download_isos.sh \ - || exit 1 -fi - -qemu-img create -f qcow2 hda.qcow2 10G - -qemu "$@" \ - -drive file=android.iso,media=cdrom,readonly=on - #-device usb-host,vendorid=0xffff,productid=0xffff diff --git a/android-x86/download_isos.sh b/android-x86/download_isos.sh deleted file mode 100755 index 6e7d30f..0000000 --- a/android-x86/download_isos.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -android='https://sourceforge.net/projects/android-x86/files/latest/download' - -curl -LC- -o android.iso "$android" diff --git a/android-x86/run.sh b/android-x86/run.sh index 85fc2de..ad23035 100755 --- a/android-x86/run.sh +++ b/android-x86/run.sh @@ -2,10 +2,14 @@ cd "$(dirname "$0")" . ../lib.sh +ISO=( + [android]='https://sourceforge.net/projects/android-x86/files/latest/download' +) + if ! [ -f hda.qcow2 ]; then - ask_yn "hda.qcow2 not found, create?" \ - && bash ./create.sh \ - || exit 1 + ask_yn 'hda not found, create?' || exit 1 + qemu-img create -f qcow2 hda.qcow2 10G + download_isos fi qemu "$@" \ diff --git a/arch/run.sh b/arch/run.sh index 2733ed2..2161665 100755 --- a/arch/run.sh +++ b/arch/run.sh @@ -10,7 +10,7 @@ if ! [ -f hda.qcow2 ]; then || exit 1 fi -echo -e 'User: \e[1m\e[31march:arch\e[0m' +echo "User: ${BOLD}${RED}arch:arch${NORMAL}" read -rp 'Continue? ' qemu "$@" \ diff --git a/debian12/run.sh b/debian12/run.sh index bd95292..0abc368 100755 --- a/debian12/run.sh +++ b/debian12/run.sh @@ -10,7 +10,7 @@ if ! [ -f hda.qcow2 ]; then || exit 1 fi -echo -e 'User: \e[1m\e[31mroot:\e[0m' +echo "User: ${BOLD}${RED}root:${NORMAL}" read -rp 'Continue? ' qemu "$@" \ diff --git a/lib.sh b/lib.sh index 1c24c75..3f7ac04 100644 --- a/lib.sh +++ b/lib.sh @@ -3,6 +3,10 @@ DIR="$(dirname "${BASH_SOURCE[0]}")" BRIDGE=virbr0 +NORMAL=$'\e[0m' +BOLD=$'\e[1m' +RED=$'\e[31m' + function ask_yn() { local ans @@ -14,6 +18,19 @@ function ask_yn() { esac } +declare -A ISO +declare -a OPTS +function download_isos() { + for iso in "${!ISO[@]}"; do + if ! [ -f "$iso" ] && ask_yn "download $iso?"; then + curl -LC- -o "$iso" "${ISO[$iso]}" + fi + if [ -f "$iso" ]; then + OPTS+=(-drive "file=$iso,media=cdrom,readonly=on") + fi + done +} + function _getmaxram() { local ram; ram="$(free -g | awk '/^Mem:/{print $2 - 2}')" @@ -52,6 +69,7 @@ function qemu() { -device qemu-xhci \ -object memory-backend-ram,id=mem,size=2G,share=on \ -numa node,memdev=mem \ + "${OPTS[@]}" \ "$@" ) } diff --git a/win2k22/create.sh b/win2k22/create.sh deleted file mode 100644 index 8ae279b..0000000 --- a/win2k22/create.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e -cd "$(dirname "$0")" -. ../lib.sh - -if ! [ -f win2k22.iso ] || ! [ -f virtio.iso ]; then - ask_yn "win2k22.iso and/or virtio.iso not found, download?" \ - && bash ./download_isos.sh \ - || exit 1 -fi - -qemu-img create -f qcow2 hda.qcow2 40G - -qemu "$@" \ - -drive file=win2k22.iso,media=cdrom,readonly=on \ - -drive file=virtio.iso,media=cdrom,readonly=on \ - #-device usb-host,vendorid=0xffff,productid=0xffff diff --git a/win2k22/download_isos.sh b/win2k22/download_isos.sh deleted file mode 100755 index cd55f0e..0000000 --- a/win2k22/download_isos.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -e - -win2k22='https://go.microsoft.com/fwlink/p/?LinkID=2195280' -virtio='https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso' - -curl -LC- \ - -o win2k22.iso "$win2k22" \ - -o virtio.iso "$virtio" diff --git a/win2k22/run.sh b/win2k22/run.sh index 16930d7..5b1c434 100755 --- a/win2k22/run.sh +++ b/win2k22/run.sh @@ -2,12 +2,16 @@ cd "$(dirname "$0")" . ../lib.sh +ISO=( + [win2k22]='https://go.microsoft.com/fwlink/p/?LinkID=2195280' + [virtio]='https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso' +) + if ! [ -f hda.qcow2 ]; then - ask_yn "hda.qcow2 not found, create?" \ - && bash ./create.sh \ - || exit 1 + ask_yn 'hda not found, create?' || exit 1 + qemu-img create -f qcow2 hda.qcow2 40G + download_isos fi qemu "$@" \ - -drive file=virtio.iso,media=cdrom,readonly=on \ #-device usb-host,vendorid=0xffff,productid=0xffff