-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathimage-builder
executable file
·181 lines (145 loc) · 5.45 KB
/
image-builder
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
#!/bin/bash
# Licensed under MIT License
# See: https://opensource.org/license/mit
#
# Copyright (c) 2024 BobbyUnkown
# Script to build firmware for ulo builder
# BobbyUnkown https://github.com/bobbyunknown
CONFIG_FILE="config"
PACKAGE_DIR="package"
CONFIG_PACKAGE="config-package"
setup_image_builder() {
local version="$1"
local new_name="openwrt-${version}"
local image_builder_name="openwrt-imagebuilder-${version}-armsr-armv8.Linux-x86_64.tar.xz"
local download_url="https://downloads.openwrt.org/releases/${version}/targets/armsr/armv8"
if [ ! -d "$new_name" ]; then
echo "Downloading OpenWRT Image Builder version ${version}..."
wget "${download_url}/${image_builder_name}" || {
echo "Failed to download Image Builder"
return 1
}
echo "Extracting Image Builder..."
tar xf "$image_builder_name" || {
echo "Failed to extract Image Builder"
return 1
}
mv "openwrt-imagebuilder-${version}-armsr-armv8.Linux-x86_64" "$new_name"
rm "$image_builder_name"
fi
return 0
}
build_image() {
local version="$1"
local new_name="openwrt-${version}"
cd "$new_name" || {
echo "Failed to enter directory $new_name"
return 1
}
if [ -d "../package" ]; then
echo "Copying custom packages..."
cp -r "../package"/* packages/
echo "Available custom packages:"
ls -1 packages/*.ipk 2>/dev/null
fi
if [ -d "../files" ]; then
cp -r "../files" ./
echo "Files copied successfully"
fi
if [ -f "../$CONFIG_PACKAGE" ]; then
local base_packages=$(sed ':a;N;$!ba;s/\\\n//g' "../$CONFIG_PACKAGE" | tr -s ' ')
local custom_packages=""
if [ -d "packages" ] && [ "$(ls -A packages/*.ipk 2>/dev/null)" ]; then
custom_packages=$(ls packages/*.ipk | xargs -n1 basename | sed 's/_.*//' | tr '\n' ' ')
echo "Custom packages to be installed:"
echo "$custom_packages"
fi
local all_packages="$base_packages $custom_packages"
echo "Starting image build with all packages:"
echo "$all_packages"
make image PROFILE="generic" PACKAGES="$all_packages" FILES="files"
if [ $? -eq 0 ]; then
echo "Image build successful"
else
echo "Image build failed"
return 1
fi
else
echo "Error: File $CONFIG_PACKAGE not found"
return 1
fi
cd ..
return 0
}
update_rootfs_size() {
local version="$1"
local new_name="openwrt-${version}"
local config_file="$new_name/.config"
echo "Modifying root partition size and image configuration..."
if [ -f "$config_file" ]; then
cp "$config_file" "${config_file}.backup"
sed -i 's/CONFIG_TARGET_ROOTFS_PARTSIZE=.*/CONFIG_TARGET_ROOTFS_PARTSIZE=512/' "$config_file"
sed -i 's/CONFIG_TARGET_ROOTFS_SQUASHFS=.*/CONFIG_TARGET_ROOTFS_SQUASHFS=n/' "$config_file"
sed -i 's/CONFIG_TARGET_ROOTFS_EXT4FS=.*/CONFIG_TARGET_ROOTFS_EXT4FS=n/' "$config_file"
sed -i 's/CONFIG_TARGET_ROOTFS_CPIOGZ=.*/CONFIG_TARGET_ROOTFS_CPIOGZ=n/' "$config_file"
echo "CONFIG_TARGET_ROOTFS_TARGZ=y" >> "$config_file"
echo "# CONFIG_TARGET_ROOTFS_SQUASHFS is not set" >> "$config_file"
echo "# CONFIG_TARGET_ROOTFS_EXT4FS is not set" >> "$config_file"
echo "# CONFIG_TARGET_ROOTFS_CPIOGZ is not set" >> "$config_file"
echo "CONFIG_TARGET_ROOTFS_PARTSIZE=512" >> "$config_file"
echo "Rootfs configuration updated successfully:"
echo "- Root partition size: 512MB"
echo "- Format: tar.gz (generic)"
echo "- Other formats disabled: squashfs, ext4fs, cpiogz"
else
echo "Warning: .config file not found in $new_name"
return 1
fi
return 0
}
copy_rootfs() {
local version="$1"
local new_name="openwrt-${version}"
local rootfs_file="${new_name}/bin/targets/armsr/armv8/openwrt-${version}-armsr-armv8-generic-rootfs.tar.gz"
local ulo_rootfs="$(pwd)/./ULO-Builder/rootfs"
local rootfs_name="openwrt-${version}-armsr-armv8-generic-rootfs.tar.gz"
echo "Copying rootfs to ULO-Builder..."
echo "Source: $rootfs_file"
echo "Destination: $ulo_rootfs"
if [ ! -f "$rootfs_file" ]; then
echo "Error: Rootfs file not found at $rootfs_file"
ls -l "${new_name}/bin/targets/armsr/armv8/"
return 1
fi
mkdir -p "$ulo_rootfs"
cp -v "$rootfs_file" "$ulo_rootfs/$rootfs_name" || {
echo "Error: Failed to copy rootfs"
echo "Current directory: $(pwd)"
return 1
}
if [ -f "$ulo_rootfs/$rootfs_name" ]; then
echo "Rootfs successfully copied to ULO-Builder"
ls -l "$ulo_rootfs"
sed -i '/^ROOTFS=/d' "$CONFIG_FILE"
echo "ROOTFS=$rootfs_name" >> "$CONFIG_FILE"
echo "Rootfs name has been saved to config file"
else
echo "Error: File not found after copying"
return 1
fi
return 0
}
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: Config file not found"
exit 1
fi
version=$(grep "VERSION=" "$CONFIG_FILE" | cut -d'=' -f2)
if [ -z "$version" ]; then
echo "Error: VERSION not found in config file"
exit 1
fi
echo "Using OpenWrt version $version"
setup_image_builder "$version" && \
update_rootfs_size "$version" && \
build_image "$version" && \
copy_rootfs "$version"