Skip to content

Commit

Permalink
Clean-up deploy-pxe-artifacts.sh script.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmileka committed Sep 27, 2024
1 parent b1f81dc commit 89e6363
Showing 1 changed file with 2 additions and 125 deletions.
127 changes: 2 additions & 125 deletions toolkit/tools/imagecustomizer/pxe-azl-livenet/deploy-pxe-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ mount_dir=/mnt/$(basename $sourceIsoPath)
tftpbootLocalDir="/var/lib/tftpboot"
httpLocalDir="/etc/httpd/marineros"
httpRoot="http://192.168.0.1/marineros"
# isoRelativePath=liveos/azure-linux.iso
isoRelativePath=liveos/
# optional arguments
hostScriptRelativePath=liveos/host-script.sh
hostConfigRelativePath=liveos/host-config.cfg

# ---- helper functions ----

Expand All @@ -47,107 +43,8 @@ function copy_file () {
chown root:root $target_file
}

# function createPxeGrubCfg() {
# local pxeGrubCfg=$1
# local isoRelativePath=$2
# local hostScriptRelativePath=$3
# local hostConfigRelativePath=$4

# if [[ -z $httpRoot ]]; then
# echo "error: failed to create grub.cfg. An http root path must be specified."
# exit 1
# fi

# if [[ -z $isoRelativePath ]]; then
# echo "error: failed to create grub.cfg. An iso relative path must be specified."
# exit 1
# fi

# rdRoot="root=live:$httpRoot/$isoRelativePath"

# if [[ -n $hostScriptRelativePath ]]; then
# rdHostScript="rd.host.script=live:$httpRoot/$hostScriptRelativePath"
# fi

# if [[ -n $hostConfigRelativePath ]]; then
# rdHostConfig="rd.host.config=live:$httpRoot/$hostConfigRelativePath"
# fi

# cat <<EOF > $pxeGrubCfg
# set timeout=10
# set bootprefix=/boot
# # set debug=all

# menuentry "CBL-Mariner" {
# linux /boot/vmlinuz \\
# ip=dhcp \\
# $rdRoot \\
# $rdHostScript \\
# $rdHostConfig \\
# rd.auto=1 \\
# selinux=0 security= \\
# console=tty0 console=ttyS0 \\
# sysctl.kernel.unprivileged_bpf_disabled=1 \\
# rd.info \\
# log_buf_len=1M \\
# rd.shell \\
# rd.live.image \\
# rd.live.dir=liveos \\
# rd.live.squashimg=rootfs.img \\
# rd.live.overlay=1 \\
# rd.live.overlay.overlayfs \\
# rd.live.overlay.nouserconfirmprompt

# initrd /boot/initrd.img
# }
# EOF

# chmod 755 $pxeGrubCfg
# chown root:root $pxeGrubCfg
# }

function createPxeHostCfg() {
local pxeHostConfig=$1

cat <<EOF > $pxeHostConfig
hostname=pxetestclient
configserver=http://192.168.0.1
EOF

chmod 644 $pxeHostConfig
chown root:root $pxeHostConfig
}

function createPxeHostScript() {
local pxeHostScript=$1

cat <<EOF > $pxeHostScript
#!/bin/bash
# set -x
set -e
echo "executing pre-pivote user script with (\$1)" > /dev/kmsg
filename=\$1
if [[ -n "\$filename" ]]; then
while IFS='=' read -r key value; do
# Skip empty lines
[ -z "\$key" ] && continue
# Process the key and value
echo "Key: \$key" > /dev/kmsg
echo "Value: \$value" > /dev/kmsg
done < "\$filename"
fi
EOF

chmod 755 $pxeHostScript
chown root:root $pxeHostScript
}

function deploy_tftp_folder() {
local isoRelativePath=$1
local hostScriptRelativePath=$2
local hostConfigRelativePath=$3

copy_file $mount_dir/efi/boot/grubx64.efi $tftpbootLocalDir/grubx64.efi
copy_file $mount_dir/efi/boot/bootx64.efi $tftpbootLocalDir/bootx64.efi
Expand All @@ -157,36 +54,16 @@ function deploy_tftp_folder() {
copy_file $mount_dir/boot/initrd.img $tftpbootLocalDir/boot/initrd.img

mkdir -p $tftpbootLocalDir/boot/grub2
#
# this file is only needed for the iso
# copy_file $mount_dir/boot/grub2/efiboot.img $tftpbootLocalDir/boot/grub2/efiboot.img
#

copy_file $mount_dir/boot/grub2/grub-pxe.cfg $tftpbootLocalDir/boot/grub2/grub.cfg

sed -i 's/iso-publish-path/192.168.0.1\/marineros\/liveos/g' $tftpbootLocalDir/boot/grub2/grub.cfg

# createPxeGrubCfg \
# $tftpbootLocalDir/boot/grub2/grub.cfg \
# $isoRelativePath \
# $hostScriptRelativePath \
# $hostConfigRelativePath
}

function deploy_http_folder() {
local isoRelativePath=$1
local hostScriptRelativePath=$2
local hostConfigRelativePath=$3
mkdir -p $httpLocalDir/liveos
chmod 755 $httpLocalDir/liveos
# copy_file $mount_dir/liveos/rootfs.img $httpLocalDir/liveos/rootfs.img
copy_file $sourceIsoPath $httpLocalDir/$isoRelativePath/$(basename $sourceIsoPath)
# if [[ -n $hostScriptRelativePath ]]; then
# createPxeHostScript $httpLocalDir/$hostScriptRelativePath
# fi
# if [[ -n $hostConfigRelativePath ]]; then
# createPxeHostCfg $httpLocalDir/$hostConfigRelativePath
# fi
}

function clean() {
Expand All @@ -199,8 +76,8 @@ function deploy() {
sudo mkdir -p $mount_dir
sudo mount $sourceIsoPath $mount_dir

deploy_http_folder $isoRelativePath $hostScriptRelativePath $hostConfigRelativePath
deploy_tftp_folder $isoRelativePath $hostScriptRelativePath $hostConfigRelativePath
deploy_http_folder $isoRelativePath
deploy_tftp_folder $isoRelativePath
systemctl restart httpd

sudo umount $mount_dir
Expand Down

0 comments on commit 89e6363

Please sign in to comment.