DistroHopper/config/renew.sh

85 lines
3.2 KiB
Bash
Raw Normal View History

2023-03-13 16:19:50 +00:00
#!/bin/bash
2023-03-18 13:53:27 +00:00
# shellcheck source=./distrohopper.conf
2023-03-14 11:24:54 +00:00
export LC_ALL=C
2023-03-13 16:19:50 +00:00
echo "Updating VMs..."
# distrohopper config file
CONFIG_DIR="$HOME/.config/distrohopper"
source "$CONFIG_DIR/distrohopper.conf"
# shellcheck source=distrohopper.conf
# remove desktop files (ready to run VMs)
2023-03-18 13:53:27 +00:00
rm -r "$CONFIG_DIR/ready"
mkdir "$CONFIG_DIR/ready"
2023-03-13 16:19:50 +00:00
# Enter ditrohopper VMs dir
2023-03-18 13:53:27 +00:00
cd "$VMS_DIR" || exit
2023-03-13 16:19:50 +00:00
# check for VMs .conf files (ready to run VMs)
2023-03-18 13:53:27 +00:00
for vm_conf in *.conf; do
vm_desktop=$(basename "$VMS_DIR/$vm_conf" .conf)
2023-03-13 16:19:50 +00:00
# Use fuzzy matching to find the best matching icon file (ready to run VMs)
2023-03-18 13:53:27 +00:00
icon_name=$(basename "$VMS_DIR/$vm_conf" .conf | cut -d'-' -f -2)
2023-03-13 16:19:50 +00:00
icon_file=$(find "$ICON_DIR" -type f -iname "${icon_name// /}.*")
# If no icon was found, try shorter name (ready to run VMs)
if [ -z "$icon_file" ]; then
2023-03-18 13:53:27 +00:00
icon_name=$(basename "$VMS_DIR/$vm_conf" .conf | cut -d'-' -f1)
2023-03-13 16:19:50 +00:00
icon_file=$(find "$ICON_DIR" -type f -iname "${icon_name// /}.*")
fi
# If no icon was found, use a default icon (ready to run VMs)
if [ -z "$icon_file" ]; then
icon_file="$ICON_DIR/tux.svg"
fi
# content of desktop files (ready to run VMs)
desktop_file_content="[Desktop Entry]
Type=Application
2023-03-18 13:53:27 +00:00
Name=$vm_desktop
Exec=sh -c 'cd \"$VMS_DIR\" && quickemu -vm \"$vm_conf\"'
2023-03-13 16:19:50 +00:00
Icon=$icon_file
Categories=System;Virtualization;"
# create desktop files (ready to run VMs)
2023-03-18 13:53:27 +00:00
echo "$desktop_file_content" > "$CONFIG_DIR"/ready/"$vm_desktop".desktop
2023-03-13 16:19:50 +00:00
done
# remove desktop files (supported VMs)
2023-03-18 13:53:27 +00:00
rm -r "$CONFIG_DIR/supported"
mkdir "$CONFIG_DIR/supported"
2023-03-13 16:19:50 +00:00
# get supported VMs
quickget | sed 1d | cut -d':' -f2 | grep -o '[^ ]*' > "$CONFIG_DIR/supported.md"
while read -r get_name; do
2023-03-18 13:53:27 +00:00
vm_desktop=$(echo "$get_name" | tr ' ' '_')
releases=$(quickget "$vm_desktop" | grep 'Releases' | cut -d':' -f2 | sed 's/^ //')
editions=$(quickget "$vm_desktop" | grep 'Editions' | cut -d':' -f2 | sed 's/^ //')
2023-03-13 16:19:50 +00:00
icon_name="$ICON_DIR/$get_name"
if [ -f "$icon_name.svg" ]; then
icon_file="$icon_name.svg"
elif [ -f "$icon_name.png" ]; then
icon_file="$icon_name.png"
else
icon_file="$ICON_DIR/tux.svg"
fi
# Check if there are editions
if [ -z "$editions" ]; then
# Create desktop file for VMs without editions
desktop_file_content="[Desktop Entry]
Type=Application
Name=$get_name
releases=$releases
replace='\"!\"'
2023-03-18 13:53:27 +00:00
Exec=sh -c 'cd \"$VMS_DIR\" && yad --form --field=\"Release:CB\" \"${releases// /$replace}\" | cut -d\"|\" -f1 | xargs -I{} sh -c \"quickget $get_name {}\"'
2023-03-13 16:19:50 +00:00
Icon=$icon_file
Categories=System;Virtualization;"
2023-03-18 13:53:27 +00:00
echo "$desktop_file_content" > "$CONFIG_DIR"/supported/"$vm_desktop".desktop
2023-03-13 16:19:50 +00:00
else
# Create desktop file for VMs with editions
desktop_file_content="[Desktop Entry]
Type=Application
Name=$get_name
releases=$releases
editions=$editions
replace=$replace
2023-03-18 13:53:27 +00:00
Exec=sh -c 'cd \"$VMS_DIR\" && yad --form --separator=\" \" --field=\"Release:CB\" \"${releases// /$replace}\" --field=\"Edition:CB\" \"${editions// /$replace}\" | xargs -I{} sh -c \"quickget $get_name {}\"'
2023-03-13 16:19:50 +00:00
Icon=$icon_file
Categories=System;Virtualization;"
2023-03-18 13:53:27 +00:00
echo "$desktop_file_content" > "$CONFIG_DIR"/supported/"$vm_desktop".desktop
2023-03-13 16:19:50 +00:00
fi
done < "$CONFIG_DIR"/supported.md