#!/usr/bin/env bash # SC2317: Command appears to be unreachable. Check usage (or ignore if invoked indirectly). # - https://www.shellcheck.net/wiki/SC2317 # - Disable globally because many functions are called indirectly # shellcheck disable=SC2317 # shellcheck source=lib.sh SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-$0}")")" source "${SCRIPT_DIR}/lib.sh" # Load DistroHopper user config so qget honors RAMDISK / ISO_DIR settings if [ -f "${HOME}/.config/dh/config" ]; then # shellcheck source=/dev/null . "${HOME}/.config/dh/config" fi # Latest cherrypick (or not) commit. Start from here... # https://github.com/quickemu-project/quickemu/tree/3da9edc9953340622db23be4661aefa4cd0632f2 export TEXTDOMAIN=qget # Locale translation support (replaces deprecated $"..." syntax). RESOURCE_DIR="${APPDIR:-${SCRIPT_DIR}}" export PUBLIC_DIR="${PUBLIC_DIR:-${RESOURCE_DIR}/public}" TEMPLATES_DIR="${TEMPLATES_DIR:-${RESOURCE_DIR}/templates}" # Fall back to templates when generated public/ metadata is unavailable. if [ "${DH_USE_TEMPLATES:-no}" != "yes" ] && [ ! -d "${PUBLIC_DIR}" ] && [ -d "${TEMPLATES_DIR}" ]; then export DH_USE_TEMPLATES="yes" fi if [[ -n $Q_DEBUG ]]; then export TEXTDOMAINDIR="${PWD}/locale" else export TEXTDOMAINDIR=/usr/share/locale fi qgetVersion="0.9" function cleanup() { if [ -n "$(jobs -p)" ]; then kill "$(jobs -p)" 2>/dev/null fi } function detect_capabilities() { # Support sixel (zellij) HAS_CHAFA=0 HAS_NERD_FONT=0 command -v chafa >/dev/null && HAS_CHAFA=1 if command -v fc-match &>/dev/null; then fc-match monospace 2>/dev/null | grep -qi 'nerd\|NF' && HAS_NERD_FONT=1 fi [[ -n "${KITTY_WINDOW_ID}" || "${TERM}" == "xterm-kitty" || -n "${WEZTERM_PANE}" ]] && HAS_NERD_FONT=1 } function show_os_info() { local os="${1}" requested_arch="${2:-}" requested_release="${3:-}" if ! dh_load_os "${os}"; then echo "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED" "${os}")" >&2 return 1 fi if [ -n "${requested_arch}" ]; then ARCH=$(_upstream_to_qarch "${requested_arch}") if [[ $(type -t arch_) == function ]] && ! arch_ | tr ' ' '\n' | grep -Fxq "${ARCH}"; then local supported_arches="${QEMU_ARCH:-}" [[ $(type -t arch_) == function ]] && supported_arches=$(arch_) echo "ERROR! ${ARCH} is not a supported ${PRETTY} architecture." echo "Supported architectures: ${supported_arches:-not declared}." return 1 fi # The releases and editions of the selected architecture. # Edition queries already name a discovered release. In live mode, # do not rescan/probe the entire upstream archive for every query. if [ -n "${requested_release}" ] && [ "${DH_USE_TEMPLATES:-no}" == yes ]; then RELEASES="${requested_release}" else RELEASES="$(dh_releases "${ARCH}")" fi if [ -n "${requested_release}" ]; then EDITIONS="$(dh_editions "${requested_release}" "${ARCH}")" else EDITIONS="$(dh_editions "" "${ARCH}")" fi else if [ -n "${requested_release}" ] && [ "${DH_USE_TEMPLATES:-no}" == yes ]; then RELEASES="${requested_release}" else RELEASES="$(dh_releases "")" fi EDITIONS="$(dh_editions "${requested_release}")" fi [ "${os}" == "bedrock-linux" ] && EDITIONS="${EDITIONS} prepared" # The architecture list: the static value, or the template's arch_(). if [[ $(type -t arch_) == function ]]; then QEMU_ARCH="$(arch_)" fi # The editions one per line. An edition can contain a space (e.g. # "Brazilian Portuguese"), so the space separated EDITIONS value cannot # be split apart again — this list can. local _editions_list="" if [ "${QGET_PLAIN:-}" == "1" ]; then if [ -z "${requested_arch}${requested_release}" ] && [ -n "${EDITIONS_LIST:-}" ]; then _editions_list="${EDITIONS_LIST}" elif [[ "${EDITIONS}" == *$'\n'* ]] || { [ -n "${EDITIONS}" ] && printf '%s\n' "${EDITIONS_LIST:-}" | grep -Fxq "${EDITIONS}"; }; then _editions_list="${EDITIONS}" elif [ -n "${EDITIONS_LIST:-}" ]; then # Scoped static metadata is space-joined. Recover its entries using # the lossless global list, preferring the longest matching name. local remaining="${EDITIONS}" candidate best while [ -n "$remaining" ]; do best="" while IFS= read -r candidate; do [ -n "$candidate" ] || continue if [[ "$remaining" == "$candidate" || "$remaining" == "$candidate "* ]]; then ((${#candidate} > ${#best})) && best="$candidate" fi done <<< "$EDITIONS_LIST" # Compatibility with old metadata missing a global-list entry. [ -n "$best" ] || best="${remaining%% *}" _editions_list+="${_editions_list:+$'\n'}${best}" remaining="${remaining#"$best"}" remaining="${remaining# }" done else # Template edition functions commonly return a space-separated list. _editions_list=$(printf '%s\n' "${EDITIONS}" | tr ' ' '\n' | awk 'NF') fi else _editions_list="${EDITIONS}" fi detect_capabilities echo echo " ${PRETTY}" if [[ "${HAS_CHAFA}" == "1" ]] && [[ -f "icons/${ICON}" ]]; then chafa -s 5x5 "icons/${ICON}" fi local cols cols=$(tput cols 2>/dev/null || echo 80) # The plain output is meant to be parsed by other programs: every value # stays on a single line, so a long release or edition list is never # wrapped and truncated. The default output is wrapped for humans. local _wrap=1 if [ "${QGET_PLAIN:-}" == "1" ]; then _wrap=0 # Discovery functions may return one value per line. Plain scalar # fields must really be single-line or front-ends lose all but the # first value. The lossless edition list was captured above. RELEASES=$(printf '%s\n' "$RELEASES" | awk '{$1=$1; if (NF) {printf "%s%s", sep, $0; sep=" "}}') QEMU_ARCH=$(printf '%s\n' "$QEMU_ARCH" | awk '{$1=$1; if (NF) {printf "%s%s", sep, $0; sep=" "}}') EDITIONS=$(printf '%s\n' "$EDITIONS" | awk '{$1=$1; if (NF) {printf "%s%s", sep, $0; sep=" "}}') fi if [ -n "${requested_arch}" ]; then echo "$(printf -- "$MSG_CATEGORY" "${CATEGORY}")" echo "$(printf -- "$MSG_BASED_OF" "${BASEDOF}")" echo "$(printf -- "$MSG_WEBSITE" "${HOMEPAGE}")" echo "$(printf -- "$MSG_CREDENTIALS" "${CREDENTIALS}")" [ -n "${QEMU_ARCH}" ] && echo "$(printf -- "$MSG_ARCHS" "${QEMU_ARCH}")" echo "$(printf -- "$MSG_RELEASES" "${RELEASES}")" [ -n "${EDITIONS}" ] && echo "$(printf -- "$MSG_EDITIONS" "${EDITIONS}")" else echo "$(printf -- "$MSG_CATEGORY" "${CATEGORY}")" echo "$(printf -- "$MSG_BASED_OF" "${BASEDOF}")" echo "$(printf -- "$MSG_WEBSITE" "${HOMEPAGE}")" echo "$(printf -- "$MSG_CREDENTIALS" "${CREDENTIALS}")" if [ "${_wrap}" -eq 1 ]; then [ -n "${QEMU_ARCH}" ] && echo "$(printf -- "$MSG_ARCHS" "${QEMU_ARCH}")" | fmt -w "$cols" echo "$(printf -- "$MSG_RELEASES" "${RELEASES}")" | fmt -w "$cols" if [ -n "${EDITIONS}" ]; then if [ "${os}" == "bedrock-linux" ]; then echo "$(printf -- "$MSG_EDITIONS" "${EDITIONS}")" else echo "$(printf -- "$MSG_EDITIONS" "${EDITIONS}")" | fmt -w "$cols" fi fi else [ -n "${QEMU_ARCH}" ] && echo "$(printf -- "$MSG_ARCHS" "${QEMU_ARCH}")" echo "$(printf -- "$MSG_RELEASES" "${RELEASES}")" [ -n "${EDITIONS}" ] && echo "$(printf -- "$MSG_EDITIONS" "${EDITIONS}")" # The editions one per line, for the front-ends to pick from. # It is the last field of the plain output, so it runs to the # end of the output. [ -n "${_editions_list}" ] && printf 'EditionsList:\n%s\n' "${_editions_list}" fi fi if [ "${QGET_PLAIN:-}" == "1" ]; then if [ -n "${requested_arch}" ]; then [ -n "${_editions_list}" ] && printf 'EditionsList:\n%s\n' "${_editions_list}" fi [ -n "${RSS}" ] && echo "$(printf -- "$MSG_RSS" "${RSS}")" [ -n "${DW}" ] && echo "$(printf -- "$MSG_DISTROWATCH" "${DW}")" echo "$(printf -- "$MSG_DESCRIPTION" "${DESCRIPTION}")" return 0 fi [ -n "${RSS}" ] && echo "$(printf -- "$MSG_RSS" "${RSS}")" [ -n "${DW}" ] && echo "$(printf -- "$MSG_DISTROWATCH" "${DW}")" echo "$(printf -- "$MSG_DESCRIPTION" "${DESCRIPTION}")" rosette_info "${os}" } function os_support() { local dir file filename local seen="" # Match listing sources to the selected mode. local dirs=() if [ "${DH_USE_TEMPLATES:-no}" == "yes" ]; then dirs=("${TEMPLATES_DIR}") elif [ "${DH_FORCE_PUBLIC:-no}" == "yes" ]; then dirs=("${PUBLIC_DIR}") else # Auto mode: union so a missing public file does not hide a distro. dirs=("${PUBLIC_DIR}" "${TEMPLATES_DIR}") fi for dir in "${dirs[@]}"; do [ -d "$dir" ] || continue for file in "$dir"/*; do [ -f "$file" ] || continue [[ "$file" =~ tmp_ ]] && continue filename="${file##*/}" case " ${seen} " in *" ${filename} "*) continue ;; esac seen="${seen} ${filename}" echo "$filename" done done } function error_specify_os() { echo "$(printf -- "$MSG_ERROR_YOU_MUST_SPECIFY_AN")" echo "$(printf -- "$MSG_SUPPORTED_OPERATING_SYSTEMS")" os_support | fmt -w $(tput cols) echo -e "$(printf -- "$MSG_NTO_SEE_ALL_POSSIBLE_ARGUMENTS")" exit 1 } function os_supported() { #if [[ ! "$(os_support)" =~ ${OS} ]]; then if [[ ! $'\n'"$(os_support)"$'\n' =~ $'\n'"${OS}"$'\n' ]]; then echo -e "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_2" "${OS}")" # Say where we looked, otherwise an exported PUBLIC_DIR pointing at a # stale/other checkout is indistinguishable from a missing template. echo -e "Looked in: ${PUBLIC_DIR} (qget: ${BASH_SOURCE[0]:-$0})\n" if [[ -f "${SCRIPT_DIR}/public/${OS}" ]]; then echo -e "$(printf -- "$MSG_NOTE_EXISTS_IN_THIS_CHECKOUT" "${OS}" "${SCRIPT_DIR}" "${OS}")" echo -e "$(printf -- "$MSG_BUT_PUBLIC_DIR_POINTS_ELSEWHERE")" fi os_support | fmt -w $(tput cols 2>/dev/null || echo 80) exit 1 fi } function error_specify_release() { dh_load_os "${OS}" local cols cols=$(tput cols 2>/dev/null || echo 80) echo -e "\nERROR! You must specify a release for ${PRETTY:-${OS}}." echo "$(printf -- "$MSG_RELEASES" "${RELEASES}")" | fmt -w "$cols" if [ -n "${EDITIONS}" ]; then echo "$(printf -- "$MSG_EDITIONS" "${EDITIONS}")" | fmt -w "$cols" fi exit 1 } function error_not_supported_release() { #if [[ ! "${RELEASES[*]}" =~ ${RELEASE} ]]; then if [[ ! " ${RELEASES} " =~ " ${RELEASE} " ]]; then echo -e "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_3" "${DISPLAY_NAME}" "${RELEASE}")" echo -n $' - Supported releases: ' echo "${RELEASES}" exit 1 fi } function error_not_supported_arch() { echo -e "$(printf -- "$MSG_ERROR_DOES_NOT_SUPPORT_THE" "${PRETTY}" "${ARCH}")" echo -n $' - Supported architectures: ' local SUPPORTED_ARCHS SUPPORTED_ARCHS="$(arch_ 2>/dev/null)" [ -n "${SUPPORTED_ARCHS}" ] && echo "${SUPPORTED_ARCHS}" || echo "(none declared)" echo "$(printf -- "$MSG_INSPECT_ARCHITECTURE_SPECIFIC_CHOICES_WI" "${ARCH}" "${OS}")" exit 1 } # Validate an explicitly requested --arch against the OS arch_() list. # Called only when the user passed --arch, so the host-default arch can never # hard-fail an amd64-only OS on an arm64 host. function validate_arch() { [ "${ARCH_EXPLICIT}" == "yes" ] || return 0 declare -F arch_ &>/dev/null || return 0 local SUPPORTED_ARCHS SUPPORTED_ARCHS="$(arch_ 2>/dev/null)" [ -n "${SUPPORTED_ARCHS}" ] || return 0 if [[ ! " ${SUPPORTED_ARCHS} " =~ " ${ARCH} " ]]; then error_not_supported_arch fi } function error_not_supported_lang() { echo -e "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_4" "${I18N}" "${PRETTY}")" echo -n $' - Editions: ' for I18N in "${I18NS[@]}"; do echo -n "${I18N} " done exit 1 } function error_not_supported_argument() { echo "$(printf -- "$MSG_ERROR_NOT_SUPPORTED_ARGUMENT")" echo "$(printf -- "$MSG_TO_SEE_ALL_POSSIBLE_ARGUMENTS")" echo "$(printf -- "$MSG_QGET_H_OR_QGET_HELP")" exit 1 } function error_unable_to_create_dir() { echo "$(printf -- "$MSG_ERROR_UNABLE_TO_CREATE_DIRECTORY" "${DIR}")" exit 1 } function error_not_supported_image() { echo "$(printf -- "$MSG_ERROR_ONLY_ISO_IMG_AND")" exit 1 } function is_valid_language() { local I18N="" local PASSED_I18N="${1}" for I18N in "${I18NS[@]}"; do if [[ "${I18N}" == "${PASSED_I18N}" ]]; then return 0 fi done return 1 } function handle_missing() { # Handle odd missing Fedora combinations case "${OS}" in fedora-linux) # First we need to handle the Beta naming kludge if [[ "${RELEASE}" == *"_Beta" ]]; then NRELEASE="${RELEASE/_Beta/}" else NRELEASE="${RELEASE}" fi if [[ "${NRELEASE}" -lt 40 && "${EDITION}" == "Onyx" ]] || [[ "${NRELEASE}" -lt 40 && "${EDITION}" == "Sericea" ]]; then echo "$(printf -- "$MSG_ERROR_UNSUPPORTED_COMBINATION")" echo "$(printf -- "$MSG_FEDORA_IS_NOT_AVAILABLE_PLEASE" "${RELEASE}" "${EDITION}")" exit 1 fi ;; esac } function validate_release() { local DISPLAY_NAME="" local RELEASE_GENERATOR="${1}" # The list is kept in the global RELEASES, which is what # error_not_supported_release reports. DISPLAY_NAME="${PRETTY}" # The static release list of the selected architecture, or the live one # from the template when running in template mode. RELEASES="$(dh_releases "${ARCH}")" if [ -z "${RELEASES}" ] && [[ $(type -t "${RELEASE_GENERATOR}") == function ]]; then RELEASES="$(${RELEASE_GENERATOR})" fi error_not_supported_release } function bedrock_base_values() { local BASE_OS="${1}" local VALUE_TYPE="${2}" ( dh_load_os "bedrock-linux" case "${VALUE_TYPE}" in releases) _base_releases_ "${BASE_OS}";; editions) _base_editions_ "${BASE_OS}";; esac ) } function bedrock_choose_value() { local LABEL="${1}" local OPTIONS="${2}" local CHOICE="" if command -v gum >/dev/null && [ -t 0 ]; then CHOICE=$(printf '%s\n' ${OPTIONS} | gum filter --header="${LABEL}") elif command -v fzf >/dev/null && [ -t 0 ]; then CHOICE=$(printf '%s\n' ${OPTIONS} | fzf --prompt="${LABEL} ") elif command -v yad >/dev/null && [ -n "${DISPLAY:-}" ]; then local OPTIONS_FMT="${OPTIONS// /!}" CHOICE=$(yad --form --title="Bedrock base selection" \ --field="${LABEL}:CB" "${OPTIONS_FMT}" \ --button="Select:0" --button="Cancel:1" | cut -d'|' -f1) else return 1 fi [ -n "${CHOICE}" ] || return 1 printf '%s\n' "${CHOICE}" } function bedrock_vm_config_value() { local VM_CONF="${1}" local KEY="${2}" awk -v key="${KEY}" ' { line=$0 sub(/^[[:space:]]*/, "", line) split(line, fields, "=") if (fields[1] == key) { value=substr(line, index(line, "=") + 1) sub(/^[[:space:]]+/, "", value) sub(/[[:space:]]+$/, "", value) if (value ~ /^".*"$/) value=substr(value, 2, length(value) - 2) print value exit } } ' "${VM_CONF}" } function bedrock_vm_disk_path() { local VM_CONF="${1}" local DISK_PATH="" DISK_PATH=$(bedrock_vm_config_value "${VM_CONF}" disk_img) [ -z "${DISK_PATH}" ] && DISK_PATH="$(dirname "${VM_CONF}")/disk.qcow2" [[ "${DISK_PATH}" != /* ]] && DISK_PATH="$(dirname "${VM_CONF}")/${DISK_PATH}" printf '%s\n' "${DISK_PATH}" } function bedrock_vm_config_is_usable() { local VM_CONF="${1}" local GUEST="" local VM_ARCH="" local DISK_PATH="" GUEST=$(bedrock_vm_config_value "${VM_CONF}" guest_os) [ "${GUEST}" == "linux" ] || return 1 VM_ARCH=$(bedrock_vm_config_value "${VM_CONF}" arch) case "${VM_ARCH:-x86_64}" in x86_64|amd64) VM_ARCH="amd64";; aarch64|arm64) VM_ARCH="arm64";; *) return 1;; esac [ "${VM_ARCH}" == "${ARCH}" ] || return 1 DISK_PATH=$(bedrock_vm_disk_path "${VM_CONF}") [ -f "${DISK_PATH}" ] } function bedrock_choose_existing_vm() { local VM_DIR="${VMS_DIR:-$PWD}" local VM_CONF="" local CHOICE="" local VM_OPTIONS="" local -a VM_CONFIGS=() local -a VM_NAMES=() while IFS= read -r -d '' VM_CONF; do [[ "$(basename "${VM_CONF}")" == bedrock-*.conf ]] && continue bedrock_vm_config_is_usable "${VM_CONF}" || continue VM_CONFIGS+=("${VM_CONF}") VM_NAMES+=("$(basename "${VM_CONF}")") done < <(find "${VM_DIR}" -maxdepth 1 -type f -name '*.conf' -print0 2>/dev/null) if [ "${#VM_CONFIGS[@]}" -eq 0 ]; then echo "$(printf -- "$MSG_ERROR_NO_PREPARED_LINUX_VM" "${VM_DIR}")" >&2 return 1 fi if command -v gum >/dev/null && [ -t 0 ]; then CHOICE=$(printf '%s\n' "${VM_NAMES[@]}" | gum filter --header="Select prepared Linux VM:") elif command -v fzf >/dev/null && [ -t 0 ]; then CHOICE=$(printf '%s\n' "${VM_NAMES[@]}" | fzf --prompt="Select prepared Linux VM: ") elif command -v yad >/dev/null && [ -n "${DISPLAY:-}" ]; then local IFS='!' VM_OPTIONS="${VM_NAMES[*]}" CHOICE=$(yad --form --title="Bedrock base selection" \ --field="Select prepared Linux VM (.conf):CB" "${VM_OPTIONS}" \ --button="Select:0" --button="Cancel:1" | cut -d'|' -f1) else echo "$(printf -- "$MSG_ERROR_SELECT_A_PREPARED_VM")" >&2 return 1 fi [ -n "${CHOICE}" ] || return 1 for ((i = 0; i < ${#VM_NAMES[@]}; i++)); do if [ "${VM_NAMES[$i]}" == "${CHOICE}" ]; then printf '%s\n' "${VM_CONFIGS[$i]}" return 0 fi done return 1 } function create_bedrock_from_vm() { if [ "${OPERATION}" == "download" ]; then echo "$(printf -- "$MSG_ERROR_A_PREPARED_VM_BASE")" >&2 exit 1 fi local VM_CONF="${BASE_VM_CONF:-}" local BASE_NAME="" local BASE_DISK="" local PID_FILE="" local PID="" local DISK_PATH="" local DISK_QUOTED="" [ -n "${VM_CONF}" ] || VM_CONF=$(bedrock_choose_existing_vm) || exit 1 if [[ "${VM_CONF}" != /* && ! -f "${VM_CONF}" && -f "${VMS_DIR:-$PWD}/${VM_CONF}" ]]; then VM_CONF="${VMS_DIR:-$PWD}/${VM_CONF}" fi if [ ! -f "${VM_CONF}" ] || ! bedrock_vm_config_is_usable "${VM_CONF}"; then echo "$(printf -- "$MSG_ERROR_IS_NOT_A_PREPARED" "${VM_CONF}" "${ARCH}")" >&2 exit 1 fi BASE_DISK=$(bedrock_vm_disk_path "${VM_CONF}") BASE_NAME=$(basename "${VM_CONF}" .conf) PID_FILE="$(dirname "${BASE_DISK}")/${BASE_NAME}.pid" if [ -r "${PID_FILE}" ]; then read -r PID < "${PID_FILE}" if [[ "${PID}" =~ ^[0-9]+$ ]] && kill -0 "${PID}" 2>/dev/null; then echo "$(printf -- "$MSG_ERROR_STOP_BEFORE_USING_IT" "${BASE_NAME}")" >&2 exit 1 fi fi command -v qemu-img >/dev/null 2>&1 || { echo "$(printf -- "$MSG_ERROR_QEMU_IMG_IS_REQUIRED")" >&2 exit 1 } local TARGET_NAME TARGET_NAME=$(printf '%s' "${BASE_NAME}" | tr -cs '[:alnum:]._+-' '-') TARGET_NAME="${TARGET_NAME#-}" TARGET_NAME="${TARGET_NAME%-}" VM_PATH="${OS}-${RELEASE}-prepared-${TARGET_NAME}$(arch_suffix)" check_vm_folder_name "${VM_PATH}" if [ -e "${VM_PATH}.conf" ] || [ -e "${VM_PATH}" ]; then echo "$(printf -- "$MSG_ERROR_ALREADY_EXISTS_REFUSING_TO" "${VM_PATH}")" >&2 exit 1 fi mkdir "${VM_PATH}" || exit 1 echo "$(printf -- "$MSG_COPYING_PREPARED_VM_DISK_FROM" "${BASE_NAME}")" if ! qemu-img convert -p -O qcow2 "${BASE_DISK}" "${VM_PATH}/disk.qcow2"; then rm -f "${VM_PATH}/disk.qcow2" rmdir "${VM_PATH}" 2>/dev/null echo "$(printf -- "$MSG_ERROR_COULD_NOT_COPY_PREPARED")" >&2 exit 1 fi DISK_PATH="$(realpath "${VM_PATH}/disk.qcow2")" printf -v DISK_QUOTED '%q' "${DISK_PATH}" local ARCH_LINE="" if [ -n "${ARCH:-}" ] && [ "${ARCH}" != "amd64" ]; then ARCH_LINE="arch=\"$(_qarch_to_upstream "${ARCH}")\"" fi CONF_FILE="${VM_PATH}.conf" cat > "${CONF_FILE}" </dev/null && config_ if [ -n "${QGET_DEFAULT_VM_CONFIG:-}" ] && [ -f "${QGET_DEFAULT_VM_CONFIG}" ]; then cat "${QGET_DEFAULT_VM_CONFIG}" >> "${CONF_FILE}" fi BASE_OS="prepared" BASE_RELEASE="${BASE_NAME}" BASE_EDITION="" extract_ echo "$(printf -- "$MSG_BEDROCK_VM_CONFIG_CREATED" "${CONF_FILE}")" } function select_bedrock_base() { local BASE_RELEASES="" local BASE_EDITIONS="" BASE_RELEASES=$(bedrock_base_values "${BASE_OS}" releases | xargs) if [ -z "${BASE_RELEASES}" ]; then echo "$(printf -- "$MSG_ERROR_COULD_NOT_FIND_RELEASES" "${BASE_OS}")" >&2 exit 1 fi if [ -z "${BASE_RELEASE}" ]; then BASE_RELEASE=$(bedrock_choose_value "Select ${BASE_OS} base release:" "${BASE_RELEASES}") || { echo "$(printf -- "$MSG_ERROR_SPECIFY_THE_BASE_RELEASE" "${BASE_OS}")" >&2 echo "$(printf -- "$MSG_SUPPORTED_RELEASES" "${BASE_RELEASES}")" >&2 exit 1 } fi if [[ ! " ${BASE_RELEASES} " == *" ${BASE_RELEASE} "* ]]; then echo "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_5" "${BASE_RELEASE}" "${BASE_OS}")" >&2 echo "$(printf -- "$MSG_SUPPORTED_RELEASES" "${BASE_RELEASES}")" >&2 exit 1 fi BASE_EDITIONS=$(bedrock_base_values "${BASE_OS}" editions | xargs) if [ -n "${BASE_EDITIONS}" ]; then if [ -z "${BASE_EDITION}" ]; then BASE_EDITION=$(bedrock_choose_value "Select ${BASE_OS} ${BASE_RELEASE} edition:" "${BASE_EDITIONS}") || { echo "$(printf -- "$MSG_ERROR_SPECIFY_THE_BASE_EDITION" "${BASE_OS}")" >&2 echo "$(printf -- "$MSG_SUPPORTED_EDITIONS" "${BASE_EDITIONS}")" >&2 exit 1 } fi if [[ ! " ${BASE_EDITIONS} " == *" ${BASE_EDITION} "* ]]; then echo "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_6" "${BASE_EDITION}" "${BASE_OS}")" >&2 echo "$(printf -- "$MSG_SUPPORTED_EDITIONS" "${BASE_EDITIONS}")" >&2 exit 1 fi elif [ -n "${BASE_EDITION}" ]; then echo "$(printf -- "$MSG_ERROR_DOES_NOT_HAVE_BASE" "${BASE_OS}")" >&2 exit 1 fi } function list_json() { # Reference: https://stackoverflow.com/a/67359273 list_csv | jq -R 'split(",") as $h|reduce inputs as $in ([]; . += [$in|split(",")|. as $a|reduce range(0,length) as $i ({};.[$h[$i]]=$a[$i])])' exit 0 } function list_csv() { CSV_DATA="$(csv_data)" echo "Display Name,OS,Release,Option,Downloader,PNG,SVG" sort -t',' -k2,2 <<<"${CSV_DATA}" exit 0 } list_isos() { local URL local FUNC local OPTION local OS echo "OS|Release|Edition|URL" for OS in $(os_support); do dh_load_os "${OS}" for RELEASE in $(releases_ | sed -Ee 's/eol-\S+//g' ); do # hide eol releases # If the OS has an editions_() function, use it. if [[ $(type -t editions_) == function ]]; then for OPTION in $(editions_); do URL=$("$0" --url "${OS}" "${RELEASE}" "${OPTION}" 2>/dev/null | head -1) if [ -z "${URL}" ]; then echo "${OS}|${RELEASE}|${OPTION}|${URL}" else echo "${OS}|${RELEASE}|${OPTION}|${URL}" fi done elif [[ "${OS}" == "windows"* ]] && [[ $(type -t languages_) == function ]]; then languages_ for OPTION in "${I18NS[@]}"; do #URL=$(./qget -u ${OS} ${RELEASE} ${OPTION}) echo "${OS}|${RELEASE}|${OPTION}|" done elif [[ "${OS}" == "macos" ]]; then echo "${OS}|${RELEASE}||" else URL=$("$0" --url "${OS}" "${RELEASE}" 2>/dev/null | head -1) echo "${OS}|${RELEASE}||${URL}" fi done done exit 0 } function csv_data() { local DISPLAY_NAME local DL="" local DOWNLOADER local FUNC local OPTION local OS local PNG local RELEASE local SVG local HAS_ZSYNC=0 local OSNAME local PRETTY local ICON local CATEGORY local BASEDOF local HOMEPAGE local CREDENTIALS local DESCRIPTION # Check if zsync is available if command -v zsync &>/dev/null; then HAS_ZSYNC=1 fi for OS in $(os_support); do dh_load_os "${OS}" DISPLAY_NAME="${PRETTY}" SVG="" PNG="" if [[ "${ICON}" == *.svg ]]; then SVG="https://dh.osowoso.org/icons/${ICON}" elif [[ "${ICON}" == *.png ]]; then PNG="https://dh.osowoso.org/icons/${ICON}" else PNG="-" fi # The editions of this distro. EDITIONS is set by dh_load_os from the # generated metadata; do not shadow it with a local variable. local EDITIONS_LIST="" if [[ $(type -t editions_) == function ]] || [ -n "${EDITIONS:-}" ]; then EDITIONS_LIST=$(dh_editions "") fi for RELEASE in $(dh_releases ""); do if [[ "${OS}" == *"ubuntu"* ]] && [[ ${RELEASE} == *"daily"* ]] && [ ${HAS_ZSYNC} -eq 1 ]; then DOWNLOADER="zsync" else DOWNLOADER="${DL}" fi # Editions may depend on the release (kde-neon, fedora-linux, zorin), so # re-evaluate them for the release currently being listed. local RELEASE_EDITIONS="${EDITIONS_LIST}" if [[ $(type -t editions_) == function ]] || [ -n "${EDITIONS:-}" ]; then RELEASE_EDITIONS=$(dh_editions "${RELEASE}" "${ARCH:-}") fi # If the OS has an editions_() function, use it. if [[ ${RELEASE_EDITIONS} ]]; then for OPTION in ${RELEASE_EDITIONS}; do echo "${DISPLAY_NAME},${OS},${RELEASE},${OPTION},${DOWNLOADER},${PNG},${SVG}" done elif [[ "${OS}" == "windows"* ]] && [[ $(type -t languages_) == function ]]; then languages_ for I18N in "${I18NS[@]}"; do echo "${DISPLAY_NAME},${OS},${RELEASE},${I18N},${DOWNLOADER},${PNG},${SVG}" done else echo "${DISPLAY_NAME},${OS},${RELEASE},,${DOWNLOADER},${PNG},${SVG}" fi done & done wait } # list_supported — output "OS RELEASE EDITION" rows. # Defined once, after list_csv/csv_data, so the CSV pipeline stays the single # source of truth for the distro metadata. function list_supported() { # The CSV row is "OS,RELEASE,EDITION,...". An empty edition must stay # empty — turning it into "-" would print a placeholder that is not a # real edition. list_csv | tail -n +2 | cut -d ',' -f2,3,4 | while IFS= read -r row; do printf '%s\n' "${row//,/$'\t'}" | tr '\t' ' ' done exit 0 } function list_by_category() { local filter="${1,,}" local OSNAME="" CATEGORY="" for f in "${PUBLIC_DIR}"/*; do [ -f "$f" ] || continue OSNAME="" CATEGORY="" eval "$(grep -E '^(OSNAME|CATEGORY)=' "$f" | head -2)" [ -z "$OSNAME" ] && continue echo "${CATEGORY,,}" | grep -qi "${filter}" && echo "$OSNAME" done exit 0 } function test_result() { local OS="${1}" local RELEASE="${2}" local EDITION="${3:-}" local URL="${4:-}" local RESULT="${5:-}" if [ -n "${EDITION}" ]; then OS="${OS}-${RELEASE}-${EDITION}" else OS="${OS}-${RELEASE}" fi if [ -n "${RESULT}" ]; then # Pad the OS string for consistent output OS=$(printf "%-35s" "${OS}") echo -e "${RESULT}: ${OS} ${URL}" else OS=$(printf "%-36s" "${OS}:") echo -e "${OS} ${URL}" fi } function test_all() { OS="${1}" os_supported # A release and an edition may be given before the call; when they # are, only that combination is tested. local WANT_RELEASE="${RELEASE:-}" local WANT_EDITION="${EDITION:-}" local CHECK="" local FUNC="${OS}" if [[ "${OS}" == *ubuntu* && "${OS}" != "ubuntu-server" ]]; then FUNC="ubuntu" fi local URL="" dh_load_os "${OS}" local TEST_RELEASES if [ -n "${WANT_RELEASE}" ]; then TEST_RELEASES="${WANT_RELEASE}" else TEST_RELEASES="$(dh_releases "${ARCH}")" if [ -z "${TEST_RELEASES}" ] && [[ $(type -t releases_) == function ]]; then TEST_RELEASES="$(releases_)" fi fi for RELEASE in ${TEST_RELEASES}; do dh_load_os "${OS}" if [ "${OS}" == 'rebornos' ]; then if curl -I "https://cdn.soulharsh007.dev/RebornOS-ISO/${ISO}"; then test_result "${OS} ${RELEASE} ${URL} PASS" else test_result "${OS} ${RELEASE} ${URL} FAIL" fi elif [[ $(type -t editions_) == function ]] || [ -n "${EDITIONS:-}" ]; then dh_load_os "${OS}" local TEST_EDITIONS TEST_EDITIONS="$(dh_editions "${RELEASE}" "${ARCH}")" if [ -n "${WANT_EDITION}" ]; then TEST_EDITIONS="${WANT_EDITION}" fi for EDITION in ${TEST_EDITIONS}; do validate_release releases_ local GET_OUT GET_STATUS GET_OUT="$(get_ 2>/dev/null)" GET_STATUS=$? URL="$(printf '%s' "${GET_OUT}" | cut -d' ' -f1 | head -n 1)" if [ "${GET_STATUS}" -ne 0 ]; then # get_ failed outright: report as a failure, not a skip. if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "" elif [ "${OPERATION}" == "test" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "" "FAIL" fi continue fi if [ -z "${URL}" ]; then # The distro template signals "not available" by # returning no URL; treat that as a skip, not a failure. if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "" elif [ "${OPERATION}" == "test" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "" "SKIP" fi continue fi if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" elif [ "${OPERATION}" == "test" ]; then CHECK=$(web_check "${URL}" && echo "PASS" || echo "FAIL") test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" "${CHECK}" fi done elif [[ "${OS}" == "windows"* ]]; then dh_load_os "${OS}" languages_ for I18N in "${I18NS[@]}"; do validate_release releases_ if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${I18N}" "" elif [ "${OPERATION}" == "test" ]; then test_result "${OS}" "${RELEASE}" "${I18N}" "${URL}" "SKIP" fi done elif [[ "${OS}" == "macos" ]]; then validate_release releases_ (get_) elif [ "${OS}" == "ubuntu-server" ]; then validate_release releases_ (get_) elif [[ "${OS}" == *ubuntu* ]]; then validate_release releases_ (get_) else validate_release releases_ URL=$(get_ | cut -d' ' -f1 | head -n 1) if [ "${OPERATION}" == "show" ]; then test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" elif [ "${OPERATION}" == "test" ]; then CHECK=$(web_check "${URL}" && echo "PASS" || echo "FAIL") test_result "${OS}" "${RELEASE}" "${EDITION}" "${URL}" "${CHECK}" fi fi done } # Verify a detached GPG signature against a file. # KEY_SOURCE: fingerprint → fetched from keyserver; https://... → downloaded. function check_signature() { local iso="$1" local sig="$2" local key_id="${3:-${GPG:-}}" if ! command -v gpg &>/dev/null; then echo "$(printf -- "$MSG_WARNING_GPG_NOT_FOUND_SKIPPING")" return 1 fi printf '%s' "$(printf -- "$MSG_CHECKING_GPG_SIGNATURE_FOR" "${iso}")" local GPG_HOME GPG_HOME=$(mktemp -d) chmod 700 "${GPG_HOME}" local import_ok=0 if [[ "${key_id}" =~ ^https?:// ]]; then local kf kf=$(mktemp) curl --disable --silent --location -o "${kf}" "${key_id}" 2>/dev/null \ && GNUPGHOME="${GPG_HOME}" gpg --quiet --import "${kf}" 2>/dev/null \ && import_ok=1 rm -f "${kf}" elif [ -n "${key_id}" ]; then GNUPGHOME="${GPG_HOME}" gpg --quiet \ --keyserver hkps://keys.openpgp.org --recv-keys "${key_id}" 2>/dev/null \ || GNUPGHOME="${GPG_HOME}" gpg --quiet \ --keyserver hkps://keyserver.ubuntu.com --recv-keys "${key_id}" 2>/dev/null import_ok=1 fi if [ "${import_ok}" -eq 0 ]; then echo "$(printf -- "$MSG_ERROR_FAILED_TO_IMPORT_GPG" "${key_id}")" rm -rf "${GPG_HOME}" exit 1 fi if GNUPGHOME="${GPG_HOME}" gpg --verify "${sig}" "${iso}" 2>/dev/null; then echo "$(printf -- "$MSG_GOOD")" else echo "$(printf -- "$MSG_ERROR")" echo "$(printf -- "$MSG_SIGNATURE_VERIFICATION_FAILED_FOR" "${iso}")" rm -rf "${GPG_HOME}" exit 1 fi rm -rf "${GPG_HOME}" } function open_homepage() { dh_load_os "${1}" local XDG_OPEN="" if [ -z "${PRETTY}" ]; then error_specify_os else # shellcheck disable=SC2034 XDG_OPEN=$(xdg-open "${HOMEPAGE}" || sensible-browser "${HOMEPAGE}" || x-www-browser "${HOMEPAGE}" || gnome-open "${HOMEPAGE}") exit 0 fi } function check_vm_folder_name() { local name="${1}" # Underscores are part of real release names (e.g. "45_Beta"), so they # have to be allowed in the folder name. if [[ "$name" =~ [^a-zA-Z0-9._+\-] ]]; then echo "$(printf -- "$MSG_ERROR_VM_FOLDER_NAME_CONTAINS" "${name}")" >&2 exit 1 fi if [ -d "$name" ]; then echo "$(printf -- "$MSG_WARNING_VM_FOLDER_ALREADY_EXISTS" "${name}")" >&2 fi local avail_kb avail_kb=$(df -k . 2>/dev/null | awk 'NR==2{print $4}') if [[ -n "$avail_kb" && "$avail_kb" -lt 5242880 ]]; then echo "$(printf -- "$MSG_WARNING_LESS_THAN_5_GB")" >&2 fi } function check_download_url() { local url="${1}" local result http_code content_type result=$(curl --silent --head --location --max-time 15 --connect-timeout 5 \ --write-out "%{http_code} %{content_type}" --output /dev/null "${url}" 2>/dev/null) http_code="${result%% *}" content_type="${result#* }" if [[ "$http_code" != "200" ]]; then echo "$(printf -- "$MSG_WARNING_URL_RETURNED_HTTP" "${http_code}")" >&2 return 1 fi if echo "$content_type" | grep -qi "text/html"; then echo "$(printf -- "$MSG_WARNING_URL_POINTS_TO_AN")" >&2 return 1 fi return 0 } function ensure_7z_available() { if [[ "${ISO:-}" == *.7z ]]; then if ! command -v 7z &>/dev/null && ! command -v 7zz &>/dev/null && ! command -v 7za &>/dev/null; then echo "$(printf -- "$MSG_ERROR_7ZIP_NEEDS_INSTALLING_UNABLE")" >&2 return 1 fi fi return 0 } function create_vm() { # shellcheck disable=SC2206 local URL_HASH=(${1// / }) local URL="${URL_HASH[0]}" local HASH="${URL_HASH[1]}" local TORRENT_URL="" # GitLab artifact URLs include a query string, which is not a filename. local IMAGE_URL="${URL%%[?#]*}" local ISO="${IMAGE_URL##*/}" if [[ "${URL}" == *.torrent ]]; then TORRENT_URL="${URL}" URL="${URL%.torrent}" ISO="${ISO%.torrent}" fi local SPLIT_ZIP="no" if [[ "${ISO}" == *.zip ]]; then # Probe for a companion .z01 part. Use a small range GET rather than # HEAD, since some hosts reject HEAD while answering range requests. _probe_query="" if [[ "${URL}" == *\?* ]]; then _probe_query="?${URL#*\?}" fi if curl --silent --location --range 0-0 --output /dev/null --fail \ --connect-timeout 10 --max-time 15 \ "${IMAGE_URL%.zip}.z01${_probe_query}" 2>/dev/null; then SPLIT_ZIP="yes" else echo "$(printf -- "$MSG_WARNING_LOOKS_LIKE_A_ZIP" "${ISO}")" >&2 fi fi local TARGET_DIR="$(image_target_dir "${ISO}")" # Ensure target directory exists early — needed by torrent/magnet/HTTP paths mkdir -p "${TARGET_DIR}" # Resolution order: TORRENT → MAGNET → HTTP # TORRENT: .torrent URL (stable, embeds webseed, infohash never drifts) # MAGNET: magnet URI (needs MAGNET_PREFERRED or interactive opt-in) # HTTP: plain curl download (always works) if [[ -n "${TORRENT_URL}" && -z "${TORRENT:-}" ]]; then TORRENT="${TORRENT_URL}" fi if [ -n "${TORRENT:-}" ] && command -v aria2c &>/dev/null; then echo "Downloading via .torrent file (preferred)..." # TORRENT may be URL + checksum metadata; aria2c must receive only the URL. local torrent_source="${TORRENT%% *}" if torrent_get "${torrent_source}" "${TARGET_DIR}" "${ISO}"; then if [ -n "${HASH}" ]; then check_hash "${ISO}" "${HASH}" || return $? fi dh_load_os "${OS}" ensure_7z_available || return $? if declare -F extract_ >/dev/null; then extract_ || return $? fi make_vm_config "${ISO}" return 0 else echo "WARNING: Torrent download failed, trying magnet..." >&2 # Fall through to magnet fi fi # --- 2. Try MAGNET (respects MAGNET_PREFERRED / DH_MAGNET_PREFERRED) --- local prefer_magnet="${MAGNET_PREFERRED:-${DH_MAGNET_PREFERRED:-}}" local use_magnet=0 if [ -n "${MAGNET:-}" ] && command -v aria2c &>/dev/null; then if [[ "${prefer_magnet}" == "true" || "${prefer_magnet}" == "1" || "${prefer_magnet}" == "yes" ]]; then use_magnet=1 elif [ -t 0 ]; then # Interactive terminal — ask the user (preserves current UX for humans) echo "Magnet link available. Use aria2c? [y/N]" read -r -n 1 ans echo if [[ "${ans,,}" == "y" ]]; then use_magnet=1 fi else # Non-interactive (e.g. quicktest, CI) — default to HTTP unless explicitly opted in echo "INFO: Magnet link available but non-interactive; use DH_MAGNET_PREFERRED=1 to force magnet" >&2 fi fi if [ "${use_magnet}" -eq 1 ]; then echo "Downloading via magnet link..." if torrent_get "${MAGNET}" "${TARGET_DIR}" "${ISO}"; then if [ -n "${HASH}" ]; then check_hash "${ISO}" "${HASH}" || return $? fi dh_load_os "${OS}" ensure_7z_available || return $? if declare -F extract_ >/dev/null; then extract_ || return $? fi make_vm_config "${ISO}" table_write ./TODO/all return 0 else echo "WARNING: Magnet download failed, falling back to HTTP..." >&2 # Fall through to HTTP path fi fi # --- 3. HTTP download path (final fallback) --- if [ "${SPLIT_ZIP}" == "yes" ]; then # Split zip archive: download all parts, then reassemble with 7z. local BASE_URL="${IMAGE_URL%.zip}" local BASE_ISO="${ISO%.zip}" local PART_URL PART_FILE local SEVENZ="" if command -v 7z &>/dev/null; then SEVENZ="7z" elif command -v 7zz &>/dev/null; then SEVENZ="7zz" elif command -v 7za &>/dev/null; then SEVENZ="7za" else echo "$(printf -- "$MSG_ERROR_7Z_7ZZ_IS_REQUIRED")" >&2 return 1 fi # Preserve any query string (auth tokens) from the original URL while # changing the path extension for each part. local URL_QUERY="" if [[ "${URL}" == *\?* ]]; then URL_QUERY="?${URL#*\?}" fi local PARTS=("${ISO}") local n=1 while [ "${n}" -le 20 ]; do local part_ext printf -v part_ext 'z%02d' "${n}" if curl --silent --location --range 0-0 --output /dev/null --fail \ --connect-timeout 10 --max-time 15 \ "${IMAGE_URL%.zip}.${part_ext}" 2>/dev/null; then PARTS+=("${BASE_ISO}.${part_ext}") n=$((n+1)) else break fi done for PART in "${PARTS[@]}"; do local part_ext="${PART##*.}" local PART_URL if [ "${part_ext}" == "zip" ]; then PART_URL="${BASE_URL}.zip${URL_QUERY}" else PART_URL="${BASE_URL}.${part_ext}${URL_QUERY}" fi web_get "${PART_URL}" "${TARGET_DIR}" "${PART}" || return $? done echo "$(printf -- "$MSG_EXTRACTING_WITH" "${ISO}" "${SEVENZ}")" (cd "${TARGET_DIR}" && "${SEVENZ}" x -y "${ISO}") || { echo "$(printf -- "$MSG_ERROR_FAILED_TO_EXTRACT" "${ISO}")" >&2; return 1; } ISO="${BASE_ISO}" if [ -n "${HASH}" ]; then check_hash "${ISO}" "${HASH}" fi else check_download_url "${URL}" || true web_get "${URL}" "${TARGET_DIR}" "${ISO}" || return $? if [ -n "${HASH}" ]; then check_hash "${ISO}" "${HASH}" fi fi dh_load_os "${OS}" ensure_7z_available || return $? if declare -F extract_ >/dev/null; then extract_ || return $? fi make_vm_config "${ISO}" table_write ./TODO/all } function create_config() { local VM_PATH="${1}" local INPUT="${2}" local FIXED_ISO="" OS="custom" if ! mkdir "${VM_PATH}" 2>/dev/null; then echo "$(printf -- "$MSG_WARNING_THIS_WILL_OVERWRITE_CONTENT" "${VM_PATH}")" fi if [[ "${INPUT}" == "http://"* ]] || [[ "${INPUT}" == "https://"* ]]; then INPUT="$(web_redirect "${INPUT}")" if [[ "${INPUT}" == *".iso" ]] || [[ "${INPUT}" == *".img" ]] || [[ "${INPUT}" == *".ISO" ]] || [[ "${INPUT}" == *".IMG" ]]; then local DL_DIR="$(image_target_dir "${INPUT##*/}")" mkdir -p "${DL_DIR}" web_get "${INPUT}" "${DL_DIR}" || exit $? INPUT="${INPUT##*/}" else error_not_supported_image fi fi function moving_image() { echo "$(printf -- "$MSG_MOVING_IMAGE_TO_TARGET_DIR")" mv "$1" "$2" } local TARGET_DIR="$(image_target_dir "${INPUT##*/}")" mkdir -p "${TARGET_DIR}" if [[ "${INPUT}" == *".ISO" ]]; then moving_image "${INPUT}" "${TARGET_DIR}/${INPUT##*/}.iso" INPUT="${INPUT##*/}.iso" CUSTOM_IMAGE_TYPE="iso" elif [[ "${INPUT}" == *".iso" ]]; then moving_image "${INPUT}" "${TARGET_DIR}" CUSTOM_IMAGE_TYPE="iso" elif [[ "${INPUT}" == *".img" ]]; then moving_image "${INPUT}" "${VM_PATH}" CUSTOM_IMAGE_TYPE="img" elif [[ "${INPUT}" == *".qcow2" ]]; then moving_image "${INPUT}" "${VM_PATH}/disk.qcow2" INPUT="disk.qcow2" CUSTOM_IMAGE_TYPE="qcow2" else error_not_supported_image fi if [ ! -f "$(image_target_dir "${INPUT}")/${INPUT##*/}" ]; then echo "$(printf -- "$MSG_ERROR_IMAGE_NOT_FOUND")" exit 1 else INPUT="$(basename "${INPUT}")" fi echo "Creating custom VM config for ${INPUT##*/}." case "${INPUT,,}" in *freebsd*) CUSTOM_OS="freebsd";; *kolibrios*) CUSTOM_OS="kolibrios";; *reactos*) CUSTOM_OS="reactos";; *windows-server*|*eval_oemret_x*|*eval_x*) CUSTOM_OS="windows-server";; *windows*|win*) CUSTOM_OS="windows" # Older windows 10 ISOs use the year followed by the month rather than the year & half). Match any text for language. if [ "${3}" != "--disable-unattended" ] && ( [ "${3}" == "--unattended" ] || grep -E -q 'Win(10|11)_([0-9]{2}H(1|2)|[0-9]{4})_[^.]*?(x64|x32)(v[0-9])?.iso' <<< "${INPUT}" ); then echo "$(printf -- "$MSG_CREATING_UNATTENDED_WINDOWS_INSTALLATION")" echo echo "$(printf -- "$MSG_DOWNLOADING_VIRTIO_DRIVERS")" web_get "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" "$(image_target_dir "virtio-win.iso")" || exit $? FIXED_ISO="virtio-win.iso" rm -f "${VM_PATH}/unattended.iso" unattended_windows "${VM_PATH}" || exit $? fi ;; *) CUSTOM_OS="linux";; esac echo -e "$(printf -- "$MSG_SELECTING_OS_NIF_THIS_IS" "${CUSTOM_OS}")" make_vm_config "${INPUT}" "${FIXED_ISO}" } # 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 find_latest_qemu_version() { local latest latest=$(floatversion --full -M \ "$(curl --disable -sLf --retry 3 --max-time 8 \ "https://github.com/qemu/qemu/tags" | grep -s 'Link--primary')" 2>/dev/null) if [ -n "$latest" ]; then echo "$(printf -- "$MSG_LATEST_QEMU_RELEASE" "${latest}")" else echo "$(printf -- "$MSG_COULD_NOT_FETCH_QEMU_VERSION")" >&2 fi } function resolve_quickemu() { command -v quickemu || \ if [ -x "./quickemu" ]; then echo "$(pwd)/quickemu" else echo "$(printf -- "$MSG_QUICKEMU_NOT_FOUND")" >&2 exit 1 fi } run_itself() { local DOWNLOAD_SPEC if [ -n "${1}" ]; then OS="${1,,}" else error_specify_os fi os_supported dh_load_os "${OS}" if [ -n "${2}" ]; then RELEASE="${2}" validate_arch if [ "${OS}" == "bedrock-linux" ]; then validate_release releases_ BASE_OS="${3}" if [ "${BASE_OS}" == "prepared" ]; then BASE_VM_CONF="${4}" create_bedrock_from_vm return fi local BASE_OS_OPTIONS BASE_OS_OPTIONS="$(editions_)" if [[ ! " ${BASE_OS_OPTIONS} " == *" ${BASE_OS} "* ]]; then local BASE_PROMPT="Select a Bedrock base for ${ARCH}:" [ -n "${BASE_OS}" ] && BASE_PROMPT="${BASE_OS} is unavailable on ${ARCH}; select a supported base:" BASE_OS=$(bedrock_choose_value "${BASE_PROMPT}" "${BASE_OS_OPTIONS}") || { echo "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_7" "${BASE_OS}" "${ARCH}")" >&2 echo "$(printf -- "$MSG_SUPPORTED_BASES" "${BASE_OS_OPTIONS}")" >&2 exit 1 } fi EDITION="${BASE_OS}" BASE_RELEASE="${4}" BASE_EDITION="${5}" select_bedrock_base VM_PATH="${OS}-${RELEASE}-${BASE_OS}-${BASE_RELEASE}" [ -n "${BASE_EDITION}" ] && VM_PATH+="-${BASE_EDITION}" VM_PATH+="$(arch_suffix)" check_vm_folder_name "${VM_PATH}" DOWNLOAD_SPEC=$("get_") || return $? create_vm "${DOWNLOAD_SPEC}" || return $? if [ -n "${QGET_DEFAULT_VM_CONFIG:-}" ] && [ -f "${QGET_DEFAULT_VM_CONFIG}" ] && [ -f "${VM_PATH}.conf" ]; then cat "${QGET_DEFAULT_VM_CONFIG}" >> "${VM_PATH}.conf" fi return fi VM_PATH="${OS}-${RELEASE}$(arch_suffix)" check_vm_folder_name "${VM_PATH}" # If the OS has an editions_() function, use it. if [[ $(type -t editions_) == function ]] || [ -n "${EDITIONS:-}" ]; then validate_release releases_ EDITIONS=$(dh_editions "${RELEASE}" "${ARCH}") if [ -n "${3}" ]; then EDITION="${3}" if [[ ! "${EDITIONS[*]}" = *"${EDITION}"* ]]; then echo -e "$(printf -- "$MSG_ERROR_IS_NOT_A_SUPPORTED_8" "${EDITION}" "${PRETTY}" "${ARCH}")" echo -n $' - Supported editions: ' for EDITION in "${EDITIONS[@]}"; do echo -n "${EDITION} " done echo "" exit 1 fi else show_os_info "${OS}" "${ARCH}" "${RELEASE}" echo -e "$(printf -- "$MSG_NERROR_YOU_MUST_SPECIFY_AN" "${PRETTY}" "${ARCH}")" echo "$(printf -- "$MSG_USE_QGET_SHOW_ARCH_RELEASE" "${ARCH}" "${RELEASE}" "${OS}")" exit 1 fi handle_missing VM_PATH="${OS}-${RELEASE}-${EDITION}$(arch_suffix)" DOWNLOAD_SPEC=$("get_" "${EDITION}") || return $? create_vm "${DOWNLOAD_SPEC}" || return $? elif [ "${OS}" == "macos" ]; then # macOS doesn't use create_vm() validate_release releases_ get_ elif [[ "${OS}" == *"ubuntu-server"* ]]; then # (Comes before regular Ubuntu, or the code tries to download the desktop) # # Ubuntu doesn't use create_vm() validate_release releases_ get_ elif [[ "${OS}" == *"ubuntu"* ]]; then # Ubuntu doesn't use create_vm() validate_release releases_ get_ elif [[ "${OS}" == "windows"* ]]; then I18N="English International" languages_"${OS}" if [ -n "${3}" ]; then I18N="${3}" if [[ ! "${I18NS[*]}" = *"${I18N}"* ]]; then error_not_supported_lang fi VM_PATH="$(echo "${OS}-${RELEASE}-${I18N// /-}" | tr -d '()')$(arch_suffix)" fi validate_release releases_ get_ else validate_release releases_ DOWNLOAD_SPEC=$("get_") || return $? create_vm "${DOWNLOAD_SPEC}" || return $? fi else error_specify_release fi } # shellcheck disable=SC2046 function run_ui() { if ! command -v gum &> /dev/null; then echo "$(printf -- "$MSG_GUM_COULD_NOT_BE_FOUND")" exit 1 fi OS=$(gum filter --height=17 --header="Select an OS:" $(os_support)) #os_info "${OS}" > "$TMPFILE" dh_load_os "${OS}" ARCHS="${QEMU_ARCH:-}" if [ -z "${ARCHS}" ] && [[ $(type -t arch_) == function ]]; then ARCHS="$(arch_)" fi ARCHS="${ARCHS:-$(_host_arch)}" ARCH_LIST=() read -r -a ARCH_LIST <<< "${ARCHS}" if [ "${#ARCH_LIST[@]}" -gt 1 ]; then ARCH=$(printf '%s\n' "${ARCH_LIST[@]}" | gum choose --height=9 --header="Select $OS architecture:") [ -z "${ARCH}" ] && return 0 else ARCH="${ARCH_LIST[0]}" fi RELEASES="$(dh_releases "${ARCH}")" RELEASE=$(gum filter --height=9 --header="Select $OS release:" ${RELEASES}) [ -z "${RELEASE}" ] && return 0 EDITIONS=$(dh_editions "${RELEASE}" "${ARCH}") [ "${OS}" == "bedrock-linux" ] && EDITIONS="${EDITIONS} prepared" if [ -n "${EDITIONS}" ]; then local EDITION_HEADER="Select ${OS} ${RELEASE} edition:" [ "${OS}" == "bedrock-linux" ] && EDITION_HEADER="Select Bedrock base distro or prepared VM:" EDITION=$(gum filter --height=9 --header="${EDITION_HEADER}" ${EDITIONS}) [ -z "${EDITION}" ] && return 0 echo '' run_itself "${OS}" "${RELEASE}" "${EDITION}" else echo '' run_itself "${OS}" "${RELEASE}" fi } function help_message() { #shellcheck disable=SC2016 printf ' _ __ _ __ _ ____| |_ / _` |/ _` |/ _ \ _| | (_| | (_| | __/| |_ \__, |\__, |\___|\___| |_||___/ v%s using curl %s -------------------------------------------------------------------------------- Project - https://github.com/osowoso/distrohopper Discord - https://discord.gg/UQRE3aNF -------------------------------------------------------------------------------- Usage: qget [edition] qget ubuntu 22.04 qget bedrock-linux [base-edition] qget bedrock-linux 0.7.31 debian 13.7.0 netinst qget bedrock-linux 0.7.31 prepared linux-vm.conf qget --arch arm64 fedora-linux 43 Workstation Advanced usage: qget [path] [release] [edition] qget --download ubuntu 22.04 qget --show --arch arm64 --release 43 fedora-linux When a distro supports multiple architectures, select the architecture before choosing its release and edition. Use --show --arch to inspect the options available for a specific architecture. Arguments: --arch : Set architecture (default: host architecture) --download [edition] : Download image; no VM configuration --create-config [path/url] [flags] : Create VM config for an OS image --open-homepage : Open homepage for the OS --show [--arch ] [--release ] [os] : Show OS information --templates : Read metadata from templates/ (live) instead of public/ (static) --public : Read metadata from public/ (static) only, no template fallback --version : Show version --help : Show this help message --ui : Run in UI mode ------------------------------------ Flags ------------------------------------- --create-config: --disable-unattended : Force qget not to set up an unattended installation -------------------------- For testing & development --------------------------- --url [os] [release] [edition] : Show image URL(s) --check [os] [release] [edition] : Check image URL(s) --list : List all supported systems --list-csv : List everything in csv format --list-json : List everything in json format --list-category : List distros matching a category (e.g. Gaming, Security) -------------------------------------------------------------------------------- Supported Operating Systems:\n\n' "$qgetVersion" "${CURL_VERSION}" os_support | fmt -w 80 } trap cleanup EXIT if ((BASH_VERSINFO[0] < 4)); then echo "$(printf -- "$MSG_SORRY_YOU_NEED_BASH_4")" exit 1 fi QUICKEMU=$(resolve_quickemu) I18NS=() OPERATION="" NORMALISED_HOST_ARCH="$(_host_arch)" ARCH="${NORMALISED_HOST_ARCH}" ARCH_EXPLICIT="no" export ARCH NORMALISED_HOST_ARCH CURL=$(command -v curl) if [ ! -x "${CURL}" ]; then echo "$(printf -- "$MSG_ERROR_CURL_NOT_FOUND_PLEASE")" exit 1 fi CURL_VERSION=$("${CURL}" --version | head -n 1 | cut -d' ' -f2) # Global flags that may appear before the command. while [ "$#" -gt 0 ]; do case "${1}" in --templates|-templates) # Read the distro metadata straight from templates/ instead of # the generated public/ files. The templates discover releases # and editions live, so this always reflects the current # upstream state but needs network access and is slower. DH_USE_TEMPLATES="yes" export DH_USE_TEMPLATES DH_USER_TEMPLATES="yes" export DH_USER_TEMPLATES shift ;; --public|-public) # Force reading metadata from the generated public/ files only, # disabling the automatic fallback to templates/ when a distro # is missing from public/. DH_FORCE_PUBLIC="yes" export DH_FORCE_PUBLIC DH_USE_TEMPLATES="no" export DH_USE_TEMPLATES shift ;; -a|--arch) # The architecture may be given before or after the command, # so it is handled here as well as in the command dispatch. if [ -z "${2:-}" ]; then echo "ERROR! --arch requires an architecture." >&2 exit 1 fi ARCH="$(_upstream_to_qarch "${2}")" ARCH_EXPLICIT="yes" export ARCH shift 2 ;; *) break ;; esac done # Note: Old commands `list`, `list_csv`, `list_json` are kept for backwards compatibility # They now map to the new `--list`, `--list-csv`, `--list-json` options case "${1}" in --ui) OPERATION="ui" shift run_ui ;; --download|-download) OPERATION="download" shift ;; --create-config|-create-config) OPERATION="config" shift create_config "${@}" exit $? ;; --open-homepage|-open-homepage|-o) shift open_homepage "${1}" ;; --show|-show) shift SHOW_ARCH="" SHOW_RELEASE="" while [[ "${1:-}" == "--arch" || "${1:-}" == "--release" || "${1:-}" == "--plain" ]]; do case "${1}" in --arch) if [ -z "${2:-}" ] || [[ "${2}" == --* ]]; then echo "$(printf -- "$MSG_ERROR_ARCH_REQUIRES_AN_ARCHITECTURE")" >&2 exit 1 fi SHOW_ARCH="${2}" shift 2 ;; --release) if [ -z "${2:-}" ] || [[ "${2}" == --* ]]; then echo "$(printf -- "$MSG_ERROR_RELEASE_REQUIRES_A_RELEASE")" >&2 exit 1 fi SHOW_RELEASE="${2}" shift 2 ;; --plain) QGET_PLAIN=1; export QGET_PLAIN; shift ;; esac done if [ -z "${1}" ]; then if [ -n "${SHOW_ARCH}${SHOW_RELEASE}" ]; then echo "ERROR! --arch and --release require an OS." exit 1 fi for OS in $(os_support); do show_os_info "${OS}" done else show_os_info "${1}" "${SHOW_ARCH}" "${SHOW_RELEASE}" || exit 1 fi exit 0 ;; --version|-version) WHERE=$(dirname "${BASH_SOURCE[0]}") "${WHERE}/quickemu" --version exit 0 ;; --help|-help|--h|-h) help_message exit 0 ;; --url|-url) OPERATION="show" shift if [ -z "${1}" ]; then for OS in $(os_support); do (test_all "${OS}") done exit 0 fi # The release and edition are optional; without them every # combination of the distro is listed. OS="${1}" RELEASE="${2:-}" EDITION="${3:-}" test_all "${OS}" exit 0 ;; --check|-check) OPERATION="test" shift if [ -z "${1}" ]; then for OS in $(os_support); do (test_all "${OS}") done exit 0 fi OS="${1}" RELEASE="${2:-}" EDITION="${3:-}" test_all "${OS}" exit 0 ;; --list-os|-list-os) os_support exit 0 ;; --list-csv|-list-csv|list|list_csv) list_csv ;; --list-json|-list-json|list_json) list_json ;; --list|-list) list_supported ;; --list-category|-list-category) shift [ -z "${1}" ] && { echo "$(printf -- "$MSG_ERROR_SPECIFY_A_CATEGORY_FILTER")" >&2; exit 1; } list_by_category "${1}" ;; --qemu-version|-qemu-version) find_latest_qemu_version exit 0 ;; -a|--arch) ARCH="$(_upstream_to_qarch "${2}")" ARCH_EXPLICIT="yes" shift 2 ;; -*) error_not_supported_argument ;; esac run_itself "$@" # vim:tabstop=4:shiftwidth=4:noexpandtab