Update autoRepackUbuntuCloudImages.sh

This commit is contained in:
Molly Lau 2023-11-13 23:34:59 +09:00 committed by GitHub
parent 96b97c6e3f
commit cdd8957b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,11 @@ linuxName="Ubuntu"
websiteDir="/www/wwwroot/cloud-images.a.disk.re/$linuxName"
[[ ! -d "$websiteDir" ]] && mkdir -p "$websiteDir"
for distName in "jammy" "focal" "noble"; do
for distNum in "20.04" "22.04" "24.04"; do
distYearsNum=$(echo $distNum | cut -d'.' -f 1)
[[ "$distYearsNum" == "20" ]] && distName="focal"
[[ "$distYearsNum" == "22" ]] && distName="jammy"
[[ "$distYearsNum" == "24" ]] && distName="noble"
for archType in "amd64" "arm64"; do
fileName="$distName-server-cloudimg-$archType"
axel -n 16 -k -q -o /root/$fileName.img "https://cloud-images.ubuntu.com/$distName/current/$fileName.img"
@ -19,10 +23,18 @@ for distName in "jammy" "focal" "noble"; do
mapperDevice=$(kpartx -av $loopDevice | grep "$loopDeviceNum" | head -n 1 | awk '{print $3}')
mount /dev/mapper/$mapperDevice /mnt
sed -ri 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"/g' /mnt/etc/default/grub
if [[ "$distYearsNum" -le "22" ]]; then
sed -ri 's/cloudimg-rootfs ro/cloudimg-rootfs ro net.ifnames=0 biosdevname=0/g' /mnt/boot/grub/grub.cfg
# sed -ri 's/GRUB_TIMEOUT=0/GRUB_TIMEOUT=3/g' /mnt/etc/default/grub
# sed -ri 's/set timeout=0/set timeout=3/g' /mnt/boot/grub/grub.cfg
umount /mnt
else
umount /mnt
mapperDevice=$(kpartx -av $loopDevice | grep "$loopDeviceNum" | sort -rn | head -n 1 | awk '{print $3}')
mount /dev/mapper/$mapperDevice /mnt
sed -ri 's/cloudimg-rootfs ro/cloudimg-rootfs ro net.ifnames=0 biosdevname=0/g' /mnt/grub/grub.cfg
umount /mnt
fi
kpartx -dv $loopDevice
losetup -d $loopDevice
xz -z -1 -T 0 /root/$fileName.raw