forked from keland/USB-Rubber-Ducky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash.sh
39 lines (33 loc) · 1.02 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
#!/bin/sh
EXIT=0
if lsusb | awk '$6=="03eb:2ff6"{e=1}END{exit e}'; then
echo "Is your Ducky connected and in DFU mode? I don't see it. Try"
echo "unplugging it, then holding down the button while plugging it back in."
EXIT=1
fi
FILE=${1:-firmware.hex} # Where to get our dump.
if test -r "$FILE"; then
if egrep -vq '^:' "$FILE"; then
echo "That doesn't look like an ihex file."
EXIT=1
fi
else
echo "No such input file or you don't have permissions to read it."
EXIT=1
fi
if ! which dfu-programmer &>/dev/null; then
echo "dfu-programmer not found. Go install it and try again."
EXIT=1
fi
test $EXIT -eq 1 && exit 1 # Get all the errors at once, then exit
die() {
echo "$*"
exit 2
}
echo Erasing...
sudo dfu-programmer at32uc3b1256 erase || die "Failed to erase"
echo Flashing...
sudo dfu-programmer at32uc3b1256 flash --suppress-bootloader-mem "$FILE" \
|| die "Failed to flash"
echo Flash complete. Resetting your Ducky...
sudo dfu-programmer at32uc3b1256 reset || die "Failed to reset"