|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# # Find the most recently created firmware directory |
| 4 | +# selected_dir=$(find ~/Downloads -maxdepth 1 -type d -name "*firmware-no-clique*" -exec stat -f "%m %N" {} \; | sort -nr | head -1 | cut -d' ' -f2-) |
| 5 | + |
| 6 | +# # Check if we found a directory |
| 7 | +# if [ -z "$selected_dir" ]; then |
| 8 | +# osascript -e 'display dialog "No firmware-no-clique directory found" buttons {"OK"} default button "OK"' |
| 9 | +# exit 1 |
| 10 | +# fi |
| 11 | + |
| 12 | +# echo "Selected directory: $selected_dir" |
| 13 | + |
| 14 | +# NOTE The code above works for manual downloads of artifacts, but this is no |
| 15 | +# longer necessary when this script is used with Shortcuts.app |
| 16 | +selected_dir=~/Downloads |
| 17 | + |
| 18 | +# Function to wait for drive to appear |
| 19 | +wait_for_drive() { |
| 20 | + local side="$1" |
| 21 | + osascript -e "display dialog \"Put the ${side} half of the keyboard into bootloader mode and connect it via USB\" buttons {\"OK\"} default button \"OK\"" >/dev/null |
| 22 | + echo "Waiting for ADV360PRO drive to appear..." |
| 23 | + while [ ! -d "/Volumes/ADV360PRO" ]; do |
| 24 | + sleep 1 |
| 25 | + done |
| 26 | + echo "ADV360PRO drive detected" |
| 27 | +} |
| 28 | + |
| 29 | +# Function to wait for drive to disappear |
| 30 | +wait_for_drive_removal() { |
| 31 | + echo "Waiting for ADV360PRO drive to be removed..." |
| 32 | + while [ -d "/Volumes/ADV360PRO" ]; do |
| 33 | + sleep 1 |
| 34 | + done |
| 35 | + echo "ADV360PRO drive removed" |
| 36 | +} |
| 37 | + |
| 38 | +# Function to copy file with confirmation |
| 39 | +copy_with_confirmation() { |
| 40 | + local file_pattern="$1" |
| 41 | + local side="$2" |
| 42 | + |
| 43 | + # Find the file |
| 44 | + local file_to_copy=$(find "$selected_dir" -name "*${file_pattern}.uf2" -type f | head -1) |
| 45 | + |
| 46 | + if [ -z "$file_to_copy" ]; then |
| 47 | + echo "No file containing '${file_pattern}' found in $selected_dir" |
| 48 | + return 1 |
| 49 | + fi |
| 50 | + |
| 51 | + # Get just the filename for display |
| 52 | + local filename=$(basename "$file_to_copy") |
| 53 | + |
| 54 | + # Perform the copy |
| 55 | + echo "Copying $filename to ADV360PRO drive..." |
| 56 | + cp "$file_to_copy" "/Volumes/ADV360PRO/" >/dev/null 2>&1 |
| 57 | + |
| 58 | + echo "Copy completed" |
| 59 | +} |
| 60 | + |
| 61 | +# Main firmware flashing process |
| 62 | +echo "Starting firmware flashing process..." |
| 63 | + |
| 64 | +# Wait for drive and copy left firmware |
| 65 | +wait_for_drive "left" |
| 66 | +if ! copy_with_confirmation "left" "Left"; then |
| 67 | + echo "Left firmware copy failed or was cancelled. Exiting." |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +# Wait for drive to be removed and reappear |
| 72 | +wait_for_drive_removal |
| 73 | +wait_for_drive "right" |
| 74 | +if ! copy_with_confirmation "right" "Right"; then |
| 75 | + echo "Right firmware copy failed or was cancelled. Exiting." |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +echo "Firmware flashing process completed!" |
| 80 | +osascript -e 'display dialog "Firmware flashing process completed!\n\nBoth left and right firmware files have been copied." buttons {"OK"} default button "OK"' >/dev/null |
0 commit comments