Created
June 14, 2016 20:08
-
-
Save daid/ac6e061faaae4fddccd2f8ed919537fe 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 | |
set -e | |
set -u | |
### Parameters for the installation. | |
TARGET_NFS_DIR=/srv/nfsroot/ | |
TARGET_TFTP_DIR=/srv/tftp/ | |
MIRROR=http://ftp.debian.org/debian/ | |
ETH=eth0 | |
# Install packages that we need on the host system to install our PXE environment, which includes dnsmasq as a dhcp-server and tftp-server and nfs for the network files system. | |
apt-get -y install debootstrap zip coreutils util-linux e2fsprogs dnsmasq nfs-common nfs-kernel-server | |
mkdir -p ${TARGET_NFS_DIR} | |
mkdir -p ${TARGET_TFTP_DIR} | |
# Build a basic rootfs system (This takes a while) | |
debootstrap --arch i386 jessie ${TARGET_NFS_DIR} ${MIRROR} | |
# Setup apt-get configuration on the new rootfs. | |
cat > ${TARGET_NFS_DIR}/etc/apt/sources.list <<-EOT | |
deb ${MIRROR} stable main contrib non-free | |
deb-src ${MIRROR} stable main contrib non-free | |
deb http://security.debian.org/ stable/updates main contrib non-free | |
deb-src http://security.debian.org/ stable/updates main contrib non-free | |
deb http://ftp.debian.org/ stable-updates main contrib non-free | |
deb-src http://ftp.debian.org/ stable-updates main contrib non-free | |
EOT | |
# Setup the PXE network interfaces configuration. This is the configuration the clients will use to bring up their network. | |
# Assumes that they have a single LAN card. | |
cat > ${TARGET_NFS_DIR}/etc/network/interfaces <<-EOT | |
auto lo | |
iface lo inet loopback | |
allow-hotplug eth0 | |
iface eth0 inet dhcp | |
EOT | |
# Setup the nfs root in a way so we can chroot into it. | |
mount -t proc none ${TARGET_NFS_DIR}/proc | |
mount --bind /sys ${TARGET_NFS_DIR}/sys | |
mount --bind /dev ${TARGET_NFS_DIR}/dev | |
mount -t tmpfs none ${TARGET_NFS_DIR}/tmp | |
cp /etc/resolv.conf ${TARGET_NFS_DIR}/etc/resolv.conf | |
# Setup a random hostname on the NFS root (This might confuse some applications, as the hostname is random on each read) | |
rm ${TARGET_NFS_DIR}/etc/hostname | |
ln -s /proc/sys/kernel/random/uuid ${TARGET_NFS_DIR}/etc/hostname | |
# Get syslinux/pxelinux, which contains a lot of files, but we need some of these to get PXE booting to work. | |
sudo apt-get -y install pxelinux syslinux-efi | |
mkdir -p ${TARGET_TFTP_DIR}/bios | |
mkdir -p ${TARGET_TFTP_DIR}/efi32 | |
mkdir -p ${TARGET_TFTP_DIR}/efi64 | |
cp /usr/lib/PXELINUX/pxelinux.0 ${TARGET_TFTP_DIR}/bios/ | |
cp /usr/lib/syslinux/modules/bios/*.c32 ${TARGET_TFTP_DIR}/bios/ | |
cp /usr/lib/SYSLINUX.EFI/efi32/syslinux.efi ${TARGET_TFTP_DIR}/efi32/ | |
cp /usr/lib/syslinux/modules/efi32/*.e32 ${TARGET_TFTP_DIR}/efi32/ | |
cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi ${TARGET_TFTP_DIR}/efi64/ | |
cp /usr/lib/syslinux/modules/efi64/*.e64 ${TARGET_TFTP_DIR}/efi64/ | |
# Setup the pxelinux configuration | |
mkdir -p ${TARGET_TFTP_DIR}/pxelinux.cfg | |
cat > ${TARGET_TFTP_DIR}/pxelinux.cfg/default <<-EOT | |
DEFAULT linux | |
LABEL linux | |
KERNEL vmlinuz.img | |
APPEND ro root=/dev/nfs nfsroot=192.168.55.1:${TARGET_NFS_DIR} initrd=initrd.img | |
EOT | |
ln -s ${TARGET_TFTP_DIR}/pxelinux.cfg ${TARGET_TFTP_DIR}/bios/pxelinux.cfg | |
ln -s ${TARGET_TFTP_DIR}/pxelinux.cfg ${TARGET_TFTP_DIR}/efi32/pxelinux.cfg | |
ln -s ${TARGET_TFTP_DIR}/pxelinux.cfg ${TARGET_TFTP_DIR}/efi64/pxelinux.cfg | |
ln -s ${TARGET_TFTP_DIR}/vmlinuz.img ${TARGET_TFTP_DIR}/bios/vmlinuz.img | |
ln -s ${TARGET_TFTP_DIR}/vmlinuz.img ${TARGET_TFTP_DIR}/efi32/vmlinuz.img | |
ln -s ${TARGET_TFTP_DIR}/vmlinuz.img ${TARGET_TFTP_DIR}/efi64/vmlinuz.img | |
ln -s ${TARGET_TFTP_DIR}/initrd.img ${TARGET_TFTP_DIR}/bios/initrd.img | |
ln -s ${TARGET_TFTP_DIR}/initrd.img ${TARGET_TFTP_DIR}/efi32/initrd.img | |
ln -s ${TARGET_TFTP_DIR}/initrd.img ${TARGET_TFTP_DIR}/efi64/initrd.img | |
# Setup vmlinuz.img kernel in ${TARGET_TFTP_DIR} | |
chroot ${TARGET_NFS_DIR} apt-get -y install linux-image-686-pae firmware-linux-nonfree | |
cp ${TARGET_NFS_DIR}/boot/vmlinuz* ${TARGET_TFTP_DIR}/vmlinuz.img | |
cp ${TARGET_NFS_DIR}/boot/initrd.img* ${TARGET_TFTP_DIR}/initrd.img | |
# Setup the export to the /etc/exports file, this will server our root trough NFS after rebooting the system later. | |
cat > /etc/exports <<-EOT | |
${TARGET_NFS_DIR} *(ro,sync) | |
EOT | |
# Setup the network interface to a static IP. | |
cat > /etc/network/interfaces <<-EOT | |
auto lo | |
iface lo inet loopback | |
allow-hotplug ${ETH} | |
auto ${ETH} | |
iface ${ETH} inet static | |
address 192.168.55.1 | |
netmask 255.255.255.0 | |
gateway 192.168.55.1 | |
EOT | |
# Setup dnsmasq configuration to serve a PXE boot envirnoment, tftp-server, and to serve as dhcp server (as PXE is handled with DHCP and TFTP) | |
cat > /etc/dnsmasq.conf <<-EOT | |
interface=${ETH} | |
dhcp-range=192.168.55.10,192.168.55.254 | |
dhcp-boot=bios/pxelinux.0 | |
dhcp-match=set:efi32,option:client-arch,6 | |
dhcp-match=set:efi64,option:client-arch,7 | |
dhcp-match=set:efi64,option:client-arch,9 | |
dhcp-boot=tag:efi32,efi32/syslinux.efi | |
dhcp-boot=tag:efi64,efi64/syslinux.efi | |
enable-tftp | |
tftp-root=${TARGET_TFTP_DIR} | |
EOT | |
# Install tools in NFS root required to build EE. | |
chroot ${TARGET_NFS_DIR} apt-get update | |
chroot ${TARGET_NFS_DIR} apt-get -y install git build-essential libx11-dev cmake libxrandr-dev mesa-common-dev libglu1-mesa-dev libudev-dev libglew-dev libjpeg-dev libfreetype6-dev libopenal-dev libsndfile1-dev libxcb1-dev libxcb-image0-dev | |
# Install basic X setup in NFS root to allow us to run EE later on. | |
chroot ${TARGET_NFS_DIR} apt-get -y install xserver-xorg-core xserver-xorg-input-all xserver-xorg-video-all xinit alsa-base alsa-utils | |
# Download&install SFML,EE,SP (This takes a while) | |
chroot ${TARGET_NFS_DIR} git clone https://github.com/daid/EmptyEpsilon.git /root/EmptyEpsilon | |
chroot ${TARGET_NFS_DIR} git clone https://github.com/daid/SeriousProton.git /root/SeriousProton | |
wget http://www.sfml-dev.org/files/SFML-2.3.2-sources.zip -O ${TARGET_NFS_DIR}/root/SFML-2.3.2-sources.zip | |
unzip ${TARGET_NFS_DIR}/root/SFML-2.3.2-sources.zip -d ${TARGET_NFS_DIR}/root/ | |
chroot ${TARGET_NFS_DIR} sh -c 'cd /root/SFML-2.3.2 && cmake . && make -j 3 && make install && ldconfig' | |
mkdir -p ${TARGET_NFS_DIR}/root/EmptyEpsilon/_build | |
chroot ${TARGET_NFS_DIR} sh -c 'cd /root/EmptyEpsilon/_build && cmake .. -DSERIOUS_PROTON_DIR=$HOME/SeriousProton/ && make -j 3' | |
# Create a symlink for the final executable. | |
chroot ${TARGET_NFS_DIR} ln -s _build/EmptyEpsilon /root/EmptyEpsilon/EmptyEpsilon | |
# Create a symlink to store the options.ini file in /tmp/, this so the client can load a custom file. | |
ln -s /tmp/options.ini ${TARGET_NFS_DIR}/root/EmptyEpsilon/options.ini | |
# Create an install a systemd unit that runs EE. | |
cat > /????/ <<-EOT | |
[??SYSTEMD-UNIT-FILE??] | |
EOT | |
# EXTRA | |
cat > /etc/network/interfaces.dhcp_client <<-EOT | |
auto lo | |
iface lo inet loopback | |
allow-hotplug ${ETH} | |
auto ${ETH} | |
iface ${ETH} inet dhcp | |
EOT | |
cat > /root/dhcp_client.sh <<-EOT | |
#!/bin/bash | |
## Script to stop the dhcp server, and use the network port as normal client port. So we can access other networks. | |
ifdown -a | |
systemctl stop dnsmasq | |
ifup -a -i /etc/network/interfaces.dhcp_client | |
EOT | |
chmod +x /root/dhcp_client.sh | |
cat > /root/dhcp_client.sh <<-EOT | |
#!/bin/bash | |
## Script to stop the dhcp server, and use the network port as normal client port. So we can access other networks. | |
ifdown -a | |
systemctl start dnsmasq | |
ifup -a | |
EOT | |
chmod +x /root/dhcp_client.sh | |
cat > /root/update.sh <<-EOT | |
#!/bin/bash | |
## Script to update EE, assumes you have internet on this machine. | |
chroot ${TARGET_NFS_DIR} sh -c 'cd /root/SeriousProton/ && git pull' | |
chroot ${TARGET_NFS_DIR} sh -c 'cd /root/EmptyEpsilon/ && git pull' | |
chroot ${TARGET_NFS_DIR} sh -c 'cd /root/EmptyEpsilon/_build && cmake .. -DSERIOUS_PROTON_DIR=$HOME/SeriousProton/ && make -j 3' | |
EOT | |
chmod +x /root/update.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you have your /root/dhcp_client.sh file being overwritten on line 167.