-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_all.sh
More file actions
executable file
Β·393 lines (340 loc) Β· 14.7 KB
/
build_all.sh
File metadata and controls
executable file
Β·393 lines (340 loc) Β· 14.7 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/usr/bin/env bash
# ============================================================================
# UNBOUND β Master Build Script (Unix/macOS/Linux/WSL)
# ============================================================================
# Usage:
# ./build_all.sh <target> [options]
#
# Targets:
# windows - Build Windows GUI binary via Wails (requires Wine + Go)
# darwin - Build macOS binary via Wails
# linux - Build Linux CLI/GUI binary
# linux-steamdeck - Build for Steam Deck (Decky Loader plugin + binary)
# android - Build Android APK via Gradle
# ios - Build iOS/macOS universal binary
# tvos - Build tvOS binary
# openwrt - Build OpenWrt IPK package
# webos - Build LG webOS app
# decky - Build Decky Loader plugin only
# magisk - Build Magisk module ZIP
# all - Build all available targets
#
# Options:
# --debug - Enable debug build mode
# --clean - Clean build artifacts before building
# --version <ver> - Override version string (default: from wails.json)
# --help - Show this help message
#
# Examples:
# ./build_all.sh windows
# ./build_all.sh android --debug
# ./build_all.sh all --clean --version 1.0.5
# ============================================================================
set -euo pipefail
# ββ Colors βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# ββ Globals ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
BUILD_DIR="$PROJECT_ROOT/build"
DIST_DIR="$PROJECT_ROOT/dist"
DEBUG_MODE=false
CLEAN_BUILD=false
VERSION_OVERRIDE=""
# ββ Logging helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
log_info() { echo -e "${CYAN}[INFO]${NC} $*"; }
log_ok() { echo -e "${GREEN}[OK]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
log_step() { echo -e "\n${BOLD}βββ $* βββ${NC}"; }
# ββ Version resolution βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
resolve_version() {
if [ -n "$VERSION_OVERRIDE" ]; then
echo "$VERSION_OVERRIDE"
return
fi
if command -v jq &>/dev/null && [ -f "$PROJECT_ROOT/wails.json" ]; then
jq -r '.info.productVersion // "0.0.0"' "$PROJECT_ROOT/wails.json" 2>/dev/null || echo "0.0.0"
else
grep -oP '"productVersion":\s*"\K[^"]+' "$PROJECT_ROOT/wails.json" 2>/dev/null || echo "0.0.0"
fi
}
# ββ Prerequisite checks ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
require_cmd() {
if ! command -v "$1" &>/dev/null; then
log_error "$1 is required but not found in PATH."
log_info "Install: $2"
return 1
fi
}
# ββ Clean ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
do_clean() {
log_step "Cleaning build artifacts"
rm -rf "$BUILD_DIR/bin" "$BUILD_DIR/bin-linux" "$BUILD_DIR/bin-darwin"
rm -rf "$DIST_DIR"/*.zip "$DIST_DIR"/*.apk "$DIST_DIR"/*.ipa "$DIST_DIR"/*.ipk
rm -rf "$PROJECT_ROOT/frontend/dist" "$PROJECT_ROOT/frontend/node_modules/.cache"
log_ok "Clean complete"
}
# ββ Frontend build βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
build_frontend() {
log_step "Building frontend assets"
require_cmd npm "https://nodejs.org/"
if [ -d "$PROJECT_ROOT/frontend" ]; then
pushd "$PROJECT_ROOT/frontend" >/dev/null
npm install --include=dev
npm run build
popd >/dev/null
log_ok "Frontend built"
else
log_warn "frontend/ directory not found, skipping"
fi
}
# ββ Windows (via Wails + Wine cross-compile or native) βββββββββββββββββββββββ
build_windows() {
local ver
ver="$(resolve_version)"
log_step "Building Windows binary (wails)"
require_cmd go "https://go.dev/dl/"
require_cmd wails "go install github.com/wailsapp/wails/v2/cmd/wails@latest"
build_frontend
local debug_flag=""
[ "$DEBUG_MODE" = true ] && debug_flag="-debug"
wails build -platform windows/amd64 -clean -o "unbound.exe" $debug_flag
local out="$BUILD_DIR/bin"
mkdir -p "$DIST_DIR/unbound-v${ver}-win64"
cp -f "$out/unbound.exe" "$DIST_DIR/unbound-v${ver}-win64/" 2>/dev/null || \
cp -f "$BUILD_DIR/bin/unbound.exe" "$DIST_DIR/unbound-v${ver}-win64/" 2>/dev/null || true
log_ok "Windows binary built: $DIST_DIR/unbound-v${ver}-win64/"
}
# ββ macOS / Darwin (native, must run on Mac) ββββββββββββββββββββββββββββββββ
build_darwin() {
local ver
ver="$(resolve_version)"
log_step "Building macOS binary (wails)"
require_cmd go "brew install go"
require_cmd wails "go install github.com/wailsapp/wails/v2/cmd/wails@latest"
build_frontend
local debug_flag=""
[ "$DEBUG_MODE" = true ] && debug_flag="-debug"
wails build -platform darwin/universal $debug_flag
log_ok "macOS app built: $BUILD_DIR/bin/Unbound.app"
}
# ββ Linux (native or Docker) βββββββββββββββββββββββββββββββββββββββββββββββββ
build_linux() {
local ver
ver="$(resolve_version)"
log_step "Building Linux binary"
require_cmd go "https://go.dev/dl/"
build_frontend
local debug_flag=""
[ "$DEBUG_MODE" = true ] && debug_flag="-tags debug"
# Build CLI mode binary for Linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "$BUILD_DIR/bin/unbound-linux" $debug_flag .
log_ok "Linux binary built: $BUILD_DIR/bin/unbound-linux"
}
# ββ Steam Deck (SteamOS + Decky plugin) ββββββββββββββββββββββββββββββββββββββ
build_linux_steamdeck() {
build_linux
build_decky
}
# ββ Android (Gradle) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
build_android() {
local ver
ver="$(resolve_version)"
log_step "Building Android APK"
if [ -d "$PROJECT_ROOT/android" ]; then
if command -v ./gradlew &>/dev/null; then
pushd "$PROJECT_ROOT/android" >/dev/null
local variant="assembleRelease"
[ "$DEBUG_MODE" = true ] && variant="assembleDebug"
./gradlew $variant
popd >/dev/null
elif command -v gradle &>/dev/null; then
pushd "$PROJECT_ROOT/android" >/dev/null
gradle assembleRelease
popd >/dev/null
else
log_error "Gradle wrapper or gradle CLI not found"
return 1
fi
mkdir -p "$DIST_DIR"
find "$PROJECT_ROOT/android" -name "*.apk" -exec cp -v {} "$DIST_DIR/" \; 2>/dev/null || true
log_ok "Android APK(s) copied to: $DIST_DIR/"
else
log_warn "android/ directory not found, skipping"
fi
}
# ββ iOS / tvOS (must run on Mac with Xcode) βββββββββββββββββββββββββββββββββ
build_ios() {
log_step "Building iOS/tvOS binaries"
if [ -f "$PROJECT_ROOT/macos/build.sh" ]; then
bash "$PROJECT_ROOT/macos/build.sh"
fi
if [ -f "$PROJECT_ROOT/tvos/build-tvos.sh" ]; then
bash "$PROJECT_ROOT/tvos/build-tvos.sh"
fi
log_ok "Apple platform builds complete"
}
build_tvos() {
log_step "Building tvOS binary"
if [ -f "$PROJECT_ROOT/tvos/build-tvos.sh" ]; then
bash "$PROJECT_ROOT/tvos/build-tvos.sh"
else
log_warn "tvos/build-tvos.sh not found"
fi
}
# ββ OpenWrt (Docker or native) ββββββββββββββββββββββββββββββββββββββββββββββ
build_openwrt() {
local ver
ver="$(resolve_version)"
log_step "Building OpenWrt IPK package"
if [ -d "$PROJECT_ROOT/openwrt" ]; then
# Build the Go binary for mipsle (OpenWrt typical arch)
require_cmd go "https://go.dev/dl/"
GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build \
-o "$BUILD_DIR/bin/unbound-openwrt-mipsle" \
-ldflags="-s -w" .
# Package as IPK
if command -v docker &>/dev/null; then
docker build -t unbound-openwrt \
--build-arg VERSION="$ver" \
"$PROJECT_ROOT/openwrt/unbound-wrt/" 2>/dev/null || \
log_warn "Docker IPK build failed (may require SDK setup)"
fi
mkdir -p "$DIST_DIR"
log_ok "OpenWrt binary built: $BUILD_DIR/bin/unbound-openwrt-mipsle"
else
log_warn "openwrt/ directory not found, skipping"
fi
}
# ββ webOS (LG) βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
build_webos() {
log_step "Building webOS app"
if [ -d "$PROJECT_ROOT/webos" ]; then
pushd "$PROJECT_ROOT/webos" >/dev/null
if command -v ares-package &>/dev/null; then
ares-package -o "$BUILD_DIR/bin-webos" .
elif command -v npm &>/dev/null && [ -f package.json ]; then
npm install
npm run build 2>/dev/null || log_warn "webos npm build script not defined"
fi
popd >/dev/null
log_ok "webOS build complete"
else
log_warn "webos/ directory not found, skipping"
fi
}
# ββ Decky Loader Plugin βββββββββββββββββββββββββββββββββββββββββββββββββββββ
build_decky() {
log_step "Building Decky Loader plugin"
if [ -d "$PROJECT_ROOT/decky-plugin" ]; then
pushd "$PROJECT_ROOT/decky-plugin" >/dev/null
require_cmd npm "https://nodejs.org/"
npm install
npm run build 2>/dev/null || log_warn "Decky plugin build script not found"
popd >/dev/null
mkdir -p "$DIST_DIR"
if [ -f "$PROJECT_ROOT/scripts/build-decky.sh" ]; then
bash "$PROJECT_ROOT/scripts/build-decky.sh"
fi
log_ok "Decky plugin built"
else
log_warn "decky-plugin/ directory not found, skipping"
fi
}
# ββ Magisk Module ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
build_magisk() {
local ver
ver="$(resolve_version)"
log_step "Building Magisk module"
if [ -d "$PROJECT_ROOT/magisk-module" ]; then
mkdir -p "$DIST_DIR"
local zip="$DIST_DIR/unbound-magisk-v${ver}.zip"
pushd "$PROJECT_ROOT/magisk-module" >/dev/null
if command -v zip &>/dev/null; then
zip -r "$zip" . -x "*.git*"
else
tar -czf "$DIST_DIR/unbound-magisk-v${ver}.tar.gz" .
fi
popd >/dev/null
log_ok "Magisk module: $zip"
else
log_warn "magisk-module/ directory not found, skipping"
fi
}
# ββ All targets ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
build_all() {
log_step "Building ALL available targets"
echo -e " ${YELLOW}β’${NC} Linux"
echo -e " ${YELLOW}β’${NC} OpenWrt"
echo -e " ${YELLOW}β’${NC} Android"
echo -e " ${CYAN}β’${NC} Decky Plugin"
echo -e " ${YELLOW}β’${NC} Magisk Module"
echo -e " ${YELLOW}β’${NC} webOS"
build_linux
build_openwrt
build_android
build_decky
build_magisk
build_webos
# macOS/iOS only on Mac
if [[ "$(uname -s)" == "Darwin" ]]; then
echo -e " ${YELLOW}β’${NC} macOS"
echo -e " ${YELLOW}β’${NC} iOS/tvOS"
build_darwin
build_ios
fi
log_ok "All builds complete"
}
# ββ Usage / Help βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
show_help() {
sed -n '2,/^#$/s/^# \?//p' "$0"
}
# ββ Main dispatch ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
main() {
local target=""
while [[ $# -gt 0 ]]; do
case "$1" in
--debug) DEBUG_MODE=true; shift ;;
--clean) CLEAN_BUILD=true; shift ;;
--version) VERSION_OVERRIDE="$2"; shift 2 ;;
--help|-h) show_help; exit 0 ;;
-*) log_error "Unknown option: $1"; exit 1 ;;
*) target="$1"; shift ;;
esac
done
if [ -z "$target" ]; then
show_help
exit 1
fi
[ "$CLEAN_BUILD" = true ] && do_clean
case "$target" in
windows) build_windows ;;
darwin|macos) build_darwin ;;
linux) build_linux ;;
linux-steamdeck|steamdeck) build_linux_steamdeck ;;
android) build_android ;;
ios) build_ios ;;
tvos) build_tvos ;;
openwrt) build_openwrt ;;
webos) build_webos ;;
decky|decky-plugin) build_decky ;;
magisk) build_magisk ;;
all) build_all ;;
*)
log_error "Unknown target: $target"
echo ""
show_help
exit 1
;;
esac
log_step "Build complete: $target"
echo -e " ${GREEN}Output:${NC} $DIST_DIR/"
echo -e " ${GREEN}Binaries:${NC} $BUILD_DIR/bin/"
}
main "$@"