You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

#!/bin/bash
# Use this Script on a fresh CentOS 8 Installation
#
# https://codeberg.org/angestoepselt/LinuxPXE/
# created by angestoepselt e.V.
# November 2020
REPO=https://codeberg.org/angestoepselt/LinuxPXE.git
working_dir=/srv/tftp
##############################################
### DO NOT change anything below this line ###
##############################################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
#variables
ipaddr=$(hostname -I | awk '{print $1}')
## install dependencies and clone repo
echo "install dependencies and clone repo"
yum install -y tftp-server dnsmasq git nginx
if [ -d "$working_dir" ]; then
echo "${working_dir} exists, do backup"
mv $working_dir /srv/tftp_backup
echo "moved to tftp_backup"
fi
git clone ${REPO} $working_dir
echo "disabling firewall"
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
# deactivate selinux
echo "deactivating selinux"
sed -i -e 's/permissive\|enforcing/disabled/g' /etc/sysconfig/selinux
echo "add pxe.conf to dnsmasq"
tee -a /etc/dnsmasq.d/pxe.conf > /dev/null <<EOT
tftp-root=$working_dir
enable-tftp
dhcp-boot=legacy/pxelinux.0
dhcp-option=vendor:PXEClient,6,2b
dhcp-no-override
dhcp-range=${ipaddr},proxy
EOT
echo "disabled = no" > /etc/xinetd.d/tftp
systemctl restart tftp dnsmasq && systemctl enable tftp dnsmasq
### modify nginx autoindex on and tftp folder as root folder
sed -i -e 's/\/usr\/share\/nginx\/html/\/srv\/tftp/g' /etc/nginx/nginx.conf
sed -i -e '/^http {/,/^}/{/^}/i\autoindex on;' -e '}' /etc/nginx/nginx.conf
echo ''
echo '############################'
echo '### your server is ready ###'
echo '### run modify_pxe.sh ###'
echo '############################'
echo ''
exit 0