Skip to content
This repository
Browse code

archiso-pxe-server.sh: Updating to upstream

  • Loading branch information...
commit 4c48ae7afb43c5a3e716280c6d215454cbe19937 1 parent 2866ed6
Sven-Hendrik Haase authored

Showing 1 changed file with 77 additions and 74 deletions. Show diff stats Hide diff stats

  1. +77 74 overlay/opt/bin/archiso-pxe-server.sh
151 overlay/opt/bin/archiso-pxe-server.sh 100755 → 100644
@@ -5,144 +5,144 @@
5 5
6 6 # Requires: dnsmasq and nbd packages
7 7
  8 +set -e
  9 +
8 10 TMPDIR=/tmp/archiso-pxe-server
9   -VERSION=20100925
  11 +VERSION=20101216
  12 +INSTALL_DIR=arch
  13 +DNSMASQ_SKIP=false
  14 +NBD_SKIP=false
10 15
11 16 iso_umount() {
12 17 trap - 0 1 2 15
13   - umount $TMPDIR/mnt
14   - rmdir $TMPDIR/mnt
  18 + umount ${TMPDIR}/mnt
  19 + rmdir ${TMPDIR}/mnt
15 20 }
16 21
17 22 iso_mount() {
18   - mkdir -p $TMPDIR/mnt
  23 + mkdir -p ${TMPDIR}/mnt
19 24 trap 'iso_umount' 0 1 2 15
20   - mount $ISO $TMPDIR/mnt -o ro,loop
  25 + mount ${ISO} ${TMPDIR}/mnt -o ro,loop
21 26 }
22 27
23 28 show_help()
24 29 {
25 30 exitvalue=${1}
26 31 echo
27   - echo "archiso-pxe-server version $VERSION"
  32 + echo "archiso-pxe-server version ${VERSION}"
28 33 echo
29 34 echo "archiso-pxe-server [options]"
30 35 echo
31 36 echo " options:"
32   - echo " -i [ip] ip address of the local interface to serve"
33   - echo " (default: $IP )"
34   - echo " -d [device] boot device of Arch Linux Live media"
35   - echo " (default: $DEVICE )"
36   - echo " -s [isofile] Arch Linux Live media iso image"
37   - echo " (default: $ISO )"
38   - echo " -b [boot] path to /boot from archiso"
39   - echo " (default: $BOOT )"
40   - echo " -t [tftpboot] path to setup PXE enviroment"
41   - echo " (default: $TMPDIR )"
  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} )"
