added better dependancy check
This commit is contained in:
+72
-15
@@ -31,18 +31,49 @@ title() {
|
|||||||
# Dependencies
|
# Dependencies
|
||||||
# -------------------------
|
# -------------------------
|
||||||
check_dependencies() {
|
check_dependencies() {
|
||||||
for cmd in flashkit fzf md5sum; do
|
# Ensure ~/.local/bin is in PATH (for pip installs)
|
||||||
if ! command -v $cmd &> /dev/null; then
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
gum confirm "$cmd is not installed. Install it now?" && {
|
|
||||||
gum spin --spinner="line" --title="Installing $cmd..." -- sudo apt-get install -y $cmd
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
# flashkit
|
||||||
|
if ! command -v flashkit &> /dev/null; then
|
||||||
|
gum confirm "flashkit is not installed. Install it now?" || exit 1
|
||||||
|
|
||||||
|
gum spin --spinner="line" --title="Installing flashkit..." -- \
|
||||||
|
python3 -m pip install --user flashkit
|
||||||
|
|
||||||
|
# Re-check after install
|
||||||
|
if ! command -v flashkit &> /dev/null; then
|
||||||
|
gum style --foreground="#FFA500" "flashkit install failed or not in PATH."
|
||||||
|
gum style --foreground="#FFA500" "Try: export PATH=\$HOME/.local/bin:\$PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# pyserial
|
||||||
if ! python3 -c "import serial" &> /dev/null; then
|
if ! python3 -c "import serial" &> /dev/null; then
|
||||||
gum confirm "pyserial is not installed. Install it now?" && {
|
gum confirm "pyserial is not installed. Install it now?" || exit 1
|
||||||
gum spin --spinner="line" --title="Installing pyserial..." -- python3 -m pip install pyserial
|
|
||||||
}
|
gum spin --spinner="line" --title="Installing pyserial..." -- \
|
||||||
|
python3 -m pip install --user pyserial
|
||||||
|
|
||||||
|
if ! python3 -c "import serial" &> /dev/null; then
|
||||||
|
gum style --foreground="#FFA500" "pyserial install failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# fzf
|
||||||
|
if ! command -v fzf &> /dev/null; then
|
||||||
|
gum confirm "fzf is not installed. Install it now?" || exit 1
|
||||||
|
|
||||||
|
gum spin --spinner="line" --title="Installing fzf..." -- \
|
||||||
|
sudo apt-get update && sudo apt-get install -y fzf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# md5sum (usually present, but just in case)
|
||||||
|
if ! command -v md5sum &> /dev/null; then
|
||||||
|
gum style --foreground="#FFA500" "md5sum not found. Please install coreutils."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +127,9 @@ read_cart() {
|
|||||||
# FZF file browser
|
# FZF file browser
|
||||||
# -------------------------
|
# -------------------------
|
||||||
browse_files() {
|
browse_files() {
|
||||||
find ~/ -type f -name "*.md" -size +256k 2>/dev/null \
|
search_path="$1"
|
||||||
|
|
||||||
|
find "$search_path" -type f -name "*.md" -size +256k 2>/dev/null \
|
||||||
| fzf \
|
| fzf \
|
||||||
--height=40% \
|
--height=40% \
|
||||||
--reverse \
|
--reverse \
|
||||||
@@ -112,7 +145,32 @@ write_rom() {
|
|||||||
clear
|
clear
|
||||||
title
|
title
|
||||||
|
|
||||||
rom_file=$(browse_files)
|
# Build menu dynamically
|
||||||
|
options=()
|
||||||
|
|
||||||
|
if [ -d "/mnt/nas/Games/ROMs/megadrive" ]; then
|
||||||
|
options+=("NAS (/mnt/nas/Games/ROMs/megadrive)")
|
||||||
|
fi
|
||||||
|
|
||||||
|
options+=("Search Home (~)")
|
||||||
|
|
||||||
|
source_choice=$(printf "%s\n" "${options[@]}" | gum choose --header="Select ROM source:")
|
||||||
|
|
||||||
|
case "$source_choice" in
|
||||||
|
"NAS (/mnt/nas/Games/ROMs/megadrive)")
|
||||||
|
if [ ! -d "/mnt/nas/Games/ROMs/megadrive" ]; then
|
||||||
|
gum style --foreground="#FFA500" "NAS path not available."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
rom_file=$(browse_files "/mnt/nas/Games/ROMs/megadrive")
|
||||||
|
;;
|
||||||
|
"Search Home (~)")
|
||||||
|
rom_file=$(browse_files "$HOME")
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
[ -z "$rom_file" ] && {
|
[ -z "$rom_file" ] && {
|
||||||
gum style --foreground="#FFA500" "No file selected."
|
gum style --foreground="#FFA500" "No file selected."
|
||||||
@@ -120,8 +178,8 @@ write_rom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# File info
|
# File info
|
||||||
rom_size=$(du -h "$rom_file" | cut -f1)
|
rom_size=$(du -h "$rom_file" | awk '{print $1}')
|
||||||
rom_md5=$(md5sum "$rom_file" | cut -d ' ' -f1)
|
rom_md5=$(md5sum "$rom_file" | awk '{print $1}')
|
||||||
|
|
||||||
gum style \
|
gum style \
|
||||||
--foreground="#FFA500" \
|
--foreground="#FFA500" \
|
||||||
@@ -136,7 +194,6 @@ MD5: $rom_md5"
|
|||||||
gum spin --spinner="line" --title="Writing ROM..." -- flashkit --port "$selected_port" write-rom -i "$rom_file"
|
gum spin --spinner="line" --title="Writing ROM..." -- flashkit --port "$selected_port" write-rom -i "$rom_file"
|
||||||
gum style --foreground="#FFA500" "Done! ROM written successfully."
|
gum style --foreground="#FFA500" "Done! ROM written successfully."
|
||||||
|
|
||||||
# Auto refresh
|
|
||||||
read_cart
|
read_cart
|
||||||
} || {
|
} || {
|
||||||
gum style --foreground="#FFA500" "Cancelled."
|
gum style --foreground="#FFA500" "Cancelled."
|
||||||
|
|||||||
Reference in New Issue
Block a user