This commit is contained in:
zenobit 2023-03-23 23:41:29 +01:00
parent 00d0165368
commit ff5155730c

140
dh
View file

@ -36,8 +36,31 @@ set_variables() {
#GTK_THEME="alt-dialog" #GTK_THEME="alt-dialog"
DH_CONFIG_DIR="$HOME/.config/distrohopper" DH_CONFIG_DIR="$HOME/.config/distrohopper"
DH_CONFIG="$DH_CONFIG_DIR/distrohopper.conf" DH_CONFIG="$DH_CONFIG_DIR/distrohopper.conf"
export LC_ALL=C DH_ICON_DIR="/usr/share/icons/distrohopper"
source "$DH_CONFIG" || install_process PREFIX="/usr/bin/"
TERMINAL=sakura
replace='"!"'
source "$DH_CONFIG" >/dev/null 2>&1 \
&& cd "$VMS_DIR" \
&& export "DH_CONFIG_DIR" \
"DH_CONFIG" \
"DH_ICON_DIR" \
"PREFIX" \
"TERMINAL" \
"replace" \
|| echo "Not installed yet!" \
&& VMS_DIR="$(pwd)" \
&& DH_CONFIG_DIR="$(pwd)" \
&& DH_ICON_DIR="$(pwd)"/icons \
&& export "VMS_DIR" \
"DH_CONFIG_DIR" \
"DH_ICON_DIR" \
"TERMINAL" \
"replace" \
&& echo "Using current: $VMS_DIR directory!"
echo "DistroHopper v$version"
echo "quickemu v$(quickemu --version)
"
# Set traps to catch the signals and exit gracefully # Set traps to catch the signals and exit gracefully
trap "exit" INT trap "exit" INT
trap "exit" EXIT trap "exit" EXIT
@ -89,7 +112,7 @@ install_process() {
&& run_once \ && run_once \
&& echo "Creating directory structure..." \ && echo "Creating directory structure..." \
&& create_structure \ && create_structure \
&& echo "Setting directory..." \ && echo "Setting up directory..." \
&& set_dir \ && set_dir \
&& echo "Installing needed..." \ && echo "Installing needed..." \
&& echo "For now voidlinux only" \ && echo "For now voidlinux only" \
@ -99,19 +122,6 @@ install_process() {
} }
# basic # basic
enter_vms_dir() {
cd "$VMS_DIR" || set_dir
}
# DistroHopper info
show_info() {
progname="${progname:="${0##*/}"}"
version="0.6"
echo "DistroHopper v$version"
echo "quickemu v$(quickemu --version)
"
}
renew_supported() { renew_supported() {
# get supported VMs # get supported VMs
quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' > "$DH_CONFIG_DIR/supported.md" quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' > "$DH_CONFIG_DIR/supported.md"
@ -156,39 +166,41 @@ Categories=System;Virtualization;"
} }
renew_ready() { renew_ready() {
source "$DH_CONFIG" cd "$VMS_DIR" || exit 1
cd "$VMS_DIR" || exit 1 # check for VMs .conf files (ready to run VMs)
# check for VMs .conf files (ready to run VMs) if [ ! -e *.conf ]; then
for vm_conf in *.conf; do echo "No .conf files found"
vm_desktop=$(basename "$VMS_DIR/$vm_conf" .conf) return
# Use fuzzy matching to find the best matching icon file (ready to run VMs) fi
icon_name=$(basename "$VMS_DIR/$vm_conf" .conf | cut -d'-' -f -2) for vm_conf in *.conf; do
icon_file=$(find "$DH_ICON_DIR" -type f -iname "${icon_name// /}.*") vm_desktop=$(basename "$VMS_DIR/$vm_conf" .conf)
# If no icon was found, try shorter name (ready to run VMs) # Use fuzzy matching to find the best matching icon file (ready to run VMs)
if [ -z "$icon_file" ]; then icon_name=$(basename "$VMS_DIR/$vm_conf" .conf | cut -d'-' -f -2)
icon_name=$(basename "$VMS_DIR/$vm_conf" .conf | cut -d'-' -f1) icon_file=$(find "$DH_ICON_DIR" -type f -iname "${icon_name// /}.*")
icon_file=$(find "$DH_ICON_DIR" -type f -iname "${icon_name// /}.*") # If no icon was found, try shorter name (ready to run VMs)
elif [ -z "$icon_file" ]; then if [ -z "$icon_file" ]; then
icon_file="$DH_ICON_DIR/tux.svg" icon_name=$(basename "$VMS_DIR/$vm_conf" .conf | cut -d'-' -f1)
fi icon_file=$(find "$DH_ICON_DIR" -type f -iname "${icon_name// /}.*")
# content of desktop files (ready to run VMs) elif [ -z "$icon_file" ]; then
desktop_file_content="[Desktop Entry] icon_file="$DH_ICON_DIR/tux.svg"
fi
# content of desktop files (ready to run VMs)
desktop_file_content="[Desktop Entry]
Type=Application Type=Application
Name=$vm_desktop Name=$vm_desktop
Exec=sh -c 'cd \"$VMS_DIR\" && quickemu -vm \"$vm_conf\"' Exec=sh -c 'cd \"$VMS_DIR\" && quickemu -vm \"$vm_conf\"'
Icon=$icon_file Icon=$icon_file
Categories=System;Virtualization;" Categories=System;Virtualization;"
# create desktop files (ready to run VMs) # create desktop files (ready to run VMs)
echo "$desktop_file_content" > "$DH_CONFIG_DIR"/ready/"$vm_desktop".desktop echo "$desktop_file_content" > "$DH_CONFIG_DIR"/ready/"$vm_desktop".desktop
done done
} }
run_gui() { run_gui() {
key=$((RANDOM % 9000 + 1000)) key=$((RANDOM % 9000 + 1000))
yad --plug="$key" --tabnum=1 --monitor --icons --listen --read-dir="$DH_CONFIG_DIR"/ready --sort-by-name --no-buttons --borders=0 --icon-size=48 --item-width=76 & yad --plug="$key" --tabnum=1 --monitor --icons --listen --read-dir="$DH_CONFIG_DIR"/ready --sort-by-name --no-buttons --borders=0 --icon-size=46 --item-width=76 &
yad --plug="$key" --tabnum=2 --monitor --icons --listen --read-dir="$DH_CONFIG_DIR"/supported --sort-by-name --no-buttons --borders=0 --icon-size=48 --item-width=76 & yad --plug="$key" --tabnum=2 --monitor --icons --listen --read-dir="$DH_CONFIG_DIR"/supported --sort-by-name --no-buttons --borders=0 --icon-size=46 --item-width=76 &
yad --plug="$key" --tabnum=3 --monitor --icons --listen --read-dir="$DH_CONFIG_DIR" --sort-by-name --no-buttons --borders=0 --icon-size=48 --item-width=76 & yad --dynamic --notebook --key="$key" --monitor --listen --window-icon="$DH_ICON_DIR"/hop.svg --width=900 --height=900 --title="DistroHopper" --tab="run VM" --tab="download VM" --tab="settings" --button "test"
yad --dynamic --notebook --key="$key" --monitor --window-icon="$DH_ICON_DIR"/hop.svg --width=900 --height=800 --title="DistroHopper" --listen --no-buttons --tab="run VM" --tab="download VM" --tab="settings" --button "test"
} }
run_tui() { run_tui() {
@ -308,28 +320,14 @@ add_distro() {
# run # run
set_variables set_variables
show_info case "$1" in
d) set_dir;;
if [ "$1" = "d" ] ; then i) echo "Starting installation..." && install_process;;
set_dir s) echo "Updating supported VMs..." && renew_supported;;
echo "New dir is: $VMS_DIR" t) echo "You are master! Running TUI..." && run_tui;;
elif [ "$1" = "i" ] ; then r) echo "Updating ready VMs..." && renew_ready;;
echo "Starting installation..." a) echo "Adding new distro started..." && add_distro;;
install_process h) echo "Possible arguments are:
elif [ "$1" = "s" ] ; then
echo "Updating supported VMs..."
renew_supported
elif [ "$1" = "t" ] ; then
echo "You are master! Running TUI..."
run_tui
elif [ "$1" = "r" ] ; then
echo "Updating ready VMs..."
renew_ready
elif [ "$1" = "a" ] ; then
echo "Adding new distro started..."
add_distro
elif [ "$1" = "h" ] ; then
echo "Posible argumets are:
d Set where VMs are stored d Set where VMs are stored
i Install DistroHopper i Install DistroHopper
s Update supported VMs s Update supported VMs
@ -338,18 +336,12 @@ elif [ "$1" = "h" ] ; then
a Add new distro to quickget a Add new distro to quickget
h Show this help h Show this help
o Copy all ISOs to target dir (for Ventoy) o Copy all ISOs to target dir (for Ventoy)
p Push changed quickget to quickemu project" p Push changed quickget to quickemu project";;
elif [ "$1" = "o" ] ; then o) echo "Copying ISOs to dir. It will take some time..." && isos_to_dir;;
echo "Copying ISOs to dir. It will take some time..." p) echo "Nothing here yet!";;
isos_to_dir *) echo "You can show help if you run 'dh h'
elif [ "$1" = "p" ] ; then Starting DistroHopper GUI..." && run_gui;;
echo "Nothing here yet!" esac
else
echo "You can show help if you run 'dh h'"
echo "Starting DistroHopper GUI..."
run_gui
fi
some_bugs some_bugs
exit 0 exit 0