-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·239 lines (184 loc) · 6.01 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·239 lines (184 loc) · 6.01 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
#!/usr/bin/env bash
set -e
# Determine wrt_core path
if [ -d "wrt_core" ]; then
WRT_CORE_PATH="wrt_core"
elif [ -d "../wrt_core" ]; then
WRT_CORE_PATH="../wrt_core"
else
echo "Error: wrt_core directory not found!"
exit 1
fi
BASE_PATH=$(cd "$WRT_CORE_PATH" && pwd)
Dev=$1
Build_Mod=$2
SUPPORTED_DEVS=()
collect_supported_devs() {
local ini_file
local dev_key
local IFS
SUPPORTED_DEVS=()
for ini_file in "$BASE_PATH"/compilecfg/*.ini; do
[[ -f "$ini_file" ]] || continue
dev_key=$(basename "$ini_file" .ini)
if [[ -f "$BASE_PATH/deconfig/$dev_key.config" ]]; then
SUPPORTED_DEVS+=("$dev_key")
fi
done
if [[ ${#SUPPORTED_DEVS[@]} -eq 0 ]]; then
return
fi
IFS=$'\n' SUPPORTED_DEVS=($(printf '%s\n' "${SUPPORTED_DEVS[@]}" | LC_ALL=C sort))
}
print_usage() {
echo "Usage: $0 <device> [debug]"
}
print_supported_devs() {
local index
echo "Supported devices:"
for ((index = 0; index < ${#SUPPORTED_DEVS[@]}; index++)); do
printf " %d) %s\n" "$((index + 1))" "${SUPPORTED_DEVS[index]}"
done
}
prompt_select_dev() {
local input
local selected_index
while true; do
print_supported_devs
printf "Select device by number (q to quit): "
if ! read -r input; then
echo
echo "Cancelled."
exit 1
fi
if [[ "$input" =~ ^[[:space:]]*[qQ][[:space:]]*$ ]]; then
echo "Cancelled."
exit 1
fi
if [[ "$input" =~ ^[[:space:]]*([0-9]+)[[:space:]]*$ ]]; then
selected_index=${BASH_REMATCH[1]}
if ((selected_index >= 1 && selected_index <= ${#SUPPORTED_DEVS[@]})); then
Dev=${SUPPORTED_DEVS[selected_index - 1]}
return
fi
fi
echo "Invalid selection. Please enter a number between 1 and ${#SUPPORTED_DEVS[@]}."
done
}
prompt_select_build_mode() {
local input
while true; do
echo "Build mode:"
echo " 1) normal"
echo " 2) debug"
printf "Select build mode (1-2, q to quit): "
if ! read -r input; then
echo
echo "Cancelled."
exit 1
fi
if [[ "$input" =~ ^[[:space:]]*[qQ][[:space:]]*$ ]]; then
echo "Cancelled."
exit 1
fi
if [[ "$input" =~ ^[[:space:]]*1[[:space:]]*$ ]]; then
Build_Mod=""
return
fi
if [[ "$input" =~ ^[[:space:]]*2[[:space:]]*$ ]]; then
Build_Mod="debug"
return
fi
echo "Invalid selection. Please enter 1 or 2."
done
}
is_interactive_terminal() {
[[ -t 0 && -t 1 ]]
}
if [[ $# -eq 0 ]]; then
collect_supported_devs
if [[ ${#SUPPORTED_DEVS[@]} -eq 0 ]]; then
echo "Error: no supported devices found."
exit 1
fi
if ! is_interactive_terminal; then
print_usage
print_supported_devs
exit 1
fi
prompt_select_dev
if [[ -z $Build_Mod ]]; then
prompt_select_build_mode
fi
fi
CONFIG_FILE="$BASE_PATH/deconfig/$Dev.config"
INI_FILE="$BASE_PATH/compilecfg/$Dev.ini"
if [[ ! -f $CONFIG_FILE ]]; then
echo "Config not found: $CONFIG_FILE"
exit 1
fi
if [[ ! -f $INI_FILE ]]; then
echo "INI file not found: $INI_FILE"
exit 1
fi
read_ini_by_key() {
local key=$1
awk -F"=" -v key="$key" '$1 == key {print $2}' "$INI_FILE"
}
remove_uhttpd_dependency() {
local config_path="$BASE_PATH/../$BUILD_DIR/.config"
local luci_makefile_path="$BASE_PATH/../$BUILD_DIR/feeds/luci/collections/luci/Makefile"
if grep -q "CONFIG_PACKAGE_luci-app-quickfile=y" "$config_path"; then
if [ -f "$luci_makefile_path" ]; then
sed -i '/luci-light/d' "$luci_makefile_path"
echo "Removed uhttpd (luci-light) dependency as luci-app-quickfile (nginx) is enabled."
fi
fi
}
apply_config() {
\cp -f "$CONFIG_FILE" "$BASE_PATH/../$BUILD_DIR/.config"
if grep -qE "(ipq60xx|ipq807x)" "$BASE_PATH/../$BUILD_DIR/.config" &&
! grep -q "CONFIG_GIT_MIRROR" "$BASE_PATH/../$BUILD_DIR/.config"; then
cat "$BASE_PATH/deconfig/nss.config" >> "$BASE_PATH/../$BUILD_DIR/.config"
fi
cat "$BASE_PATH/deconfig/compile_base.config" >> "$BASE_PATH/../$BUILD_DIR/.config"
cat "$BASE_PATH/deconfig/docker_deps.config" >> "$BASE_PATH/../$BUILD_DIR/.config"
cat "$BASE_PATH/deconfig/proxy.config" >> "$BASE_PATH/../$BUILD_DIR/.config"
}
REPO_URL=$(read_ini_by_key "REPO_URL")
REPO_BRANCH=$(read_ini_by_key "REPO_BRANCH")
REPO_BRANCH=${REPO_BRANCH:-main}
BUILD_DIR=$(read_ini_by_key "BUILD_DIR")
COMMIT_HASH=$(read_ini_by_key "COMMIT_HASH")
COMMIT_HASH=${COMMIT_HASH:-none}
if [[ -d action_build ]]; then
BUILD_DIR="action_build"
fi
"$BASE_PATH/update.sh" "$REPO_URL" "$REPO_BRANCH" "$BUILD_DIR" "$COMMIT_HASH"
apply_config
remove_uhttpd_dependency
cd "$BASE_PATH/../$BUILD_DIR"
make defconfig
if grep -qE "^CONFIG_TARGET_x86_64=y" "$CONFIG_FILE"; then
DISTFEEDS_PATH="$BASE_PATH/../$BUILD_DIR/package/emortal/default-settings/files/99-distfeeds.conf"
if [ -d "${DISTFEEDS_PATH%/*}" ] && [ -f "$DISTFEEDS_PATH" ]; then
sed -i 's/aarch64_cortex-a53/x86_64/g' "$DISTFEEDS_PATH"
fi
fi
if [[ $Build_Mod == "debug" ]]; then
exit 0
fi
TARGET_DIR="$BASE_PATH/../$BUILD_DIR/bin/targets"
if [[ -d $TARGET_DIR ]]; then
find "$TARGET_DIR" -type f \( -name "*.bin" -o -name "*.manifest" -o -name "*efi.img.gz" -o -name "*.itb" -o -name "*.fip" -o -name "*.ubi" -o -name "*rootfs.tar.gz" \) -exec rm -f {} +
fi
make download -j$(($(nproc) * 2))
make -j$(($(nproc) + 1)) || make -j1 V=s
FIRMWARE_DIR="$BASE_PATH/../firmware"
\rm -rf "$FIRMWARE_DIR"
mkdir -p "$FIRMWARE_DIR"
find "$TARGET_DIR" -type f \( -name "*.bin" -o -name "*.manifest" -o -name "*efi.img.gz" -o -name "*.itb" -o -name "*.fip" -o -name "*.ubi" -o -name "*rootfs.tar.gz" \) -exec cp -f {} "$FIRMWARE_DIR/" \;
\rm -f "$BASE_PATH/../firmware/Packages.manifest" 2>/dev/null
if [[ -d action_build ]]; then
make clean
fi