mirror of
https://github.com/leitbogioro/Tools.git
synced 2024-11-15 05:34:34 +08:00
Update autoRepackAlmaLinuxCloudImages.sh
This commit is contained in:
parent
1fc649ea8f
commit
1df1a4db9e
1 changed files with 30 additions and 30 deletions
|
@ -11,39 +11,39 @@ websiteDir="/www/wwwroot/cloud-images.a.disk.re/$linuxName"
|
||||||
[[ ! -d "$websiteDir" ]] && mkdir -p "$websiteDir"
|
[[ ! -d "$websiteDir" ]] && mkdir -p "$websiteDir"
|
||||||
|
|
||||||
for distNum in "9"; do
|
for distNum in "9"; do
|
||||||
for archType in "x86_64" "aarch64"; do
|
for archType in "x86_64" "aarch64"; do
|
||||||
fileName="$linuxName-$distNum-GenericCloud-latest.$archType"
|
fileName="$linuxName-$distNum-GenericCloud-latest.$archType"
|
||||||
# Replace "wget" to "axel" because axel supports multithreading and improve speed of downloading.
|
# Replace "wget" to "axel" because axel supports multithreading and improve speed of downloading.
|
||||||
axel -n 16 -k -q -o /root/$fileName.qcow2 "https://repo.almalinux.org/almalinux/$distNum/cloud/$archType/images/$fileName.qcow2"
|
axel -n 16 -k -q -o /root/$fileName.qcow2 "https://repo.almalinux.org/almalinux/$distNum/cloud/$archType/images/$fileName.qcow2"
|
||||||
qemu-img convert -f qcow2 -O raw /root/$fileName.qcow2 /root/$fileName.raw
|
qemu-img convert -f qcow2 -O raw /root/$fileName.qcow2 /root/$fileName.raw
|
||||||
losetup $loopDevice /root/$fileName.raw
|
losetup $loopDevice /root/$fileName.raw
|
||||||
# Add some parameters for kernel aims to "redirect name of network adapters", "disable kdump", "disable selinux".
|
# Add some parameters for kernel aims to "redirect name of network adapters", "disable kdump", "disable selinux".
|
||||||
grub2DirDevice=$(kpartx -av $loopDevice | grep "$loopDeviceNum" | sort -rn | sed -n '2p' | awk '{print $3}')
|
grub2DirDevice=$(kpartx -av $loopDevice | grep "$loopDeviceNum" | sort -rn | sed -n '2p' | awk '{print $3}')
|
||||||
sysDirDevice=$(kpartx -av $loopDevice | grep "$loopDeviceNum" | sort -rn | sed -n '1p' | awk '{print $3}')
|
sysDirDevice=$(kpartx -av $loopDevice | grep "$loopDeviceNum" | sort -rn | sed -n '1p' | awk '{print $3}')
|
||||||
mount /dev/mapper/$grub2DirDevice /mnt
|
mount /dev/mapper/$grub2DirDevice /mnt
|
||||||
sed -ri 's/biosdevname=0.*/net.ifnames=0 biosdevname=0 crashkernel=0 selinux=0 "/g' /mnt/grub2/grub.cfg
|
sed -ri 's/biosdevname=0.*/net.ifnames=0 biosdevname=0 crashkernel=0 selinux=0 "/g' /mnt/grub2/grub.cfg
|
||||||
umount /mnt
|
umount /mnt
|
||||||
mount /dev/mapper/$sysDirDevice /mnt
|
mount /dev/mapper/$sysDirDevice /mnt
|
||||||
sed -ri 's/biosdevname=0.*/net.ifnames=0 biosdevname=0 crashkernel=0 selinux=0"/g' /mnt/etc/default/grub
|
sed -ri 's/biosdevname=0.*/net.ifnames=0 biosdevname=0 crashkernel=0 selinux=0"/g' /mnt/etc/default/grub
|
||||||
umount /mnt
|
umount /mnt
|
||||||
kpartx -dv $loopDevice
|
kpartx -dv $loopDevice
|
||||||
losetup -d $loopDevice
|
losetup -d $loopDevice
|
||||||
# Transfer file format from ".raw" to ".xz" because xz can skip sparse files of cloud images and has a very light size aims to reduce I/O of network expenses.
|
# Transfer file format from ".raw" to ".xz" because xz can skip sparse files of cloud images and has a very light size aims to reduce I/O of network expenses.
|
||||||
xz -z -1 -T 0 /root/$fileName.raw
|
xz -z -1 -T 0 /root/$fileName.raw
|
||||||
mv /root/$fileName.raw.xz /root/$fileName.xz
|
mv /root/$fileName.raw.xz /root/$fileName.xz
|
||||||
rm -rf $websiteDir/$fileName.xz
|
rm -rf $websiteDir/$fileName.xz
|
||||||
mv /root/$fileName.xz $websiteDir/$fileName.xz
|
mv /root/$fileName.xz $websiteDir/$fileName.xz
|
||||||
rm -rf /root/$fileName.raw
|
rm -rf /root/$fileName.raw
|
||||||
rm -rf /root/$fileName.qcow2
|
rm -rf /root/$fileName.qcow2
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
# write crontab task
|
# write crontab task
|
||||||
# Crontab simulator: https://crontab.guru/
|
# Crontab simulator: https://crontab.guru/
|
||||||
# Schedule cronjob for the certain day in a week: https://blog.healthchecks.io/2022/09/schedule-cron-job-the-funky-way/
|
# Schedule cronjob for the certain day in a week: https://blog.healthchecks.io/2022/09/schedule-cron-job-the-funky-way/
|
||||||
if [[ ! `grep -i "autorepackalmalinuxcloudimages" /etc/crontab` ]]; then
|
if [[ ! $(grep -i "autorepackalmalinuxcloudimages" /etc/crontab) ]]; then
|
||||||
sed -i '$i 0 7 */100,1-7 * SUN root bash /root/autoRepackAlmaLinuxCloudImages.sh' /etc/crontab
|
sed -i '$i 0 7 */100,1-7 * SUN root bash /root/autoRepackAlmaLinuxCloudImages.sh' /etc/crontab
|
||||||
crontab -l
|
crontab -l
|
||||||
/etc/init.d/cron reload
|
/etc/init.d/cron reload
|
||||||
/etc/init.d/cron restart
|
/etc/init.d/cron restart
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue