Skip to content

Commit 462051b

Browse files
committed
Helper script for flashing
1 parent 70163ac commit 462051b

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

bin/flash_adv360pro.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
# Function to wait for drive to appear
15+
wait_for_drive() {
16+
local side="$1"
17+
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
18+
echo "Waiting for ADV360PRO drive to appear..."
19+
while [ ! -d "/Volumes/ADV360PRO" ]; do
20+
sleep 1
21+
done
22+
echo "ADV360PRO drive detected"
23+
}
24+
25+
# Function to wait for drive to disappear
26+
wait_for_drive_removal() {
27+
echo "Waiting for ADV360PRO drive to be removed..."
28+
while [ -d "/Volumes/ADV360PRO" ]; do
29+
sleep 1
30+
done
31+
echo "ADV360PRO drive removed"
32+
}
33+
34+
# Function to copy file with confirmation
35+
copy_with_confirmation() {
36+
local file_pattern="$1"
37+
local side="$2"
38+
39+
# Find the file
40+
local file_to_copy=$(find "$selected_dir" -name "*${file_pattern}*" -type f | head -1)
41+
42+
if [ -z "$file_to_copy" ]; then
43+
echo "No file containing '${file_pattern}' found in $selected_dir"
44+
return 1
45+
fi
46+
47+
# Get just the filename for display
48+
local filename=$(basename "$file_to_copy")
49+
50+
# Perform the copy
51+
echo "Copying $filename to ADV360PRO drive..."
52+
cp "$file_to_copy" "/Volumes/ADV360PRO/" >/dev/null 2>&1
53+
54+
echo "Copy completed"
55+
}
56+
57+
# Main firmware flashing process
58+
echo "Starting firmware flashing process..."
59+
60+
# Wait for drive and copy left firmware
61+
wait_for_drive "left"
62+
if ! copy_with_confirmation "left" "Left"; then
63+
echo "Left firmware copy failed or was cancelled. Exiting."
64+
exit 1
65+
fi
66+
67+
# Wait for drive to be removed and reappear
68+
wait_for_drive_removal
69+
wait_for_drive "right"
70+
if ! copy_with_confirmation "right" "Right"; then
71+
echo "Right firmware copy failed or was cancelled. Exiting."
72+
exit 1
73+
fi
74+
75+
echo "Firmware flashing process completed!"
76+
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

Comments
 (0)