Proxmark3 loader script

HI all,

First a big thanks for the team RevvoX for creating and maintaining the software. For now i am playing with the Proxmark and some Tonie dumps. With Excel the dumps are converted to the PM3 .json structure. To load these in the Toniebox / TeddyCloud i’ve made a litte script so you can load them unsupervised.

Gr.

Mr|Repel

#!/bin/bash
RED='\e[31m'
RESET='\e[0m'

# List all JSON files
json_files=(*.json)
if [[ ${#json_files[@]} -eq 0 ]]; then
    echo -e "${RED}No JSON files found! Exiting.${RESET}"
    exit 1
fi

# Display file options
echo -e "${RED}Available JSON files:${RESET}"
for i in "${!json_files[@]}"; do
    echo -e "${RED}[$i] ${json_files[$i]}${RESET}"
done

# Ask user to select a file to start from
read -p "Enter the number of the file to start with: " choice
if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 0 || choice >= ${#json_files[@]} )); then
    echo -e "${RED}Invalid selection! Exiting.${RESET}"
    exit 1
fi

# Start processing from the chosen file
for ((index=choice; index<${#json_files[@]}; index++)); do
    file="${json_files[$index]}"

    # Check if it's a file (in case of errors)
    if [[ -f "$file" ]]; then
        echo -e "${RED}Loading $file in Proxmark${RESET}"
        pm3 -c "hf 15 eload -f /home/mrrepel/proxmark3/Tonies/${file}"
        
        # Start hf 15 sim AND the countdown at the same time
        echo -e "${RED}Simulating $file in Proxmark${RESET}"
        pm3 -c "hf 15 sim" &  # Run in the background

        # Countdown for 5 seconds while the command is running (skippable)
        echo -e "${RED}Press 's' to skip countdown.${RESET}"
        i=5
        while [[ $i -gt 0 ]]; do
            read -t 1 -n 1 key
            if [[ "$key" == "s" ]]; then
                echo -e "${RED}\nCountdown skipped!${RESET}"
                break
            fi
            echo -ne "${RED}Next file in $i seconds...   \r${RESET}"
            ((i--))
            sleep 1
        done
        echo ""

        # Reset USB port (skippable)
        echo -e "${RED}Reset USB port 9ac4:4b8f (press 's' to skip waiting)${RESET}"
        sleep_time=10
        while [[ $sleep_time -gt 0 ]]; do
            read -t 1 -n 1 key
            if [[ "$key" == "s" ]]; then
                echo -e "${RED}\nTimer skipped!${RESET}"
                break
            fi
            echo -ne "${RED}Resetting USB in $sleep_time seconds...   \r${RESET}"
            ((sleep_time--))
            sleep 1
        done
        echo ""

        # Reset proxmark3
        echo -e "${RED}Resetting proxmark3${RESET}"
        sleep 5       
        pm3 -c "hw reset"
    fi
done

# Clear the screen after processing all files
clear
echo -e "${RED}All files have been processed.${RESET}"