Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve quickget custom configurations, including unattended windows support #1373

Merged
merged 6 commits into from
Jul 14, 2024
137 changes: 83 additions & 54 deletions quickget
Original file line number Diff line number Diff line change
Expand Up @@ -308,51 +308,6 @@ function csv_data() {
wait
}

function create_config() {
local VM_PATH="${1}"
local INPUT="${2}"
OS="custom"
if ! mkdir "${VM_PATH}" 2>/dev/null; then
echo "ERROR! Could not create directory: ${VM_PATH}. Please verify that it does not already exist"
exit 1
fi
if [[ "${INPUT}" == "http://"* ]] || [[ "${INPUT}" == "https://"* ]]; then
INPUT="$(web_redirect "${INPUT}")"
if [[ "${INPUT}" == *".iso" ]] || [[ "${INPUT}" == *".img" ]]; then
web_get "${INPUT}" "${VM_PATH}"
INPUT="${VM_PATH}/${INPUT##*/}"
else
echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
exit 1
fi
fi
if [[ "${INPUT}" == *".iso" ]]; then
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
CUSTOM_IMAGE_TYPE="iso"
elif [[ "${INPUT}" == *".img" ]]; then
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
CUSTOM_IMAGE_TYPE="img"
elif [[ "${INPUT}" == *".qcow2" ]]; then
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}/disk.qcow2"
CUSTOM_IMAGE_TYPE="qcow2"
else
echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
exit 1
fi
echo "Creating custom VM config for ${INPUT##*/}."
case "${INPUT,,}" in
*windows-server*) CUSTOM_OS="windows-server";;
*windows*) CUSTOM_OS="windows";;
*freebsd*) CUSTOM_OS="freebsd";;
*kolibrios*) CUSTOM_OS="kolibrios";;
*reactos*) CUSTOM_OS="reactos";;
*) CUSTOM_OS="linux";;
esac
echo "Selecting OS: ${CUSTOM_OS}. If this is incorrect, please modify the config file to include the correct OS."
echo
make_vm_config "${INPUT}"
}

