-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·122 lines (110 loc) · 3.14 KB
/
Copy pathdeploy
File metadata and controls
executable file
·122 lines (110 loc) · 3.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
cd "$(dirname "$0")"
COPY_FRONTEND=false
RESET=true
COPY_APP=true
REPL=true
BOARD_NAME=''
print_help() {
cat >&2 <<EOF
Usage: $(basename $0) [-h|--help] [-na|--no-copy-app] [-f|--frontend] [-nr|--no-reset] [-np|--no-repl] <board_name>
EOF
exit "${1:-0}"
}
set_board_name() {
board_name="$1"
if ! [ -r "backend/config_files/pinout_$board_name.json" ]; then
echo "Invalid board name: $board_name" >&2
echo "Valid board names:" >&2
for file in backend/config_files/pinout_*.json; do
echo " - $(basename "$file" .json | cut -d_ -f2-)"
done
exit 1
fi
export BOARD_NAME="$board_name"
}
while [ -n "$1" ]; do
case "$1" in
-na|--no-copy-app)
COPY_APP=false
;;
-f|--frontend)
COPY_FRONTEND=true
;;
-nr|--no-reset)
RESET=false
;;
-np|--no-repl)
REPL=false
;;
-h|--help)
print_help 1
;;
*)
set_board_name "$1"
;;
esac
shift
done
if [ -z "$BOARD_NAME" ]; then
echo "Error: you must set the board name" >&2
print_help 1
fi
mpremote_mkdir_recursive() {
declare -a dirs
index=0
path="$1"
while [ "$path" != "/" ]; do
dirs[$index]="$path"
((index++))
path="$(dirname "$path")"
done
for i in $(seq 0 $((index-1))); do
rev_index=$((index-i-1))
#echo "creating ${dirs[$((index-i-1))]}"
mpremote fs mkdir ":${dirs[$rev_index]}"
done
}
if [ "$COPY_APP" = true ]; then
envsubst < backend/board_vars.py.envsubst > backend/board_vars.py
find backend -type d \( -name tests -o -name tests_mpy \) -prune -o -type f -name '*.py' -print | while read python_file; do
target_file="${python_file##backend}"
target_dir="$(dirname "$target_file")"
if [ "$target_dir" != "/" ]; then
mpremote_mkdir_recursive "$target_dir"
fi
echo "$python_file -> $target_file (dir: $target_dir)"
mpremote fs cp "$python_file" ":$target_file"
done
pinout_config_file="pinout_${BOARD_NAME}.json"
echo "backend/config_files/${pinout_config_file} -> :/${pinout_config_file}"
mpremote fs cp "backend/config_files/${pinout_config_file}" ":/${pinout_config_file}"
#mpremote fs mkdir :"/boards"
#mpremote fs mkdir :"/boards/esp32"
#for file in main.py config.py utils.py board.py boards/esp32/*.py; do
# mpremote fs cp ./$file :/$file
#done
fi
if [ "$COPY_FRONTEND" = true ]; then
rm -rf static
(
cd ./frontend
rm -rf build/* && npm run build
)
echo mpremote fs mkdir :"/static"
find ./frontend/build/ -type f | while read f; do
dest_path="static${f##./frontend/build}.gz"
mkdir -p "$(dirname "$dest_path")"
gzip "$f" -k -9 -c > "$dest_path"
mpremote fs mkdir :"/$(dirname "$dest_path")"
mpremote fs cp "$dest_path" ":/$dest_path"
done
rm -rf "static"
fi
if [ "$RESET" = true ]; then
echo 'Restarting MCU'
mpremote reset
fi
if [ "$REPL" = true ]; then
mpremote
fi