From 9276573c0235b5d85f049f9b457766181b05a041 Mon Sep 17 00:00:00 2001 From: Alpha <43486986+sudoAlphaX@users.noreply.github.com> Date: Thu, 11 Jul 2024 01:23:28 +0530 Subject: [PATCH] refactor: move create_config function to the bottom move it below unattended_windows and web_get functions to reference them later --- quickget | 95 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/quickget b/quickget index 116278d..4e6fd29 100755 --- a/quickget +++ b/quickget @@ -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 @@ -3326,6 +3281,56 @@ 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##*/}" + 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}" +} + # 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() {