-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
170 lines (152 loc) · 5.33 KB
/
deploy.sh
File metadata and controls
170 lines (152 loc) · 5.33 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
# RPCortex Deploy Script
# Copies OS files to a connected MicroPython device using mpremote.
# Can deploy from the source tree (default) or a compiled dist/ image.
#
# Usage:
# ./deploy.sh # deploy source from repo root
# ./deploy.sh --compiled # deploy compiled dist/ image
# ./deploy.sh --compiled --out /path # deploy a custom dist directory
# ./deploy.sh --port /dev/ttyUSB0 # specify serial port explicitly
#
# mpremote install:
# pip install mpremote
#
# Notes:
# Run compile.sh first if deploying --compiled.
# /Nebula/ and /Users/ on the device are never touched — user data is safe.
# If the device has no /Nebula/ yet (fresh flash), mpremote mkdir is silent.
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DIST_DIR="${REPO_DIR}/dist"
PORT_ARG=""
COMPILED=0
# ---------------------------------------------------------------------------
# Argument parsing
# ---------------------------------------------------------------------------
while [[ $# -gt 0 ]]; do
case "$1" in
--compiled) COMPILED=1; shift ;;
--out) DIST_DIR="$2"; shift 2 ;;
--port) PORT_ARG="connect $2"; shift 2 ;;
-h|--help)
sed -n '2,20p' "$0" | grep '^#' | sed 's/^# \?//'
exit 0
;;
*)
echo "Unknown option: $1 (run with --help for usage)"
exit 1
;;
esac
done
# ---------------------------------------------------------------------------
# Prereq check
# ---------------------------------------------------------------------------
if ! command -v mpremote &>/dev/null; then
echo ""
echo " [!] mpremote not found in PATH."
echo " Install it with: pip install mpremote"
echo ""
exit 1
fi
if (( COMPILED )); then
SRC_DIR="${DIST_DIR}"
if [[ ! -d "${SRC_DIR}" ]]; then
echo " [!] Compiled dist not found: ${SRC_DIR}"
echo " Run compile.sh first, or use --out to specify a path."
exit 1
fi
echo ""
echo " Deploying COMPILED image from: ${SRC_DIR}"
else
SRC_DIR="${REPO_DIR}"
echo ""
echo " Deploying SOURCE from: ${SRC_DIR}"
fi
echo " Port: ${PORT_ARG:-auto-detect}"
echo ""
# mpremote prefix (with optional explicit port)
MPR="mpremote ${PORT_ARG}"
# ---------------------------------------------------------------------------
# Helper: upload a single file
# ---------------------------------------------------------------------------
uploaded=0
errors=0
upload() {
local local_path="$1"
local remote_path="$2"
local rel="${local_path#${SRC_DIR}/}"
if ${MPR} cp "${local_path}" ":${remote_path}" 2>/dev/null; then
printf " \033[32m[+]\033[0m %s\n" "$rel"
uploaded=$(( uploaded + 1 ))
else
printf " \033[31m[!]\033[0m FAILED: %s\n" "$rel"
errors=$(( errors + 1 ))
fi
}
# Ensure remote directories exist (silent if already present)
ensure_dir() {
${MPR} mkdir ":$1" 2>/dev/null || true
}
# ---------------------------------------------------------------------------
# Create remote directory tree
# ---------------------------------------------------------------------------
echo " -- Creating remote directories --"
ensure_dir "/Core"
ensure_dir "/Core/Launchpad"
ensure_dir "/Packages"
ensure_dir "/Packages/Launchpad"
ensure_dir "/Packages/Editor"
echo ""
# ---------------------------------------------------------------------------
# main.py
# ---------------------------------------------------------------------------
echo " -- Entry point --"
upload "${SRC_DIR}/main.py" "/main.py"
echo ""
# ---------------------------------------------------------------------------
# Core files
# ---------------------------------------------------------------------------
echo " -- Core modules --"
# Source deploy: .py files; compiled deploy: .py (stubs) + .mpy files
for f in "${SRC_DIR}"/Core/*.py "${SRC_DIR}"/Core/*.mpy; do
[[ -f "$f" ]] || continue
fname="${f##*/}"
upload "$f" "/Core/${fname}"
done
echo ""
# ---------------------------------------------------------------------------
# Launchpad command files
# ---------------------------------------------------------------------------
echo " -- Launchpad --"
for f in "${SRC_DIR}"/Core/Launchpad/*; do
[[ -f "$f" ]] || continue
fname="${f##*/}"
upload "$f" "/Core/Launchpad/${fname}"
done
echo ""
# ---------------------------------------------------------------------------
# Package stubs
# ---------------------------------------------------------------------------
echo " -- Package stubs --"
for pkg_dir in Launchpad Editor; do
for f in "${SRC_DIR}/Packages/${pkg_dir}"/*; do
[[ -f "$f" ]] || continue
fname="${f##*/}"
upload "$f" "/Packages/${pkg_dir}/${fname}"
done
done
echo ""
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
echo " ─────────────────────────────────────────────"
if (( errors > 0 )); then
echo " [!] ${errors} file(s) failed to upload — check output above."
fi
echo " Uploaded : ${uploaded} files"
echo ""
echo " Deploy complete. Reboot the device to apply."
echo ""
(( errors > 0 )) && exit 1
exit 0