-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpush_config.sh
executable file
·54 lines (42 loc) · 1.26 KB
/
push_config.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
#!/bin/bash
function msg() {
echo -e "[\e[0;92m*\e[0m]" "$@"
}
if [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "Usage: $0 /dev/ttySERIAL_PORT"
exit 1
fi
tty="$1"
build_venv="build-venv"
if ! [ "$2" == "" ]; then
build_venv="$2"
fi
if [ ! -e "$tty" ]; then
echo "Serial port does not exist"
exit 1
fi
if [ ! -e "$build_venv/bin/python" ]; then
echo "Build virtual environment does not exist or is broken. Run ./build_image.sh first to set it up."
exit 1
fi
if [ ! -f leviot_conf.py ]; then
echo "Config file does not exist. Copy leviot_conf.py.template to leviot_conf.py and change it as needed."
exit 1
fi
if ! PYTHONPATH="$(pwd)/upy_test_stubs" python -c 'import leviot_conf'; then
echo "Config file is invalid".
exit 1
fi
source $build_venv/bin/activate
echo "Ready to copy: reset the board and, when all LEDs turn on,"
echo "hold the BOOT button until they turn off and the red LED turns on."
echo
read -p "Press Enter when you are ready or Ctrl+C to cancel."
msg "Copying config file to the device"
ampy -p "$tty" -b 115200 put leviot_conf.py
if [ -f "user_boot.py" ]; then
msg "Copying user boot script"
ampy -p "$tty" -b 115200 put user_boot.py
fi
msg "Resetting board"
ampy -p "$tty" -b 115200 reset --hard >/dev/null