-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-build.sh
More file actions
executable file
·222 lines (204 loc) · 6.58 KB
/
Copy pathrun-build.sh
File metadata and controls
executable file
·222 lines (204 loc) · 6.58 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
# MeshCore Wi-Fi Firmware Builder
# This script builds the Docker image and runs the firmware build process
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
DOCKER_IMAGE="meshcore-builder"
OUTPUT_DIR="$(pwd)/firmware-output"
CACHE_DIR="$(pwd)/build-cache"
# Function to display usage
usage() {
echo -e "${BLUE}MeshCore Wi-Fi Firmware Builder${NC}"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -s, --ssid SSID Wi-Fi SSID (required)"
echo " -p, --password PASSWORD Wi-Fi password (required)"
echo " -v, --version VERSION Firmware version label (default: 1.12.0)"
echo " --commit SHA MeshCore commit to build (default: e738a74)"
echo " -o, --output DIR Output directory (default: ./firmware-output)"
echo " -c, --cache DIR Cache directory (default: ./build-cache)"
echo " --max-contacts NUM Maximum contacts (default: 300)"
echo " --max-channels NUM Maximum group channels (default: 8)"
echo " --enable-debug Enable mesh debug logging"
echo " --enable-packet-log Enable mesh packet logging"
echo " --build-only Only build the Docker image, don't run"
echo " --no-build Skip building Docker image, just run"
echo " --clear-cache Clear the build cache before running"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 --ssid MyWiFi --password MyPassword"
echo " $0 -s MyWiFi -p MyPassword -v 1.12.0 --commit e738a74"
echo " $0 --ssid MyWiFi --password MyPassword --output /tmp/firmware"
echo ""
echo -e "${YELLOW}Warning: Your Wi-Fi credentials will be embedded in the firmware.${NC}"
echo -e "${YELLOW}Do not share the compiled binaries publicly!${NC}"
}
# Parse command line arguments
WIFI_SSID=""
WIFI_PWD=""
FIRMWARE_VERSION="1.12.0"
MESHCORE_COMMIT="e738a74"
BUILD_ONLY=false
NO_BUILD=false
CLEAR_CACHE=false
MAX_CONTACTS=""
MAX_GROUP_CHANNELS=""
MESH_DEBUG=""
MESH_PACKET_LOGGING=""
while [[ $# -gt 0 ]]; do
case $1 in
-s|--ssid)
WIFI_SSID="$2"
shift 2
;;
-p|--password)
WIFI_PWD="$2"
shift 2
;;
-v|--version)
FIRMWARE_VERSION="$2"
shift 2
;;
--commit)
MESHCORE_COMMIT="$2"
shift 2
;;
-o|--output)
OUTPUT_DIR="$2"
shift 2
;;
-c|--cache)
CACHE_DIR="$2"
shift 2
;;
--max-contacts)
MAX_CONTACTS="$2"
shift 2
;;
--max-channels)
MAX_GROUP_CHANNELS="$2"
shift 2
;;
--enable-debug)
MESH_DEBUG="1"
shift
;;
--enable-packet-log)
MESH_PACKET_LOGGING="1"
shift
;;
--build-only)
BUILD_ONLY=true
shift
;;
--no-build)
NO_BUILD=true
shift
;;
--clear-cache)
CLEAR_CACHE=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
usage
exit 1
;;
esac
done
# Validate required parameters (unless build-only)
if [ "$BUILD_ONLY" = false ]; then
if [ -z "$WIFI_SSID" ] || [ -z "$WIFI_PWD" ]; then
echo -e "${RED}Error: Wi-Fi SSID and password are required${NC}"
echo ""
usage
exit 1
fi
fi
echo -e "${BLUE}=== MeshCore Wi-Fi Firmware Builder ===${NC}"
echo ""
# Handle cache clearing if requested
if [ "$CLEAR_CACHE" = true ]; then
echo -e "${YELLOW}Clearing build cache...${NC}"
rm -rf "$CACHE_DIR"
echo -e "${GREEN}Cache cleared${NC}"
fi
# Create output and cache directories
mkdir -p "$OUTPUT_DIR" "$CACHE_DIR"
echo -e "${GREEN}Output directory: $OUTPUT_DIR${NC}"
echo -e "${GREEN}Cache directory: $CACHE_DIR${NC}"
# Show cache status
if [ -d "$CACHE_DIR/.platformio" ] && [ "$(ls -A "$CACHE_DIR/.platformio" 2>/dev/null)" ]; then
CACHE_SIZE=$(du -sh "$CACHE_DIR" 2>/dev/null | cut -f1 || echo "unknown")
echo -e "${GREEN}Cache exists (${CACHE_SIZE}) - build will be faster!${NC}"
else
echo -e "${YELLOW}No cache found - first build will download tools${NC}"
fi
# Build Docker image (unless --no-build is specified)
if [ "$NO_BUILD" = false ]; then
echo -e "${YELLOW}Building Docker image: $DOCKER_IMAGE${NC}"
docker build -t "$DOCKER_IMAGE" .
if [ $? -eq 0 ]; then
echo -e "${GREEN}Docker image built successfully${NC}"
else
echo -e "${RED}Failed to build Docker image${NC}"
exit 1
fi
fi
# Exit if build-only was requested
if [ "$BUILD_ONLY" = true ]; then
echo -e "${GREEN}Docker image build completed. Use --no-build to run without rebuilding.${NC}"
exit 0
fi
echo ""
echo -e "${YELLOW}Starting firmware build process...${NC}"
echo "SSID: $WIFI_SSID"
echo "Password: [REDACTED]"
echo "Version: $FIRMWARE_VERSION"
echo "MeshCore commit: $MESHCORE_COMMIT"
echo ""
# Run the Docker container with cache volume and gomplate environment variables
echo -e "${YELLOW}Mounting cache directory for faster subsequent builds...${NC}"
docker run --rm \
-e WIFI_SSID="$WIFI_SSID" \
-e WIFI_PWD="$WIFI_PWD" \
-e FIRMWARE_VERSION="$FIRMWARE_VERSION" \
-e MESHCORE_COMMIT="$MESHCORE_COMMIT" \
${MAX_CONTACTS:+-e MAX_CONTACTS="$MAX_CONTACTS"} \
${MAX_GROUP_CHANNELS:+-e MAX_GROUP_CHANNELS="$MAX_GROUP_CHANNELS"} \
${MESH_DEBUG:+-e MESH_DEBUG="$MESH_DEBUG"} \
${MESH_PACKET_LOGGING:+-e MESH_PACKET_LOGGING="$MESH_PACKET_LOGGING"} \
-v "$OUTPUT_DIR:/output" \
-v "$CACHE_DIR:/build-cache" \
"$DOCKER_IMAGE"
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}=== Build Completed Successfully! ===${NC}"
echo -e "${GREEN}Firmware files are available in: $OUTPUT_DIR${NC}"
echo ""
echo -e "${YELLOW}Generated files:${NC}"
ls -la "$OUTPUT_DIR"
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo "1. Flash the firmware to your Heltec V3 device"
echo "2. Monitor serial output to confirm Wi-Fi connectivity"
echo "3. Remember: This is experimental firmware"
echo ""
echo -e "${RED}WARNING: Do not share these binaries publicly as they contain your Wi-Fi credentials!${NC}"
else
echo -e "${RED}Build failed! Check the output above for errors.${NC}"
exit 1
fi