Skip to content

Instantly share code, notes, and snippets.

@pietrushnic
Last active March 26, 2020 23:44
Show Gist options
  • Save pietrushnic/3bef685b05ed9e441e3131439b096392 to your computer and use it in GitHub Desktop.
Save pietrushnic/3bef685b05ed9e441e3131439b096392 to your computer and use it in GitHub Desktop.
#!/bin/bash
TFTP_SERVER="root@192.168.10.1"
ISO_URL=https://updates.xcp-ng.org/isos/8.1/xcp-ng-8.1.0-prefinal2.iso
# ISO_URL=https://updates.xcp-ng.org/isos/8.0/xcp-ng-8.0.0.iso
ISO_FILE_NAME=$(basename ${ISO_URL})
# get xcp-ng image
[ ! -f ${ISO_FILE_NAME} ] && wget ${ISO_URL}
# mount
[ ! -d isomount ] && mkdir isomount
[ ! mountpoint isomount ] && umount isomount
sudo mount -o loop ${ISO_FILE_NAME} isomount
# deploy files to tftp
# tftpboot
# ├── efi
#    └── xenserver
#    ├── bootx64.efi
#    ├── install.img
#    ├── vmlinuz
#    └── xen.gz
if ssh ${TFTP_SERVER} "test -e /tftpboot/xen.gz"; then
remote_sha25sum=$(ssh ${TFTP_SERVER} sha256sum /tftpboot/xen.gz| cut -d" " -f1)
local_sha256sum=$(sha256sum isomount/boot/xen.gz| cut -d" " -f1)
if [ "$remote_sha25sum" != "$local_sha256sum" ]; then
scp isomount/boot/xen.gz ${TFTP_SERVER}:/tftpboot
fi
fi
if ssh ${TFTP_SERVER} "test -e /tftpboot/vmlinuz"; then
remote_sha25sum=$(ssh ${TFTP_SERVER} sha256sum /tftpboot/vmlinuz| cut -d" " -f1)
local_sha256sum=$(sha256sum isomount/boot/vmlinuz| cut -d" " -f1)
if [ "$remote_sha25sum" != "$local_sha256sum" ]; then
scp isomount/boot/vmlinuz ${TFTP_SERVER}:/tftpboot
fi
fi
if ssh ${TFTP_SERVER} "test -e /tftpboot/install.img"; then
remote_sha25sum=$(ssh ${TFTP_SERVER} sha256sum /tftpboot/install.img| cut -d" " -f1)
local_sha256sum=$(sha256sum isomount/install.img| cut -d" " -f1)
if [ "$remote_sha25sum" != "$local_sha256sum" ]; then
scp isomount/install.img ${TFTP_SERVER}:/tftpboot
fi
fi
# prepare bootx64.efi
grub-mkstandalone -d /usr/lib/grub/x86_64-efi/ -O x86_64-efi --fonts=“unicode” -o bootx64.efi boot/grub/grub.cfg
scp bootx64.efi ${TFTP_SERVER}:/tftpboot
# sudo umount isomount
# rm -rf bootx64.efi``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment