quickemu/quickfzf

97 lines
3.1 KiB
Plaintext
Raw Normal View History

2023-02-09 06:57:23 +00:00
#!/usr/bin/bash
# Author: zenobit
# Description: Uses fzf to provide a simple GUI for quickemu and quickget
# script must be in same directory as quickget and quickemu!
# License MIT
2023-02-11 18:03:09 +00:00
# Define variables
2023-02-09 06:57:23 +00:00
progname="${progname:="${0##*/}"}"
2023-02-11 18:03:09 +00:00
version="0.21"
vms=(*.conf)
# Set traps to catch the signals and exit gracefully
trap "exit" INT
trap "exit" EXIT
# Dependency check: check if fzf is installed and can be executed
if ! command -v fzf >/dev/null 2>&1; then
echo "You are missing fzf..." && exit 255
2023-02-09 06:57:23 +00:00
fi
2023-02-11 18:03:09 +00:00
# Dispaly version and prepared VMs
#printf " $progname: $version\n quickemu: $(quickemu --version)\n\n Prepared VMs:\n-------------\n"
printf '%s: v.%s\nquickemu: v.%s\n\n Prepared VMs:\n-------------\n' "$progname" "$version" "$(quickemu --version)"
# Check if there are any VMs
if [ ${#vms[@]} -eq 0 ]; then
echo "No VMs found."
exit 1
fi
# Print the names of the available VMs
printf "%s\n" "${vms[@]%.*}"
2023-02-09 06:57:23 +00:00
echo "-------------"
2023-02-11 18:03:09 +00:00
# Action prompt
printf " Do you want to create a new VM? (c)
or run an existing one? (press anything)\n"
read -rn 1 -s start
2023-02-09 06:57:23 +00:00
case $start in
c )
todo="create"
;;
esac
2023-02-11 18:03:09 +00:00
# If the user chose to create a new VM
2023-02-09 06:57:23 +00:00
if [ "$todo" = "create" ]; then
2023-03-02 02:36:45 +00:00
os=$(quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose OS to download
2023-02-11 18:03:09 +00:00
or CTRL-c or ESC to quit')
# If the OS is Windows
2023-02-09 06:57:23 +00:00
if [ "$os" = windows ]; then
answer=$(echo "Default English
2023-03-02 02:36:45 +00:00
Choose other language" | fzf --cycle)
2023-02-11 18:03:09 +00:00
# If the user wants another windows language
2023-02-09 06:57:23 +00:00
if [ "$answer" = "Choose other language" ]; then
2023-02-11 18:03:09 +00:00
wrelease=$(echo "8
2023-02-09 06:57:23 +00:00
10
2023-03-02 02:36:45 +00:00
11" | fzf --cycle)
2023-02-11 18:03:09 +00:00
# get window language list
2023-02-09 06:57:23 +00:00
wlend=$(($(cat quickget | sed '/Arabic/,$!d' | grep -n '}' | cut -d':' -f1 | head -n 1) - 1))
2023-02-11 18:03:09 +00:00
# get windows language
2023-03-02 02:36:45 +00:00
wlang=$(cat quickget | sed '/Arabic/,$!d' | head -n $wlend | cut -d'=' -f2 | tail -c +2 | head -c -2 | sed 's/^[ \t]*//' | fzf --cycle --header='Choose Language
2023-02-11 18:03:09 +00:00
or CTRL-c or ESC to quit')
# downloading windows
printf '\n Trying to download Windows %s %s...\n\n' "$wrelease" "$wlang"
quickget "windows" "$wrelease" "$wlang"
2023-02-09 06:57:23 +00:00
fi
fi
2023-02-11 18:03:09 +00:00
# Get the release and edition to download, if necessary
2023-02-09 06:57:23 +00:00
choices=$(quickget "$os" | sed 1d)
2023-02-11 18:03:09 +00:00
if [ "$(echo "$choices" | wc -l)" = 1 ]; then
# get release
2023-03-02 02:36:45 +00:00
release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Release
2023-02-11 18:03:09 +00:00
or CTRL-c or ESC to quit')
# downloading
printf '\n Trying to download %s %s...\n\n' "$os" "$release"
2023-02-09 06:57:23 +00:00
quickget "$os" "$release"
else
2023-02-11 18:03:09 +00:00
# get release
2023-03-02 02:36:45 +00:00
release=$(echo "$choices" | grep 'Releases' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Release
2023-02-11 18:03:09 +00:00
or CTRL-c or ESC to quit')
# get edition
2023-03-02 02:36:45 +00:00
edition=$(echo "$choices" | grep 'Editions' | cut -d':' -f2 | grep -o '[^ ]*' | fzf --cycle --header='Choose Edition
2023-02-11 18:03:09 +00:00
or CTRL-c or ESC to quit')
# downloading
printf '\n Trying to download %s %s %s...\n\n' "$os" "$release" "$edition"
2023-02-09 06:57:23 +00:00
quickget "$os" "$release" "$edition"
fi
fi
2023-02-11 18:03:09 +00:00
# choose VM to run
2023-03-02 02:36:45 +00:00
choosed=$(echo "$(ls *.conf 2>/dev/null | sed 's/\.conf$//')" | fzf --cycle --header='Choose VM to run
2023-02-11 18:03:09 +00:00
or CTRL-c or ESC to quit')
# Run choosed VM
printf '\n Starting %s...\n\n' "$choosed"
quickemu -vm "$choosed.conf"
2023-02-09 06:57:23 +00:00
exit 0