Last active
August 29, 2015 14:19
-
-
Save hvanderlaan/57e8983a86463ef94c7b to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# deploy-pxe-server.sh: This script will setup a pxe boot / install server | |
# it will install all required packages and will place or alter the | |
# configurations files if needed. | |
# | |
# Author : Harald van der Laan | |
# Version: v0.1 | |
# Date : 15/apr/2015 | |
############################################################ | |
## functions | |
function spinner() { | |
# This function will display a spinner to let you know that | |
# the script is still running. | |
local pid=${1} | |
local delay=0.175 | |
local spinstr='|/-\' | |
local infotext=${2} | |
tput civis; | |
while [ "$(ps a | awk '{print $1}' | grep ${pid})" ]; do | |
local temp=${spinstr#?} | |
printf " [%c] %s" "${spinstr}" "${infotext}" | |
local spinstr=${temp}${spinstr%${temp}} | |
sleep ${delay} | |
printf "\b\b\b\b\b\b" | |
for i in $(seq 1 ${#infotext}); do | |
printf "\b" | |
done | |
done | |
printf " \b\b\b\b" | |
tput cnorm; | |
} | |
############################################################ | |
## Main script | |
if [ $(id -u) -ne 0 ]; then | |
echo " [Error]: This script must be runned with root privileges." | |
exit 1 | |
fi | |
# Installing required software | |
apt-get -qq update & spinner ${!} "Updating apt repository ..." | |
apt-get -qq --assume-yes install tftpd-hpa & spinner ${!} "Installing tftpd-hpa ..." | |
apt-get -qq --assume-yes install isc-dhcp-server & spinner ${!} "Installing isc-dhcp-server ..." | |
apt-get -qq --assume-yes install inetutils-inetd & spinner ${!} "Installing inetd ..." | |
apt-get -qq --assume-yes install nginx & spinner ${!} "Installing nginx ..." | |
# Settingup tftpd-hpa | |
echo " [ ] Configurating tftpd-hpa ..." | |
echo 'RUN_DAEMON="yes"' >> /etc/default/tftpd-hpa | |
echo 'OPTIONS="-l -s /var/lib/tftpboot' >> /etc/default/tftpd-hpa | |
echo " [+] Done setting up tftpd-hpa ..." | |
# Settingup isc-dhcp-server | |
echo " [ ] Configurating isc-dhcp-server ..." | |
cat << EOF >> /etc/dhcp/dhcpd.conf | |
subnet 172.16.1.0 netmask 255.255.255.0 { | |
range 172.16.1.100 172.16.1.200; | |
filename "pxelinux.0" | |
} | |
EOF | |
echo " [+] Done setting up isc-dhcp-server ..." | |
# Settingup inetd | |
echo " [ ] Configurating inetd ..." | |
echo "tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot" >> /etc/inetd.conf | |
echo " [+] Done setting up inetd ..." | |
# Settingup nginx | |
echo " [ ] Configurating nginx ..." | |
cat << EOF > /etc/nginx/sites-enabled/default | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
location / { | |
# try_files \$uri \$uri/ =404; | |
} | |
} | |
EOF | |
# Restarting applications | |
service tftpd-hpa restart &> /dev/null && echo " [+] tftpd-hpa restarted ..." | |
service isc-dhcp-server restart &> /dev/null && echo " [+] isc-dhcp-server restarted ..." | |
service nginx restart &> /dev/null && echo " [+] nginx restarted ..." | |
echo | |
echo " [ ] Manuel things to do: mount ubuntu iso to /mnt" | |
echo " [ ] sudo mount -o loop <device | iso file> /mnt" | |
echo " [ ] sudo cp -avr /mnt/install/netboot/* /var/lib/tftpboot/" | |
echo " [ ] sudo cp -avr /mnt/* /usr/share/nginx/html/ubuntu" | |
echo | |
echo " [ ] place a valid boot menu in /var/lib/tftpboot/pxelinux.cfg/default" | |
echo | |
echo " [ ] Example boot menu." | |
echo "default ubuntu-installer/amd64/boot-screems/vesamenu.c32" | |
echo "prompt 0" | |
echo "timeout 10" | |
echo | |
echo "label Install Ubuntu 14.04 LTS" | |
echo " menu default" | |
echo " menu label Install Ubuntu 14.04 LTS" | |
echo " kernel ubuntu-installer/amd64/linux" | |
echo " append url=http://this-host-ip/ubuntu/preseed/server.cfg auto=true priority=critical interface=auto \ " | |
echo " console-keymap-at/keymap=us locale=en_US hostname=ubuntu domain=localhost \ " | |
echo " initrd=ubuntu-installer/amd64/initrd.gz ramdisk_size=16432 root=/dev.rd/0 rw --" | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment