updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / archiso-pxe-server / archiso-pxe-server
blobd48e22c5982fe696bee19686d63caa68eb08d5e2
1 #!/bin/bash
3 # A basic script to setup a PXE server enviroment for Arch Linux live-media.
4 # Contributed by Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
6 # Requires: dnsmasq and nbd packages
8 set -e
10 TMPDIR=/tmp/archiso-pxe-server
11 VERSION=20110819
12 INSTALL_DIR=arch
13 DNSMASQ_SKIP=false
14 NBD_SKIP=false
16 iso_umount() {
17 trap - 0 1 2 15
18 umount ${TMPDIR}/mnt
19 rmdir ${TMPDIR}/mnt
22 iso_mount() {
23 mkdir -p ${TMPDIR}/mnt
24 mount ${ISO} ${TMPDIR}/mnt -o ro,loop
25 trap 'iso_umount' 0 1 2 15
28 show_help()
30 exitvalue=${1}
31 echo
32 echo "archiso-pxe-server version ${VERSION}"
33 echo
34 echo "archiso-pxe-server [options]"
35 echo
36 echo " options:"
37 echo " -i [ip] ip address of the local interface to serve"
38 echo " (default: ${IP} )"
39 echo " -d [device] boot device of Arch Linux Live media"
40 echo " (default: ${DEVICE} )"
41 echo " -l [install_dir] install_dir of Arch Linux Live media"
42 echo " (default: ${INSTALL_DIR} )"
43 echo " -s [isofile] Arch Linux Live media iso image"
44 echo " (default: ${ISO} )"
45 echo " -m [mountpoint] path to [device] is mounted"
46 echo " (default: ${MNTPNT} )"
47 echo " -t [tftpboot] path to setup PXE enviroment"
48 echo " (default: ${TMPDIR} )"
49 echo " -j Skip dnsmasq start up"
50 echo " (default: ${DNSMASQ_SKIP} )"
51 echo " -k Skip nbd start up"
52 echo " (default: ${NBD_SKIP} )"
53 echo
54 exit ${exitvalue}
57 copy_files()
59 rm -rf ${TMPDIR}/syslinux
60 mkdir -p ${TMPDIR}/${INSTALL_DIR}
61 cp -r ${MNTPNT}/${INSTALL_DIR}/boot ${TMPDIR}/${INSTALL_DIR}
62 mv ${TMPDIR}/${INSTALL_DIR}/boot/syslinux ${TMPDIR}
63 mv ${TMPDIR}/${INSTALL_DIR} ${TMPDIR}/syslinux
64 sed -i 's|^#IPAPPEND|IPAPPEND|g' ${TMPDIR}/syslinux/*.cfg
65 mkdir -p ${TMPDIR}/syslinux/pxelinux.cfg
66 cp ${TMPDIR}/syslinux/syslinux.cfg ${TMPDIR}/syslinux/pxelinux.cfg/default
69 start_pxe_server()
71 pkill dnsmasq > /dev/null 2>&1 || true
72 dnsmasq \
73 --port=0 \
74 --enable-tftp \
75 --tftp-root=${TMPDIR} \
76 --dhcp-boot=syslinux/pxelinux.0,"${IP}" \
77 --dhcp-range=${IP%.*}.2,${IP%.*}.254,86400
80 start_nbd_server()
82 pkill nbd-server > /dev/null 2>&1 || true
83 echo "[generic]" > ${TMPDIR}/nbd-server.conf
84 echo "[archiso]" >> ${TMPDIR}/nbd-server.conf
85 echo " readonly = true" >> ${TMPDIR}/nbd-server.conf
86 echo " exportname = ${DEVICE}" >> ${TMPDIR}/nbd-server.conf
87 nbd-server -C ${TMPDIR}/nbd-server.conf
90 guess_enviroment()
92 if grep archisolabel /proc/cmdline > /dev/null; then
93 DEVICE=/dev/disk/by-label/$(sed "s/.*archisolabel=\([^ ]\+\).\+/\1/" /proc/cmdline)
94 MNTPNT=/bootmnt
97 if grep archisobasedir /proc/cmdline > /dev/null; then
98 INSTALL_DIR=$(sed "s/.*archisobasedir=\([^ ]\+\).\+/\1/" /proc/cmdline)
101 IP=$(ip -f inet -o addr show dev eth0 scope global | cut -d' ' -f 7 | cut -d / -f 1)
104 check_parameters()
106 if [ -z "${IP}" ]; then
107 echo "ERROR: missing IP address"
108 show_help 1
111 if [ -n "${ISO}" ]; then
112 iso_mount
113 DEVICE=$(readlink -f ${ISO})
114 MNTPNT="${TMPDIR}/mnt"
117 if [ -z "${DEVICE}" ]; then
118 echo "ERROR: can not determine boot device, please specify on command line"
119 show_help 1
123 guess_enviroment
125 while getopts 'i:s:d:l:m:t:jkh' arg; do
126 case "${arg}" in
127 i) IP="${OPTARG}" ;;
128 s) ISO="${OPTARG}" ;;
129 d) DEVICE=$(readlink -f ${OPTARG}) ;;
130 l) INSTALL_DIR="${OPTARG}" ;;
131 m) MNTPNT="${OPTARG}" ;;
132 t) TMPDIR="${OPTARG}" ;;
133 j) DNSMASQ_SKIP=true ;;
134 k) NBD_SKIP=true ;;
135 h) show_help 0 ;;
136 *) echo; echo "*ERROR*: invalid argument '${arg}'"; show_help 1 ;;
137 esac
138 done
140 check_parameters
141 copy_files
142 if ! ${DNSMASQ_SKIP} ; then
143 start_pxe_server
145 if ! ${NBD_SKIP} ; then
146 start_nbd_server