-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash.sh
73 lines (63 loc) · 1.33 KB
/
flash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
label="NICENANO"
flash-by-mount() {
local device="$1"
local file="$2"
echo ""
echo "-- Flashing $file"
echo -n "-- Waiting for $device"
while true; do
if [[ -e "$device" ]]; then break; fi
sleep 0.2
echo -n '.'
done
echo ' ✓'
echo -n '-- Mounting...'
mkdir -p /tmp/flashmnt
mount "$device" /tmp/flashmnt
echo ' ✓'
echo -n "-- Sending $file..."
cp "$file" /tmp/flashmnt
sync
umount -R /tmp/flashmnt
echo ' ✓'
}
flash-by-cp() {
local dest="$1"
local file="$2"
echo -n "-- Waiting for $dest"
while true; do
if [[ -e "$dest/CURRENT.UF2" ]]; then break; fi
sleep 0.2
echo -n '.'
done
echo ' ✓'
echo -n "-- Sending $file..."
cp "$file" "$dest/"
# diskutil eject "$dest"
echo ' ✓'
}
main() {
local device='' file=''
while true; do
case "${1:-}" in
--device) device="$2"; shift 2 ;;
--file) file="$2"; shift 2 ;;
*) break ;;
esac
done
if [[ -z "${device}${file}" ]]; then
echo 'Pass --device </dev/> --file <path/to/file.uf2>'
exit 1
fi
if [[ -d /dev/disk/by-label ]]; then
flash-by-mount "/dev/disk/by-label/$label" "$file"
elif [[ -d /Volumes ]]; then
flash-by-cp "/Volumes/$label" "$file"
else
echo '-- Sorry, your platform is unsupported'
exit 1
fi
echo '-- Done!'
}
main "$@"