42 53 echo
43 54 exit ${exitvalue}
44 55 }
45 56
46 57 copy_files()
47 58 {
48   - if [ -f $BOOT/vmlinuz26 ]; then
49   - mkdir -p $TMPDIR/boot
50   - cp $BOOT/vmlinuz26 $TMPDIR/boot
51   - cp $BOOT/archiso.img $TMPDIR/boot
52   - else
53   - mkdir -p $TMPDIR/boot/i686
54   - mkdir -p $TMPDIR/boot/x86_64
55   - cp $BOOT/i686/vmlinuz26 $TMPDIR/boot/i686
56   - cp $BOOT/i686/archiso.img $TMPDIR/boot/i686
57   - cp $BOOT/x86_64/vmlinuz26 $TMPDIR/boot/x86_64
58   - cp $BOOT/x86_64/archiso.img $TMPDIR/boot/x86_64
  59 + if [ -f ${MNTPNT}/${INSTALL_DIR}/boot/i686/vmlinuz26 ]; then
  60 + mkdir -p ${TMPDIR}/${INSTALL_DIR}/boot/i686
  61 + cp ${MNTPNT}/${INSTALL_DIR}/boot/i686/vmlinuz26 ${TMPDIR}/${INSTALL_DIR}/boot/i686
  62 + cp ${MNTPNT}/${INSTALL_DIR}/boot/i686/archiso.img ${TMPDIR}/${INSTALL_DIR}/boot/i686
59 63 fi
60   - mkdir -p $TMPDIR/pxelinux.cfg
61   - cp $BOOT/memtest $TMPDIR/boot
62   - cp $BOOT/splash.png $TMPDIR/boot
63   -
64   - # Keep this for now for compatibility with 2010.05
65   - if [ -f $BOOT/isolinux/pxelinux.0 ]; then
66   - cp $BOOT/x86test $TMPDIR/boot
67   - cp $BOOT/isolinux/pxelinux.0 $TMPDIR
68   - cp $BOOT/isolinux/chain.c32 $TMPDIR
69   - cp $BOOT/isolinux/reboot.c32 $TMPDIR
70   - cp $BOOT/isolinux/vesamenu.c32 $TMPDIR
71   - sed 's|IPAPPEND 0|IPAPPEND 3|g' \
72   - $BOOT/isolinux/isolinux.cfg > \
73   - $TMPDIR/pxelinux.cfg/default
74   - else
75   - cp $BOOT/syslinux/pxelinux.0 $TMPDIR
76   - cp $BOOT/syslinux/chain.c32 $TMPDIR
77   - cp $BOOT/syslinux/hdt.c32 $TMPDIR
78   - cp $BOOT/syslinux/reboot.c32 $TMPDIR
79   - cp $BOOT/syslinux/vesamenu.c32 $TMPDIR
80   - cp -r $BOOT/syslinux/hdt $TMPDIR
81   - sed 's|^#IPAPPEND|IPAPPEND|g' \
82   - $BOOT/syslinux/syslinux.cfg > \
83   - $TMPDIR/pxelinux.cfg/default
  64 + if [ -f ${MNTPNT}/${INSTALL_DIR}/boot/x86_64/vmlinuz26 ]; then
  65 + mkdir -p ${TMPDIR}/${INSTALL_DIR}/boot/x86_64
  66 + cp ${MNTPNT}/${INSTALL_DIR}/boot/x86_64/vmlinuz26 ${TMPDIR}/${INSTALL_DIR}/boot/x86_64
  67 + cp ${MNTPNT}/${INSTALL_DIR}/boot/x86_64/archiso.img ${TMPDIR}/${INSTALL_DIR}/boot/x86_64
84 68 fi
  69 +
  70 + mkdir -p ${TMPDIR}/pxelinux.cfg
  71 + cp ${MNTPNT}/${INSTALL_DIR}/boot/memtest ${TMPDIR}/${INSTALL_DIR}/boot
  72 + cp ${MNTPNT}/${INSTALL_DIR}/boot/splash.png ${TMPDIR}/${INSTALL_DIR}/boot
  73 +
  74 + cp ${MNTPNT}/syslinux/*.0 ${TMPDIR}
  75 + cp ${MNTPNT}/syslinux/*.c32 ${TMPDIR}
  76 + cp ${MNTPNT}/syslinux/*.com ${TMPDIR}
  77 + cp -r ${MNTPNT}/syslinux/hdt ${TMPDIR}
  78 + for _cfg in ${MNTPNT}/syslinux/*.cfg; do
  79 + sed 's|^#IPAPPEND|IPAPPEND|g' ${_cfg} > ${TMPDIR}/$(basename ${_cfg})
  80 + done
  81 + cp ${TMPDIR}/syslinux.cfg ${TMPDIR}/pxelinux.cfg/default
85 82 }
86 83
87 84 start_pxe_server()
88 85 {
89   - pkill dnsmasq > /dev/null 2>&1
  86 + pkill dnsmasq > /dev/null 2>&1 || true
90 87 dnsmasq \
91 88 --port=0 \
92 89 --enable-tftp \
93   - --tftp-root=$TMPDIR \
  90 + --tftp-root=${TMPDIR} \
94 91 --dhcp-boot=/pxelinux.0,"${IP}" \
95 92 --dhcp-range=${IP%.*}.2,${IP%.*}.254,86400
96 93 }
97 94
98 95 start_nbd_server()
99 96 {
100   - pkill nbd-server > /dev/null 2>&1
101   - echo "[generic]" > $TMPDIR/nbd-server.conf
102   - echo "[archiso]" >> $TMPDIR/nbd-server.conf
103   - echo " readonly = true" >> $TMPDIR/nbd-server.conf
104   - echo " exportname = ${DEVICE}" >> $TMPDIR/nbd-server.conf
105   - nbd-server -C $TMPDIR/nbd-server.conf
  97 + pkill nbd-server > /dev/null 2>&1 || true
  98 + echo "[generic]" > ${TMPDIR}/nbd-server.conf
  99 + echo "[archiso]" >> ${TMPDIR}/nbd-server.conf
  100 + echo " readonly = true" >> ${TMPDIR}/nbd-server.conf
  101 + echo " exportname = ${DEVICE}" >> ${TMPDIR}/nbd-server.conf
  102 + nbd-server -C ${TMPDIR}/nbd-server.conf
106 103 }
107 104
108 105 guess_enviroment()
109 106 {
110 107 if grep archisolabel /proc/cmdline > /dev/null; then
111   - DEVICE="/dev/disk/by-label/"`sed "s/.\+archisolabel=\([^ ]\+\).\+/\1/" /proc/cmdline`
112   - BOOT=/bootmnt/boot
  108 + DEVICE="/dev/disk/by-label/"$(sed "s/.\+archisolabel=\([^ ]\+\).\+/\1/" /proc/cmdline)
  109 + MNTPNT=/bootmnt
113 110 fi
114 111
115   - IP=`ifconfig eth0 | awk -F":| +" '/inet addr/{print $4}'`
  112 + IP=$(ifconfig eth0 | awk -F":| +" '/inet addr/{print $4}')
116 113 }
117 114
118 115 check_parameters()
119 116 {
120   - if [ -z "$IP" ]; then
  117 + if [ -z "${IP}" ]; then
121 118 echo "ERROR: missing IP address"
122 119 show_help 1
123 120 fi
124 121
125   - if [ -n "$ISO" ]; then
  122 + if [ -n "${ISO}" ]; then
126 123 iso_mount
127   - DEVICE=`readlink -f $ISO`
128   - BOOT="$TMPDIR/mnt/boot"
  124 + DEVICE=$(readlink -f ${ISO})
  125 + MNTPNT="${TMPDIR}/mnt"
129 126 fi
130 127
131   - if [ -z "$DEVICE" ]; then
132   - echo "ERROR: can't determine boot device, please specify on command line"
  128 + if [ -z "${DEVICE}" ]; then
  129 + echo "ERROR: can not determine boot device, please specify on command line"
133 130 show_help 1
134 131 fi
135 132 }
136 133
137 134 guess_enviroment
138 135
139   -while getopts 'i:s:d:b:t:h' arg; do
  136 +while getopts 'i:s:d:l:m:t:jkh' arg; do
140 137 case "${arg}" in
141 138 i) IP="${OPTARG}" ;;
142 139 s) ISO="${OPTARG}" ;;
143   - d) DEVICE=`readlink -f ${OPTARG}` ;;
144   - b) BOOT="${OPTARG}" ;;
  140 + d) DEVICE=$(readlink -f ${OPTARG}) ;;
  141 + l) INSTALL_DIR="${OPTARG}" ;;
  142 + m) MNTPNT="${OPTARG}" ;;
145 143 t) TMPDIR="${OPTARG}" ;;
  144 + j) DNSMASQ_SKIP=true ;;
  145 + k) NBD_SKIP=true ;;
146 146 h) show_help 0 ;;
147 147 *) echo; echo "*ERROR*: invalid argument '${arg}'"; show_help 1 ;;
148 148 esac
@@ -150,6 +150,9 @@ done
150 150
151 151 check_parameters
152 152 copy_files
153   -start_pxe_server
154   -start_nbd_server
155   -
  153 +if ! ${DNSMASQ_SKIP} ; then
  154 + start_pxe_server
  155 +fi
  156 +if ! ${NBD_SKIP} ; then
  157 + start_nbd_server
  158 +fi

0 comments on commit 4c48ae7

Please sign in to comment.
Something went wrong with that request. Please try again.