Created
January 20, 2023 23:03
-
-
Save lemassykoi/99708a3e519a32e50211fcb3cbf5ee71 to your computer and use it in GitHub Desktop.
Script made to update Ubuntu Netboot for PXE Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# crontab -e | |
# 0 3 * * * /bin/bash /root/update_ubuntu_netboot.sh | |
# apt install syslinux-common | |
#============================================= | |
ubuntu_files='/srv/tftp/images/ubuntu' | |
iso_location='/srv/tftp/images/ISO' | |
dist=("focal" "jammy") | |
# focal 20.04 | |
# jammy 22.04 | |
mkdir -p /mnt/iso | |
cd /tmp | |
for str in ${dist[@]}; do | |
mkdir -p $ubuntu_files/$str | |
wget -q http://releases.ubuntu.com/$str/SHA256SUMS -O SHA256SUMS-$str | |
iso_filename=$(grep -F "server" SHA256SUMS-$str | cut -d '*' -f 2) | |
if test -f "$ubuntu_files/$str/current"; then | |
iso_previous=$(cat $ubuntu_files/$str/current) | |
else | |
echo "$iso_filename" > $ubuntu_files/$str/current | |
iso_previous="none" | |
fi | |
if [[ $iso_previous == $iso_filename ]]; then | |
echo -e "$str\t: Same ISO name, don't download" | |
rm -rf SHA256SUMS-$str | |
else | |
echo "$iso_filename" > $ubuntu_files/$str/current | |
iso_sha256=$(grep -F "server" SHA256SUMS-$str | cut -d ' ' -f 1) | |
echo -e "\n\tDownloading $str ISO..." | |
wget -q http://releases.ubuntu.com/$str/$iso_filename -O ubuntu.iso | |
chksum=$(sha256sum ubuntu.iso) | |
chksum_array=($chksum) | |
chksum=${chksum_array[0]} | |
#echo "checksum1 = $iso_sha256" | |
#echo "checksum2 = $chksum" | |
if [[ $chksum == $iso_sha256 ]]; then | |
echo -e "\t Checksum OK" | |
mount ubuntu.iso /mnt/iso | |
echo "Copying files..." | |
cp -f /mnt/iso/casper/{vmlinuz,initrd} $ubuntu_files/$str/ | |
umount /mnt/iso | |
mv ubuntu.iso $iso_location/ubuntu-$str.iso | |
if test -f "$ubuntu_files/$str/ldlinux.c32"; then | |
echo "ldlinux.c32 already present in $str directory" | |
else | |
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 $ubuntu_files/$str/ | |
fi | |
rm -rf SHA256SUMS-$str | |
else | |
echo "Checksum mismatch - nothing done." | |
fi | |
fi | |
done | |
echo "End." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment