Update autoRepackUbuntuCloudImages.sh

This commit is contained in:
Molly Lau 2023-09-23 17:00:29 +09:00 committed by GitHub
parent d03785d612
commit 6f78f18c98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,7 @@
#!/bin/bash
#
# kpartx and qumu-utils are required
apt install cron kpartx mount qemu-utils -y
apt install cron kpartx mount qemu-utils xz-utils -y
# get valid loop device
loopDevice=$(echo $(losetup -f))
loopDeviceNum=$(echo $(losetup -f) | cut -d'/' -f 3)
@ -22,14 +22,18 @@ for distName in "jammy" "focal"; do
umount /mnt
kpartx -dv $loopDevice
losetup -d $loopDevice
xz -z -1 -T 0 /root/$fileName.raw
mv /root/$fileName.raw.xz /root/$fileName.xz
rm -rf $websiteDir/$fileName.xz
mv /root/$fileName.xz $websiteDir/$fileName.xz
rm -rf $websiteDir/$fileName.raw
mv /root/$fileName.raw $websiteDir/$fileName.raw
rm -rf /root/$fileName.raw
rm -rf /root/$fileName.img
done
done
# write crontab task
if [[ ! `grep -i "autorepackubuntucloudimages" /etc/crontab` ]]; then
sed -i '$i 30 4 * * 0 root bash /root/autoRepackUbuntuCloudImages.sh' /etc/crontab
sed -i '$i 30 4 10-16,24-30 * 5 root bash /root/autoRepackUbuntuCloudImages.sh' /etc/crontab
/etc/init.d/cron restart
fi