Skip to content

Commit

Permalink
refactor: move create_config function to the bottom
Browse files Browse the repository at this point in the history
move it below unattended_windows and web_get functions to reference them
later
  • Loading branch information
sudoAlphaX authored and flexiondotorg committed Jul 14, 2024
1 parent 8d9c63f commit 9276573
Showing 1 changed file with 50 additions and 45 deletions.
95 changes: 50 additions & 45 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 @@ -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() {
Expand Down

0 comments on commit 9276573

Please sign in to comment.