forked from dingari/ota-dfu-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·48 lines (37 loc) · 1.14 KB
/
update.sh
File metadata and controls
executable file
·48 lines (37 loc) · 1.14 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
!/bin/bash
# Function to show help message
show_help() {
echo "Usage: $0 <url> <mac> <id>"
echo ""
echo "Update RuuviTag firmware using OTA DFU with Python script."
echo ""
echo "Arguments:"
echo " url The URL to download the firmware zip file (e.g. https://github.com/ruuvi/ruuvi.firmware.c/releases/download/v3.34.1/ruuvitag_b_armgcc_ruuvifw_test_v3.34.1_dfu_app.zip)"
echo ""
echo "Options:"
echo " -h, --help Show this help message and exit"
}
# Handle help flag
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
show_help
exit 0
fi
# Check if one argument are passed
if [ "$#" -ne 1 ]; then
echo "Error: Invalid number of arguments"
show_help
exit 1
fi
cd /var/lib/ota-dfu-python
URL="$1"
MAC="$(cat /usr/share/mender/identity/mac)"
ID="$(cat /usr/share/mender/identity/ruuvi-id)"
# Get current timestamp in milliseconds
DATE=$(date +%s%3N)
# Set output filename with millisecond timestamp
FIRMWARE_FILE="ruuvitag_firmware_${DATE}.zip"
wget "$URL" -O "$FIRMWARE_FILE"
python3 /usr/ota-dfu-python/dfu.py --address="$MAC" --zip="$FIRMWARE_FILE" --ruuvitag="$ID"
return_code=$?
rm -f "$FIRMWARE_FILE"
exit $return_code