-
Notifications
You must be signed in to change notification settings - Fork 0
/
openwrt-builder.sh
executable file
·126 lines (109 loc) · 4.02 KB
/
openwrt-builder.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
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
#!/usr/bin/env bash
# This script manages container operations for OpenWRT builds
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2024 Wesley Gimenes <wehagy@proton.me>
# See LICENSE for the full license text.
# sed -i -e 's,--- a/net,--- a/custom-feed,g' -e 's,+++ b/net,+++ b/custom-feed,g' patches/podman-200-update_to_5.2.2.patch
# sed -i 's,include ../..,include $(TOPDIR)/feeds/packages,g' custom-feed/*/Makefile
# quilt add custom-feed/*/Makefile
# quilt refresh
set -euxo pipefail
# Check and set the container manager (Podman or Docker)
if command -v podman; then
CONTAINER_MANAGER="podman"
elif command -v docker; then
CONTAINER_MANAGER="docker"
printf '%s/n' "Important: ${CONTAINER_MANAGER} functionality may be incomplete or unstable - please test carefully before use"
else
printf '%s/n' "ERROR: no container manager found, please install podman or docker"
exit 1
fi
# Packages to install or to remove for the build
mapfile -t TMP < <(
[[ -d custom-feed ]]
ls custom-feed
)
PACKAGES_IMAGE+=(
luci
luci-ssl
luci-app-attendedsysupgrade
"${TMP[@]}"
)
unset TMP
# Build process for a specific target, subtarget, and profile
build () {
local TARGET="${1:?Please set target}"
local SUBTARGET="${2:?Please set subtarget }"
local PROFILE_IMAGE="${3:?Please set profile image}"
local BRANCH="${4:-main}"
CONTAINER_PREFIX="ghcr.io/openwrt"
CONTAINER_TAG="${TARGET}-${SUBTARGET}-${BRANCH}"
CONTAINER_SDK_IMAGE="${CONTAINER_PREFIX}/sdk:${CONTAINER_TAG}"
CONTAINER_IMAGEBUILDER_IMAGE="${CONTAINER_PREFIX}/imagebuilder:${CONTAINER_TAG}"
CONTAINER_COMMON_ARGS=(
--transient-store
run
--rm
--pull always
#--userns keep-id
--image-volume tmpfs
--volume "${PWD}"/bin/:/builder/bin/
"$([[ -d custom-feed ]] && printf -- '--volume %s/custom-feed/:/builder/custom-feed/:ro' "${PWD}" || true)"
)
CONTAINER_SDK_ARGS=(
${CONTAINER_COMMON_ARGS[@]}
"${CONTAINER_SDK_IMAGE}"
bash -c "
# Update feeds and build packages
sed \
--in-place \
--regexp-extended \
's,git\.openwrt\.org\/(openwrt|feed|project),github\.com\/openwrt,' \
feeds.conf.default
sed \
--in-place \
'1i src-link custom /builder/custom-feed' \
feeds.conf.default
./scripts/feeds update -a
make defconfig
# Logic to build additional packages
for PACKAGE in custom-feed/*; do
./scripts/feeds install \"\${PACKAGE##*/}\"
make package/\"\${PACKAGE##*/}\"/{clean,compile} \
V=s \
-j \"\$( nproc )\"
done
# Clean
rm -rf bin/targets/
rmdir bin/packages/*/custom/tmp
shopt -s extglob
rm -rf bin/packages/*/!(custom)
shopt -u extglob
"
)
CONTAINER_IMAGEBUILDER_ARGS=(
${CONTAINER_COMMON_ARGS[@]}
"${CONTAINER_IMAGEBUILDER_IMAGE}"
bash -c "
# Create symbolic links for IPK files and build the final image
shopt -s globstar nullglob
for IPK in bin/**/*.ipk; do
ln -sr \"\${IPK}\" packages/
done
shopt -u globstar nullglob
make image \
V=s \
-j \"\$( nproc )\" \
PROFILE=${PROFILE_IMAGE} PACKAGES=\"${PACKAGES_IMAGE[*]}\"
"
)
# Prepare the output directory
[[ ! -d bin ]] && install --mode=0755 --directory bin
[[ -d custom-feed ]] && "${CONTAINER_MANAGER}" "${CONTAINER_SDK_ARGS[@]}"
"${CONTAINER_MANAGER}" "${CONTAINER_IMAGEBUILDER_ARGS[@]}"
mv bin "openwrt-${TARGET}-${SUBTARGET}-${PROFILE_IMAGE}-$(TZ='America/Sao_Paulo' date +"%Y.%m.%d_%H.%M.%S")"
}
quilt push -a
build "${@:?Please set <target> <subtarget> <profile> <opcional:openwrt branch, default is main>}"
quilt pop -a
exit 0