refactor: General improvements to create_config function

This commit is contained in:
Liam 2024-07-11 00:00:39 -07:00 committed by Martin Wimpress
parent 113bd4d1f5
commit d3a95c2fe5
1 changed files with 15 additions and 14 deletions

View File

@ -3300,13 +3300,17 @@ function create_config() {
INPUT="$(web_redirect "${INPUT}")" INPUT="$(web_redirect "${INPUT}")"
if [[ "${INPUT}" == *".iso" ]] || [[ "${INPUT}" == *".img" ]]; then if [[ "${INPUT}" == *".iso" ]] || [[ "${INPUT}" == *".img" ]]; then
web_get "${INPUT}" "${VM_PATH}" web_get "${INPUT}" "${VM_PATH}"
INPUT="${VM_PATH}/${INPUT##*/}" INPUT="${INPUT##*/}"
else else
echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config" echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
exit 1 exit 1
fi fi
fi fi
if [[ "${INPUT}" == *".iso" ]]; then
if [ ! -f "${INPUT}" ]; then
echo "ERROR! The input must be a valid URL or path to an ISO, IMG, or QCOW2 file."
exit 1
elif [[ "${INPUT}" == *".iso" ]]; then
echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}" echo "Moving image to VM dir" && mv "${INPUT}" "${VM_PATH}"
CUSTOM_IMAGE_TYPE="iso" CUSTOM_IMAGE_TYPE="iso"
elif [[ "${INPUT}" == *".img" ]]; then elif [[ "${INPUT}" == *".img" ]]; then
@ -3319,10 +3323,15 @@ function create_config() {
echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config" echo "ERROR! Only ISO,IMG and QCOW2 file types are supported for --create-config"
exit 1 exit 1
fi fi
INPUT="$(basename "${INPUT}")"
echo "Creating custom VM config for ${INPUT##*/}." echo "Creating custom VM config for ${INPUT##*/}."
case "${INPUT,,}" in case "${INPUT,,}" in
*windows-server*) CUSTOM_OS="windows-server";; *freebsd*) CUSTOM_OS="freebsd";;
*windows*) *kolibrios*) CUSTOM_OS="kolibrios";;
*reactos*) CUSTOM_OS="reactos";;
*windows-server*|*eval_oemret_x*|*eval_x*) CUSTOM_OS="windows-server";;
*windows*|win*)
CUSTOM_OS="windows" CUSTOM_OS="windows"
while [ $# -gt 2 ]; do while [ $# -gt 2 ]; do
case "${3}" in case "${3}" in
@ -3338,18 +3347,10 @@ function create_config() {
done done
;; ;;
*freebsd*) CUSTOM_OS="freebsd";;
*kolibrios*) CUSTOM_OS="kolibrios";;
*reactos*) CUSTOM_OS="reactos";;
*) CUSTOM_OS="linux";; *) CUSTOM_OS="linux";;
esac esac
echo "Selecting OS: ${CUSTOM_OS}. If this is incorrect, please modify the config file to include the correct OS." echo -e "Selecting OS: ${CUSTOM_OS}. If this is incorrect, please modify the config file to include the correct OS.\n"
echo make_vm_config "${INPUT}" "${FIXED_ISO}"
if [ -n "${FIXED_ISO}" ]; then
make_vm_config "${INPUT}" "${FIXED_ISO}"
else
make_vm_config "${INPUT}"
fi
} }
# Use command -v command to check if quickemu is in the system's PATH and # Use command -v command to check if quickemu is in the system's PATH and