-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_images.sh
302 lines (299 loc) · 16.9 KB
/
build_images.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
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
#!/bin/bash
# 从 https://github.com/oneclickvirt/incus_images 获取
run_funct="${1:-debian}"
is_build_image="${2:-false}"
build_arch="${3:-amd64}"
zip_name_list=()
opath=$(pwd)
rm -rf *.tar.xz
ls
# 检查并安装依赖工具
if command -v apt-get >/dev/null 2>&1; then
# ubuntu debian kali
if ! command -v sudo >/dev/null 2>&1; then
apt-get install sudo -y
fi
if ! command -v zip >/dev/null 2>&1; then
sudo apt-get install zip -y
fi
if ! command -v jq >/dev/null 2>&1; then
sudo apt-get install jq -y
fi
uname_output=$(uname -a)
if [[ $uname_output != *ARM* && $uname_output != *arm* && $uname_output != *aarch* ]]; then
if ! command -v snap >/dev/null 2>&1; then
sudo apt-get install snapd -y
fi
sudo systemctl start snapd
if ! command -v distrobuilder >/dev/null 2>&1; then
sudo snap install distrobuilder --classic
fi
else
# if ! command -v snap >/dev/null 2>&1; then
# sudo apt-get install snapd -y
# fi
# sudo systemctl start snapd
# if ! command -v distrobuilder >/dev/null 2>&1; then
# sudo snap install distrobuilder --classic
# fi
if ! command -v distrobuilder >/dev/null 2>&1; then
$HOME/goprojects/bin/distrobuilder --version
fi
if [ $? -ne 0 ]; then
sudo apt-get install build-essential -y
export CGO_ENABLED=1
export CC=gcc
wget https://go.dev/dl/go1.21.6.linux-arm64.tar.gz
chmod 777 go1.21.6.linux-arm64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-arm64.tar.gz
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
export GOPATH=$HOME/goprojects/
go version
apt-get install -q -y debootstrap rsync gpg squashfs-tools git make
git config --global user.name "daily-update"
git config --global user.email "[email protected]"
mkdir -p $HOME/go/src/github.com/lxc/
cd $HOME/go/src/github.com/lxc/
git clone https://github.com/lxc/distrobuilder
cd ./distrobuilder
make
export PATH=$HOME/goprojects/bin/distrobuilder:$PATH
echo $PATH
find $HOME -name distrobuilder -type f 2>/dev/null
$HOME/goprojects/bin/distrobuilder --version
fi
# wget https://api.ilolicon.com/distrobuilder.deb
# dpkg -i distrobuilder.deb
fi
if ! command -v debootstrap >/dev/null 2>&1; then
sudo apt-get install debootstrap -y
fi
fi
# 构建或列出不同发行版的镜像
build_or_list_images() {
local versions=()
local ver_nums=()
local variants=()
read -ra versions <<< "$1"
read -ra ver_nums <<< "$2"
read -ra variants <<< "$3"
local architectures=("$build_arch")
local len=${#versions[@]}
for ((i = 0; i < len; i++)); do
version=${versions[i]}
ver_num=${ver_nums[i]}
for arch in "${architectures[@]}"; do
for variant in "${variants[@]}"; do
# apk apt dnf egoportage opkg pacman portage yum equo xbps zypper luet slackpkg
if [[ "$run_funct" == "centos" || "$run_funct" == "fedora" || "$run_funct" == "openeuler" ]]; then
manager="yum"
elif [[ "$run_funct" == "kali" || "$run_funct" == "ubuntu" || "$run_funct" == "debian" ]]; then
manager="apt"
elif [[ "$run_funct" == "almalinux" || "$run_funct" == "rockylinux" || "$run_funct" == "oracle" ]]; then
manager="dnf"
elif [[ "$run_funct" == "archlinux" ]]; then
manager="pacman"
elif [[ "$run_funct" == "alpine" ]]; then
manager="apk"
elif [[ "$run_funct" == "openwrt" ]]; then
manager="opkg"
elif [[ "$run_funct" == "gentoo" ]]; then
manager="portage"
elif [[ "$run_funct" == "opensuse" ]]; then
manager="zypper"
else
echo "Unsupported distribution: $run_funct"
exit 1
fi
EXTRA_ARGS=""
if [[ "$run_funct" == "centos" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
if [ "$version" = "7" ] && [ "${arch}" != "amd64" ] && [ "${arch}" != "x86_64" ]; then
EXTRA_ARGS="-o source.url=http://mirror.math.princeton.edu/pub/centos-altarch/ -o source.skip_verification=true"
fi
if [ "$version" = "8-Stream" ] || [ "$version" = "9-Stream" ]; then
EXTRA_ARGS="${EXTRA_ARGS} -o source.variant=boot"
fi
if [ "$version" = "9-Stream" ]; then
EXTRA_ARGS="${EXTRA_ARGS} -o source.url=https://mirror1.hs-esslingen.de/pub/Mirrors/centos-stream"
fi
elif [[ "$run_funct" == "rockylinux" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
EXTRA_ARGS="-o source.variant=boot"
elif [[ "$run_funct" == "almalinux" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
EXTRA_ARGS="-o source.variant=boot"
elif [[ "$run_funct" == "oracle" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
if [[ "$version" == "9" ]]; then
EXTRA_ARGS="-o source.url=https://yum.oracle.com/ISOS/OracleLinux"
fi
elif [[ "$run_funct" == "archlinux" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
if [ "${arch}" != "amd64" ] && [ "${arch}" != "i386" ] && [ "${arch}" != "x86_64" ]; then
EXTRA_ARGS="-o source.url=http://os.archlinuxarm.org"
fi
elif [[ "$run_funct" == "alpine" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
if [ "${release}" = "edge" ]; then
EXTRA_ARGS="-o source.same_as=3.19"
fi
elif [[ "$run_funct" == "fedora" || "$run_funct" == "openeuler" || "$run_funct" == "opensuse" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
[ "${arch}" = "arm64" ] && arch="aarch64"
elif [[ "$run_funct" == "gentoo" ]]; then
[ "${arch}" = "x86_64" ] && arch="amd64"
[ "${arch}" = "aarch64" ] && arch="arm64"
if [ "${variant}" = "cloud" ]; then
EXTRA_ARGS="-o source.variant=openrc"
else
EXTRA_ARGS="-o source.variant=${variant}"
fi
elif [[ "$run_funct" == "debian" ]]; then
[ "${arch}" = "x86_64" ] && arch="amd64"
[ "${arch}" = "aarch64" ] && arch="arm64"
elif [[ "$run_funct" == "ubuntu" ]]; then
[ "${arch}" = "x86_64" ] && arch="amd64"
[ "${arch}" = "aarch64" ] && arch="arm64"
if [ "${arch}" != "amd64" ] && [ "${arch}" != "i386" ] && [ "${arch}" != "x86_64" ]; then
EXTRA_ARGS="-o source.url=http://ports.ubuntu.com/ubuntu-ports"
fi
fi
if [ "$is_build_image" == true ]; then
if command -v distrobuilder >/dev/null 2>&1; then
if [[ "$run_funct" == "gentoo" ]]; then
echo "sudo distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} ${EXTRA_ARGS}"
if sudo distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} ${EXTRA_ARGS}; then
echo "Command succeeded"
fi
elif [[ "$run_funct" != "archlinux" ]]; then
echo "sudo distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.release=${version} -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}"
if sudo distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.release=${version} -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}; then
echo "Command succeeded"
fi
else
echo "sudo distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}"
if sudo distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}; then
echo "Command succeeded"
fi
fi
else
if [[ "$run_funct" == "gentoo" ]]; then
echo "sudo $HOME/goprojects/bin/distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} ${EXTRA_ARGS}"
if sudo $HOME/goprojects/bin/distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} ${EXTRA_ARGS}; then
echo "Command succeeded"
fi
elif [[ "$run_funct" != "archlinux" ]]; then
echo "sudo $HOME/goprojects/bin/distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.release=${version} -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}"
if sudo $HOME/goprojects/bin/distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.release=${version} -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}; then
echo "Command succeeded"
fi
else
echo "sudo $HOME/goprojects/bin/distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}"
if sudo $HOME/goprojects/bin/distrobuilder build-incus "${opath}/images_yaml/${run_funct}.yaml" -o image.architecture=${arch} -o image.variant=${variant} -o packages.manager=${manager} ${EXTRA_ARGS}; then
echo "Command succeeded"
fi
fi
fi
# 强制设置架构名字
if [[ "$run_funct" == "gentoo" || "$run_funct" == "debian" || "$run_funct" == "ubuntu" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
elif [[ "$run_funct" == "fedora" || "$run_funct" == "openeuler" || "$run_funct" == "opensuse" || "$run_funct" == "alpine" || "$run_funct" == "oracle" || "$run_funct" == "archlinux" ]]; then
[ "${arch}" = "aarch64" ] && arch="arm64"
elif [[ "$run_funct" == "almalinux" || "$run_funct" == "centos" || "$run_funct" == "rockylinux" ]]; then
[ "${arch}" = "aarch64" ] && arch="arm64"
fi
if [ -f incus.tar.xz ] && [ -f rootfs.squashfs ]; then
zip "${run_funct}_${ver_num}_${version}_${arch}_${variant}.zip" incus.tar.xz rootfs.squashfs
rm -rf incus.tar.xz rootfs.squashfs
fi
else
# 强制设置架构名字
if [[ "$run_funct" == "gentoo" || "$run_funct" == "debian" || "$run_funct" == "ubuntu" ]]; then
[ "${arch}" = "amd64" ] && arch="x86_64"
elif [[ "$run_funct" == "fedora" || "$run_funct" == "openeuler" || "$run_funct" == "opensuse" || "$run_funct" == "alpine" || "$run_funct" == "oracle" || "$run_funct" == "archlinux" ]]; then
[ "${arch}" = "aarch64" ] && arch="arm64"
elif [[ "$run_funct" == "almalinux" || "$run_funct" == "centos" || "$run_funct" == "rockylinux" ]]; then
[ "${arch}" = "aarch64" ] && arch="arm64"
fi
zip_name_list+=("${run_funct}_${ver_num}_${version}_${arch}_${variant}.zip")
fi
done
done
done
if [ "$is_build_image" == false ]; then
echo "${zip_name_list[@]}"
fi
}
# 不同发行版的配置
# build_or_list_images 镜像名字 镜像版本号 variants的值
case "$run_funct" in
debian)
build_or_list_images "buster bullseye bookworm trixie" "10 11 12 13" "default cloud"
;;
ubuntu)
build_or_list_images "bionic focal jammy lunar mantic noble" "18.04 20.04 22.04 23.04 23.10 24.04" "default cloud"
;;
kali)
build_or_list_images "kali-rolling" "latest" "default cloud"
;;
archlinux)
build_or_list_images "current" "current" "default cloud"
;;
gentoo)
build_or_list_images "current" "current" "cloud systemd openrc"
;;
centos)
build_or_list_images "7 8-Stream 9-Stream" "7 8 9" "default cloud"
;;
almalinux)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-almalinux.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
rockylinux)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-rockylinux.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
alpine)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-alpine.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
openwrt)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-openwrt.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
oracle)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-oracle.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
fedora)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-fedora.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
opensuse)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-opensuse.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
openeuler)
URL="https://raw.githubusercontent.com/lxc/lxc-ci/main/jenkins/jobs/image-openeuler.yaml"
curl_output=$(curl -s "$URL" | awk '/name: release/{flag=1; next} /^$/{flag=0} flag && /^ *-/{if (!first) {printf "%s", $2; first=1} else {printf " %s", $2}}' | sed 's/"//g')
build_or_list_images "$curl_output" "$curl_output" "default cloud"
;;
*)
echo "Invalid distribution specified."
;;
esac