-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup-pxe-server
executable file
·247 lines (232 loc) · 4.76 KB
/
setup-pxe-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/ksh
#
# SPDX-License-Identifier: CDDL-1.0
#
# {{{ CDDL HEADER
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# }}}
#
# Copyright 2023 Peter Tribble
#
#
# takes an iso image and puts the pieces in the right place for pxe
# installation
#
#
# needs to be told:
# - what the tftp root is
# - where the htdocs directory is
# - what the URL of the server is
#
#
# FIXME needs progress feedback
#
umask 022
DEBUG="echo"
usage() {
echo "Usage: $0 -t tftp_dir -h htdocs_dir -u http_url"
exit 1
}
#
# interactive argument handling
#
TFTPBOOT="/tftpboot"
TFTPDIR=""
HTDOCS=""
URL=""
while getopts "t:h:u:" opt; do
case $opt in
t)
TFTPDIR="$OPTARG"
;;
h)
HTDOCS="$OPTARG"
;;
u)
URL="$OPTARG"
;;
esac
done
shift $((OPTIND-1))
case $# in
0)
printf ""
;;
*)
usage
;;
esac
#
# check everything is defined
#
if [ -z "$TFTPDIR" ]; then
echo "TFTP directory must be defined"
usage
fi
if [ -z "$HTDOCS" ]; then
echo "HTDOCS directory must be defined"
usage
fi
if [ -z "$URL" ]; then
echo "Server URL must be defined"
usage
fi
#
# check the right things exist
#
if [ ! -d ${TFTPBOOT} ]; then
echo "Unable to find ${TFTPBOOT}"
usage
fi
if [ -f $HTDOCS ]; then
echo "The HTDOCS location must be a directory"
usage
fi
if [ -d $HTDOCS ]; then
NF=`/bin/ls -1 $HTDOCS | wc -l | awk '{print $1}'`
case $NF in
0)
printf ""
;;
*)
echo "The HTDOCS location must be empty"
usage
;;
esac
fi
case $URL in
http://*)
printf ""
;;
*)
echo "Unable to recognize URL format"
usage
;;
esac
HTTOP=`dirname $HTDOCS`
if [ ! -d $HTTOP ]; then
echo "Unable to find parent of HTDOCS directory"
usage
fi
#
# everything exists, check that tftp is configured
#
if [ ! -d ${TFTPBOOT} ]; then
echo "Unable to find ${TFTPBOOT} - is tftp configured?"
exit 2
fi
if [ -d ${TFTPBOOT}/${TFTPDIR} ]; then
echo "TFTP location ${TFTPDIR} already exists"
exit 2
fi
TSTATE=`/usr/bin/svcs -H tftp/udp6 | awk '{print $1}'`
case $TSTATE in
online)
printf ""
;;
disabled)
echo "Enabling tftp service"
$DEBUG /usr/sbin/svcadm enable tftp/udp6
;;
*)
echo "Cannot find tftp service"
exit 2
;;
esac
#
# FIXME need to resolve the path to the script
#
# we're in the ISO, so need to check we have
# loader
# platform
# pkgs
#
if [ ! -d pkgs ]; then
echo "Unable to find pkgs"
exit 2
fi
if [ ! -d platform ]; then
echo "Unable to find the platform directory"
exit 2
fi
if [ ! -d boot ]; then
echo "Unable to find the iso boot directory"
exit 2
fi
if [ ! -f boot/pxeboot ]; then
echo "Unable to find pxeboot"
exit 2
fi
#
# the ISO always has a combined boot archive, so need just the one
# even if it looks like this is only 32-bit
#
if [ ! -f platform/i86pc/boot_archive ]; then
echo "Unable to find the boot archive"
exit 2
fi
#
# we need the kernel
#
if [ ! -f platform/i86pc/kernel/amd64/unix ]; then
echo "Unable to find the kernel"
exit 2
fi
#
# all seems to be present
#
$DEBUG mkdir -p $HTDOCS
echo "Copying packages"
$DEBUG cp -r pkgs $HTDOCS
#
# solaris.zlib only exists in the old-style split iso
# but if it exists, need to copy it
#
if [ -f solaris.zlib ]; then
echo "Copying solaris.zlib"
$DEBUG cp solaris.zlib $HTDOCS
fi
echo "Copying files to tftp server"
# kernel and miniroot
$DEBUG mkdir -p ${TFTPBOOT}/$TFTPDIR/platform/i86pc/kernel/amd64
$DEBUG cp platform/i86pc/boot_archive ${TFTPBOOT}/$TFTPDIR/platform/i86pc
chmod a+r ${TFTPBOOT}/$TFTPDIR/platform/i86pc/boot_archive
$DEBUG cp platform/i86pc/kernel/amd64/unix ${TFTPBOOT}/$TFTPDIR/platform/i86pc/kernel/amd64
chmod a+rx ${TFTPBOOT}/$TFTPDIR/platform/i86pc/kernel/amd64/unix
# boot loader
$DEBUG cp boot/pxeboot ${TFTPBOOT}/$TFTPDIR
$DEBUG cp boot/loader.* ${TFTPBOOT}/$TFTPDIR
$DEBUG cp -r boot/defaults ${TFTPBOOT}/$TFTPDIR
$DEBUG cp -r boot/forth ${TFTPBOOT}/$TFTPDIR
#
# we copy the add-pxe-client script to the tftp location
# and create a file containing the locations that are in use
#
$DEBUG cp tools/add-pxe-client ${TFTPBOOT}/$TFTPDIR
#
# install_media is used for both the optional solaris.zlib delivery
# and also the cardigan configuration file
#
save_config() {
echo tftpboot=${TFTPBOOT}
echo tftpdir=${TFTPBOOT}/$TFTPDIR
echo install_media=${URL}/
echo htdocs=$HTDOCS
echo install_pkgs=${URL}/pkgs/
}
if [ -n "$DEBUG" ]; then
save_config
else
save_config > ${TFTPBOOT}/$TFTPDIR/cardigan.cfg
fi
echo "To add pxe clients, cd to ${TFTPBOOT}/$TFTPDIR"
echo "and run the add-pxe-client script in that directory"