function list_supported() {
list_csv | cut -d ',' -f2,3,4 | tr ',' ' '
exit 0
Expand Down Expand Up @@ -2657,7 +2612,9 @@ function get_zorin() {
}

function unattended_windows() {
cat << 'EOF' > "${1}"
mkdir -p "${1}/unattended" 2>/dev/null

cat << 'EOF' > "${1}/unattended/autounattend.xml"
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
Expand Down Expand Up @@ -2939,6 +2896,15 @@ function unattended_windows() {
</settings>
</unattend>
EOF


echo "Downloading Spice drivers..."
web_get https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x64-latest.msi "${VM_PATH}/unattended"
web_get https://www.spice-space.org/download/windows/vdagent/vdagent-win-0.10.0/spice-vdagent-x64-0.10.0.msi "${VM_PATH}/unattended"
web_get https://www.spice-space.org/download/windows/usbdk/UsbDk_1.0.22_x64.msi "${VM_PATH}/unattended"

echo "Making unattended.iso"
mkisofs -quiet -l -o "${VM_PATH}/unattended.iso" "${VM_PATH}/unattended/"
}

function handle_curl_error() {
Expand Down Expand Up @@ -3248,13 +3214,7 @@ function get_windows() {
rm -f "${VM_PATH}/unattended.iso"
case ${RELEASE} in
10|11)
mkdir -p "${VM_PATH}/unattended" 2>/dev/null
web_get https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x64-latest.msi "${VM_PATH}/unattended"
web_get https://www.spice-space.org/download/windows/vdagent/vdagent-win-0.10.0/spice-vdagent-x64-0.10.0.msi "${VM_PATH}/unattended"
web_get https://www.spice-space.org/download/windows/usbdk/UsbDk_1.0.22_x64.msi "${VM_PATH}/unattended"
echo "Making unattended.iso"
unattended_windows "${VM_PATH}/unattended/autounattend.xml"
mkisofs -quiet -l -o "${VM_PATH}/unattended.iso" "${VM_PATH}/unattended/"
unattended_windows "${VM_PATH}"
;;
esac

Expand Down Expand Up @@ -3326,6 +3286,72 @@ function create_vm() {
make_vm_config "${ISO}"
}

function create_config() {
local VM_PATH="${1}"
local INPUT="${2}"
local FIXED_ISO=""

OS="custom"
if ! mkdir "${VM_PATH}" 2>/dev/null; then
echo "ERROR! Could not create directory: ${VM_PATH}. Please verify that it does not already exist"
exit 1
fi
if [[ "${INPUT}" == "http://"* ]] || [[ "${INPUT}" == "https://"* ]]; then
INPUT="$(web_redirect "${INPUT}")"
if [[ "${INPUT}" == *".iso" ]] || [[ "${INPUT}" == *".img" ]]; then
web_get "${INPUT}" "${VM_PATH}"
INPUT="${VM_PATH}/${INPUT##*/}"
lj3954 marked this conversation as resolved.
Show resolved Hide resolved
else
echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
exit 1
fi
fi
if [[ "${INPUT}" == *".iso" ]]; then
lj3954 marked this conversation as resolved.
Show resolved Hide resolved
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
CUSTOM_IMAGE_TYPE="iso"
elif [[ "${INPUT}" == *".img" ]]; then
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
CUSTOM_IMAGE_TYPE="img"
elif [[ "${INPUT}" == *".qcow2" ]]; then
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}/disk.qcow2"
CUSTOM_IMAGE_TYPE="qcow2"
else
echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
exit 1
fi
lj3954 marked this conversation as resolved.
Show resolved Hide resolved
echo "Creating custom VM config for ${INPUT##*/}."
case "${INPUT,,}" in
*windows-server*) CUSTOM_OS="windows-server";;
*windows*)
lj3954 marked this conversation as resolved.
Show resolved Hide resolved
CUSTOM_OS="windows"
while [ $# -gt 2 ]; do
case "${3}" in
-unattended|--unattended)
echo "Downloading VirtIO drivers..."
web_get "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" "${VM_PATH}"
FIXED_ISO=${VM_PATH}/virtio-win.iso

rm -f "${VM_PATH}/unattended.iso"
unattended_windows "${VM_PATH}"
shift
esac
done
;;
sudoAlphaX marked this conversation as resolved.
Show resolved Hide resolved

*freebsd*) CUSTOM_OS="freebsd";;
*kolibrios*) CUSTOM_OS="kolibrios";;
*reactos*) CUSTOM_OS="reactos";;
lj3954 marked this conversation as resolved.
Show resolved Hide resolved
*) CUSTOM_OS="linux";;
esac
echo "Selecting OS: ${CUSTOM_OS}. If this is incorrect, please modify the config file to include the correct OS."
echo
if [ -n "${FIXED_ISO}" ]; then
make_vm_config "${INPUT}" "${FIXED_ISO}"
else
make_vm_config "${INPUT}"
fi
lj3954 marked this conversation as resolved.
Show resolved Hide resolved
}

# Use command -v command to check if quickemu is in the system's PATH and
# fallback to checking if quickemu is in the current directory.
function resolve_quickemu() {
Expand Down Expand Up @@ -3363,11 +3389,14 @@ Advanced usage:

Arguments:
--download <os> <release> [edition] : Download image; no VM configuration
--create-config <os> [path/url] : Create VM config for a OS image
--create-config <os> [path/url] [flags] : Create VM config for a OS image
--open-homepage <os> : Open homepage for the OS
--show [os] : Show OS information
--version : Show version
--help : Show this help message
------------------------------------ Flags -------------------------------------
--create-config:
--unattended : Unattended windows installation
sudoAlphaX marked this conversation as resolved.
Show resolved Hide resolved
-------------------------- For testing & development ---------------------------
--url [os] [release] [edition] : Show image URL(s)
--check [os] [release] [edition] : Check image URL(s)
Expand Down
Loading