This commit is contained in:
Liam 2024-10-25 17:58:08 -05:00 committed by GitHub
commit 9954e299e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,12 +2,7 @@
. ../common-script.sh . ../common-script.sh
# Function to display usage instructions CONFIGURATION_URL="https://github.com/quickemu-project/quickget_configs/releases/download/daily/quickget_data.json"
usage() {
printf "%b\n" "${RED} Usage: $0 ${RC}"
printf "%b\n" "No arguments needed. The script will prompt for ISO path and USB device."
exit 1
}
# Function to display all available block devices # Function to display all available block devices
list_devices() { list_devices() {
@ -17,53 +12,23 @@ list_devices() {
printf "\n" printf "\n"
} }
# Function to fetch the latest Arch Linux ISO installDependencies() {
fetch_arch_latest_iso() { DEPENDENCIES="xz gzip bzip2 jq"
ARCH_BASE_URL="https://archive.archlinux.org/iso/" if ! command_exists ${DEPENDENCIES}; then
ARCH_LATEST=$(curl -s "$ARCH_BASE_URL" | grep -oP '(?<=href=")[0-9]{4}\.[0-9]{2}\.[0-9]{2}(?=/)' | sort -V | tail -1) printf "%b\n" "${YELLOW}Installing dependencies...${RC}"
ARCH_URL="${ARCH_BASE_URL}${ARCH_LATEST}/archlinux-${ARCH_LATEST}-x86_64.iso" case "${PACKAGER}" in
printf "%b\n" "${GREEN} Selected Arch Linux (latest) ISO URL: ${RC} $ARCH_URL" apt-get|nala)
} "${ESCALATION_TOOL}" "${PACKAGER}" install -y xz-utils gzip bzip2 jq;;
dnf|zypper)
# Function to fetch older Arch Linux ISOs and display in a table format "${ESCALATION_TOOL}" "${PACKAGER}" install -y ${DEPENDENCIES};;
fetch_arch_older_isos() { pacman)
ARCH_BASE_URL="https://archive.archlinux.org/iso/" "${ESCALATION_TOOL}" "${PACKAGER}" -S --noconfirm --needed ${DEPENDENCIES};;
ARCH_VERSIONS=$(curl -s "$ARCH_BASE_URL" | grep -oP '(?<=href=")[0-9]{4}\.[0-9]{2}\.[0-9]{2}(?=/)' | sort -V) *)
printf "%b\n" "${RED}Unsupported package manager.${RC}"
# Filter versions to include only those from 2017-04-01 and later exit 1
MIN_DATE="2017.04.01" ;;
ARCH_VERSIONS=$(echo "$ARCH_VERSIONS" | awk -v min_date="$MIN_DATE" '$0 >= min_date') esac
if [ -z "$ARCH_VERSIONS" ]; then
printf "%b\n" "${RED}No Arch Linux versions found from ${MIN_DATE} onwards.${RC}"
exit 1
fi fi
printf "%b\n" "${YELLOW}Available Arch Linux versions from ${MIN_DATE} onwards:${RC}"
COUNTER=1
ROW_ITEMS=6 # Number of versions to show per row
for VERSION in $ARCH_VERSIONS; do
printf "%-5s${YELLOW}%-15s ${RC}" "$COUNTER)" "$VERSION"
if [ $(( COUNTER % ROW_ITEMS )) -eq 0 ]; then
printf "\n" # New line after every 6 versions
fi
COUNTER=$((COUNTER + 1))
done
printf "\n" # New line after the last row
printf "%b" "Select an Arch Linux version (1-$((COUNTER - 1))): "
read -r ARCH_OPTION
ARCH_DIR=$(echo "$ARCH_VERSIONS" | sed -n "${ARCH_OPTION}p")
ARCH_URL="${ARCH_BASE_URL}${ARCH_DIR}/archlinux-${ARCH_DIR}-x86_64.iso"
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
}
# Function to fetch the latest Debian Linux ISO
fetch_debian_latest_iso() {
DEBIAN_URL=$(curl -s https://www.debian.org/distrib/netinst | grep -oP '(?<=href=")[^"]+debian-[0-9.]+-amd64-netinst.iso(?=")' | head -1)
printf "%b\n" "${GREEN} Selected Debian Linux (latest) ISO URL: ${RC} $DEBIAN_URL"
} }
# Function to ask whether to use local or online ISO # Function to ask whether to use local or online ISO
@ -77,7 +42,7 @@ choose_iso_source() {
case $ISO_SOURCE_OPTION in case $ISO_SOURCE_OPTION in
1) 1)
fetch_iso_urls # Call the function to fetch online ISO URLs get_online_iso
;; ;;
2) 2)
printf "Enter the path to the already downloaded ISO file: " printf "Enter the path to the already downloaded ISO file: "
@ -94,45 +59,156 @@ choose_iso_source() {
esac esac
} }
# Function to fetch ISO URLs decompress_iso() {
fetch_iso_urls() { printf "%b\n" "${YELLOW}Decompressing ISO file...${RC}"
clear case "${ISO_ARCHIVE_FORMAT}" in
printf "%b\n" "${YELLOW}Available ISOs for download:${RC}" xz)
printf "%b\n" "1) Arch Linux (latest)" xz -d "${ISO_PATH}"
printf "%b\n" "2) Arch Linux (older versions)" ISO_PATH="$(echo "${ISO_PATH}" | sed 's/\.xz//')";;
printf "%b\n" "3) Debian Linux (latest)" gz)
printf "\n" gzip -d "${ISO_PATH}"
printf "%b" "Select the ISO you want to download (1-3): " ISO_PATH="$(echo "${ISO_PATH}" | sed 's/\.gz//')";;
read -r ISO_OPTION bz2)
bzip2 -d "${ISO_PATH}"
case $ISO_OPTION in ISO_PATH="$(echo "${ISO_PATH}" | sed 's/\.bz2//')";;
1) *)
fetch_arch_latest_iso printf "%b\n" "${RED}Unsupported archive format. Try manually decompressing the ISO and choosing it as a local file instead.${RC}"
ISO_URL=$ARCH_URL
;;
2)
fetch_arch_older_isos
ISO_URL=$ARCH_URL
;;
3)
fetch_debian_latest_iso
ISO_URL=$DEBIAN_URL
;;
*)
printf "%b\n" "${RED}Invalid option selected.${RC}"
exit 1 exit 1
;; ;;
esac esac
ISO_PATH=$(basename "$ISO_URL") printf "%b\n" "${GREEN}ISO file decompressed successfully.${RC}"
printf "%b\n" "${YELLOW}Downloading ISO...${RC}" }
curl -L -o "$ISO_PATH" "$ISO_URL"
if [ $? -ne 0 ]; then check_hash() {
case "${#ISO_CHECKSUM}" in
32) HASH_ALGO="md5sum";;
40) HASH_ALGO="sha1sum";;
64) HASH_ALGO="sha256sum";;
128) HASH_ALGO="sha512sum";;
*) printf "%b\n" "${RED}Invalid checksum length. Skipping checksum verification.${RC}"
return;;
esac
printf "%b\n" "Checking ISO integrity using ${HASH_ALGO}..."
if ! echo "${ISO_CHECKSUM} ${ISO_PATH}" | "${HASH_ALGO}" --check --status; then
printf "%b\n" "${RED}Checksum verification failed.${RC}"
exit 1
else
printf "%b\n" "${GREEN}Checksum verification successful.${RC}"
fi
}
download_iso() {
printf "\n%b\n" "${YELLOW}Found URL: ${ISO_URL}${RC}"
printf "%b\n" "${YELLOW}Downloading ISO to ${ISO_PATH}...${RC}"
if ! curl -L -o "$ISO_PATH" "$ISO_URL"; then
printf "%b\n" "${RED}Failed to download the ISO file.${RC}" printf "%b\n" "${RED}Failed to download the ISO file.${RC}"
exit 1 exit 1
fi fi
} }
get_architecture() {
printf "%b\n" "${YELLOW}Select the architecture of the ISO to flash${RC}"
printf "%b\n" "1) x86_64"
printf "%b\n" "2) AArch64"
printf "%b\n" "3) riscv64"
printf "%b" "Select an option (1-3): "
read -r ARCH
case "${ARCH}" in
1) ARCH="x86_64";;
2) ARCH="aarch64";;
3) ARCH="riscv64";;
*)
printf "%b\n" "${RED}Invalid architecture selected. ${RC}"
exit 1
;;
esac
}
comma_delimited_list() {
echo "${1}" | tr '\n' ',' | sed 's/,/, /g; s/, $//'
}
get_online_iso() {
get_architecture
printf "%b\n" "${YELLOW}Fetching available operating systems...${RC}"
clear
# Download available operating systems, filter to to those that match requirements
# Remove entries with more than 1 ISO or any other medium, they could cause issues
OS_JSON="$(curl -L -s "$CONFIGURATION_URL" | jq -c "[.[] | \
.releases |= map(select( \
(.arch // \"x86_64\") == "\"${ARCH}\"" \
and (.iso | length == 1) and (.iso[0] | has(\"web\")) \
and .img == null and .fixed_iso == null and .floppy == null and .disk_images == null)) \
| select(.releases | length > 0)]")"
if echo "${OS_JSON}" | jq -e 'length == 0' >/dev/null; then
printf "%b\n" "${RED}No operating systems found.${RC}"
exit 1
fi
printf "%b\n" "${YELLOW}Available Operating Systems:${RC}"
comma_delimited_list "$(echo "${OS_JSON}" | jq -r '.[].name')"
printf "\n%b" "Select an operating system: "
read -r OS
OS_JSON="$(echo "${OS_JSON}" | jq --arg os "${OS}" -c '.[] | select(.name == $os)')"
if [ -z "${OS_JSON}" ]; then
printf "%b\n" "${RED}Invalid operating system selected.${RC}"
exit 1
fi
PRETTY_NAME="$(echo "${OS_JSON}" | jq -r '.pretty_name')"
printf "\n%b\n" "${YELLOW}Available releases for ${PRETTY_NAME}:${RC}"
comma_delimited_list "$(echo "${OS_JSON}" | jq -r '.releases[].release' | sort -Vur)"
printf "\n%b" "Select a release: "
read -r RELEASE
printf "\n"
OS_JSON="$(echo "${OS_JSON}" | jq --arg release "${RELEASE}" -c '.releases |= map(select(.release == $release))')"
if echo "${OS_JSON}" | jq -e '.releases | length == 0' >/dev/null; then
printf "%b\n" "${RED}Invalid release selected.${RC}"
exit 1
fi
if echo "${OS_JSON}" | jq -e '.releases[] | select(.edition != null) | any' >/dev/null; then
printf "%b\n" "${YELLOW}Available editions for ${PRETTY_NAME} ${RELEASE}:${RC}"
comma_delimited_list "$(echo "${OS_JSON}" | jq -r '.releases[].edition' | sort -Vur)"
printf "\n%b" "Select an edition: "
read -r EDITION
ENTRY="$(echo "${OS_JSON}" | jq --arg edition "${EDITION}" -c '.releases[] | select(.edition == $edition)')"
else
ENTRY="$(echo "${OS_JSON}" | jq -c '.releases[0]')"
fi
if [ -z "${ENTRY}" ]; then
printf "%b\n" "${RED}Invalid edition selected.${RC}"
exit 1
fi
WEB_DATA="$(echo "${ENTRY}" | jq -c '.iso[0].web')"
ISO_URL="$(echo "${WEB_DATA}" | jq -r '.url')"
ISO_CHECKSUM="$(echo "${WEB_DATA}" | jq -r '.checksum')"
ISO_ARCHIVE_FORMAT="$(echo "${WEB_DATA}" | jq -r '.archive_format')"
ISO_FILENAME="$(echo "${WEB_DATA}" | jq -r '.file_name')"
if [ "${ISO_FILENAME}" = "null" ]; then
ISO_FILENAME="$(basename "${ISO_URL}")"
fi
ISO_PATH="${HOME}/Downloads/${ISO_FILENAME}"
download_iso
if [ "${ISO_CHECKSUM}" != "null" ]; then
check_hash
fi
if [ "${ISO_ARCHIVE_FORMAT}" != "null" ]; then
decompress_iso
fi
}
write_iso(){ write_iso(){
clear clear
@ -191,4 +267,5 @@ write_iso(){
checkEnv checkEnv
checkEscalationTool checkEscalationTool
write_iso installDependencies
write_iso