This commit is contained in:
pedro 2024-09-24 10:51:14 -03:00
parent 8e4186d9d4
commit a60a6e6539
4 changed files with 89 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ iso
settings.ini settings.ini
# ignore all possible snapshots in this dir # ignore all possible snapshots in this dir
*.json *.json
pxe/.env

4
pxe/.env.example Normal file
View File

@ -0,0 +1,4 @@
server_ip=192.168.1.2
nfs_allowed_lan=192.168.1.0/24
tftp_path='/srv/pxe-tftp'
nfs_path='/srv/pxe-images'

3
pxe/README.md Normal file
View File

@ -0,0 +1,3 @@
Run `install-pxe.sh`
inspired on https://farga.exo.cat/exo/wiki/src/branch/master/howto/apu/apu-installer.md

81
pxe/install-pxe.sh Executable file
View File

@ -0,0 +1,81 @@
#!/bin/sh
# Copyright (c) 2024 Pedro <copyright@cas.cat>
# SPDX-License-Identifier: AGPL-3.0-or-later
set -e
set -u
# DEBUG
set -x
install_dependencies() {
apt update
apt install -y wget dnsmasq nfs-kernel-server
}
backup_file() {
target="${1}"
ts="$(date +'%Y-%m-%d_%H-%M-%S')"
if [ -f "${target}" ]; then
cp -a "${target}" "${target}_bak_${ts}"
fi
}
install_nfs() {
backup_file /etc/exports
cat /etc/exports <<END
${nfs_path} ${nfs_allowed_lan}(rw,sync,no_subtree_check,no_root_squash)
END
}
install_tftp() {
# TODO creo que se puede hacer un fichero de config específico
# podría ser algo como /etc/dnsmasq.conf.d/my-pxe-server ?
#backup_file /etc/dnsmasq.conf
cat /etc/exports <<END
${nfs_path} ${nfs_allowed_lan}(rw,sync,no_subtree_check,no_root_squash)
END
}
install_netboot() {
# if you want to refresh install, remove or move dir
if [ ! -d "${tftp_path}" ]; then
mkdir -p "${tftp_path}"
cd "${tftp_path}"
wget http://ftp.debian.org/debian/dists/${VERSION_CODENAME}/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar xvf netboot.tar.gz
cat "${tftp_path}/pxelinux.cfg/default" <<END
default wb
label wb
KERNEL vmlinuz
INITRD initd.img
APPEND ip=dhcp netboot=nfs nfsroot=${server_ip}:${nfs_path}/ boot=live text forcepae
END
fi
}
init_config() {
if [ -f ./.env ]; then
. ./env
else
echo 'WARNING: ./env does not exist, cannot read config from there'
fi
VERSION_CODENAME="${VERSION_CODENAME:-bookworm}"
tftp_path="${tftp_path:-/srv/pxe-tftp}"
server_ip="${server_ip}"
nfs_path="${nfs_path:-/srv/pxe-images}"
}
main() {
init_config
install_dependencies
install_netboot
install_tftp
install_nfs
}
main "${@}"
# written in emacs
# -*- mode: shell-script; -*-