-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpload.sh
More file actions
executable file
·55 lines (45 loc) · 1.23 KB
/
Upload.sh
File metadata and controls
executable file
·55 lines (45 loc) · 1.23 KB
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
#!/bin/bash
# Check input
if [[ -z "$1" ]]; then
start_num=0
else
start_num=$1
fi
if [[ -z "$2" ]]; then
end_num=$1
else
end_num=$2
fi
if ! [[ "$start_num" =~ ^[0-9]+$ && "$end_num" =~ ^[0-9]+$ ]]; then
echo "Both inputs must be integers."
exit 1
fi
if (( start_num > end_num )); then
temp=$start_num
start_num=$end_num
end_num=$temp
fi
shopt -s nullglob
for filename in YAMLs/1b-defcon-badge-*.yaml; do
# Extract number from the filename (assumes format like filename-XX.yaml)
base=$(basename "$filename" .yaml)
num_part=$((10#${base##*-}))
# Check if the number part is a valid integer
if [[ "$num_part" =~ ^[0-9]+$ ]]; then
start_num=$((10#$start_num))
end_num=$((10#$end_num))
if (( num_part >= start_num && num_part <= end_num )); then
echo "Uploading File: ${filename}"
read -p "Press Enter to flash ${filename} to the device..."
# Get list of matching devices
devices=(/dev/tty.usbmodem*)
if [[ ${#devices[@]} -gt 0 ]]; then
first_device="${devices[0]}"
echo "Found device: $first_device"
else
echo "No matching /dev/tty.usbmodem* device found."
fi
esphome upload "$filename" --device "$first_device"
fi
fi
done