Skip to content

Commit 97c7b23

Browse files
committed
Helper script for flashing
1 parent 70163ac commit 97c7b23

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

bin/flash_adv360pro.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
# Find the most recently created firmware directory
4+
latest_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 "$latest_dir" ]; then
8+
osascript -e 'display dialog "No firmware-no-clique directory found in Downloads" buttons {"OK"} default button "OK"'
9+
exit 1
10+
fi
11+
12+
# Show dialog with the found directory and allow editing
13+
result=$(osascript -e "display dialog \"Found firmware directory:\" default answer \"$latest_dir\" buttons {\"Cancel\", \"OK\"} default button \"OK\"" -e "text returned of result" 2>/dev/null)
14+
15+
# Check if user cancelled
16+
if [ $? -ne 0 ]; then
17+
echo "Cancelled by user"
18+
exit 1
19+
fi
20+
21+
# Use the result (either original path or user-modified path)
22+
selected_dir="$result"
23+
24+
# Verify the selected directory exists
25+
if [ ! -d "$selected_dir" ]; then
26+
osascript -e "display dialog \"Directory does not exist:\n\n$selected_dir\" buttons {\"OK\"} default button \"OK\""
27+
exit 1
28+
fi
29+
30+
echo "Selected directory: $selected_dir"
31+
32+
# Function to wait for drive to appear
33+
wait_for_drive() {
34+
local side="$1"
35+
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
36+
echo "Waiting for ADV360PRO drive to appear..."
37+
while [ ! -d "/Volumes/ADV360PRO" ]; do
38+
sleep 1
39+
done
40+
echo "ADV360PRO drive detected"
41+
}
42+
43+
# Function to wait for drive to disappear
44+
wait_for_drive_removal() {
45+
echo "Waiting for ADV360PRO drive to be removed..."
46+
while [ -d "/Volumes/ADV360PRO" ]; do
47+
sleep 1
48+
done
49+
echo "ADV360PRO drive removed"
50+
}
51+
52+
# Function to copy file with confirmation
53+
copy_with_confirmation() {
54+
local file_pattern="$1"
55+
local side="$2"
56+
57+
# Find the file
58+
local file_to_copy=$(find "$selected_dir" -name "*${file_pattern}*" -type f | head -1)
59+
60+
if [ -z "$file_to_copy" ]; then
61+
echo "No file containing '${file_pattern}' found in $selected_dir"
62+
return 1
63+
fi
64+
65+
# Get just the filename for display
66+
local filename=$(basename "$file_to_copy")
67+
68+
# Perform the copy
69+
echo "Copying $filename to ADV360PRO drive..."
70+
cp "$file_to_copy" "/Volumes/ADV360PRO/" >/dev/null 2>&1
71+
72+
echo "Copy completed"
73+
}
74+
75+
# Main firmware flashing process
76+
echo "Starting firmware flashing process..."
77+
78+
# Wait for drive and copy left firmware
79+
wait_for_drive "left"
80+
if ! copy_with_confirmation "left" "Left"; then
81+
echo "Left firmware copy failed or was cancelled. Exiting."
82+
exit 1
83+
fi
84+
85+
# Wait for drive to be removed and reappear
86+
wait_for_drive_removal
87+
wait_for_drive "right"
88+
if ! copy_with_confirmation "right" "Right"; then
89+
echo "Right firmware copy failed or was cancelled. Exiting."
90+
exit 1
91+
fi
92+
93+
echo "Firmware flashing process completed!"
94+
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)