]> git.saurik.com Git - apple/network_cmds.git/blob - newclient.tproj/newclient.csh
network_cmds-85.tar.gz
[apple/network_cmds.git] / newclient.tproj / newclient.csh
1 #! /bin/csh -f
2 ##
3 # Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 #
5 # @APPLE_LICENSE_HEADER_START@
6 #
7 # "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
8 # Reserved. This file contains Original Code and/or Modifications of
9 # Original Code as defined in and that are subject to the Apple Public
10 # Source License Version 1.0 (the 'License'). You may not use this file
11 # except in compliance with the License. Please obtain a copy of the
12 # License at http://www.apple.com/publicsource and read it before using
13 # this file.
14 #
15 # The Original Code and all software distributed under the License are
16 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
20 # License for the specific language governing rights and limitations
21 # under the License."
22 #
23 # @APPLE_LICENSE_HEADER_END@
24 ##
25 #
26 # newclient
27 #
28 # NetBoot client building script.
29 #
30 # Copyright (c) 1988, NeXT, Inc.
31 #
32 # Usage:
33 # "newclient -p DISKTYPE TEMPLATE DEST" Standalone Private
34 # "newclient [-s SERVER] CLIENT-1 ... CLIENT-n" Clients
35 #
36
37 #
38 # Constants
39 #
40 set path=(/bin /usr/bin /usr/ucb /usr/etc /etc)
41 set TESTDIR
42 set CLIENTDIR=${TESTDIR}/clients
43 set template=${TESTDIR}/usr/template/client
44 set HOSTFILE=${TESTDIR}/etc/hosts
45 set BOOTPTAB=${TESTDIR}/etc/bootptab
46
47 # We are the default server
48 set server=`hostname`
49
50 # Are we root?
51 if ( `whoami` != root ) then
52 echo "You must be root to run $0"
53 exit(1)
54 endif
55
56 # Preliminary argument checkout
57 if ( $#argv < 1 ) then
58 goto usage
59 endif
60
61 # Switches must be at argv[1]
62 foreach arg ( $argv[2-] )
63 if ( x$arg =~ x-* ) then
64 goto usage
65 endif
66 end
67
68 # Parse the switches
69 if ( $argv[1] == -p || $argv[1] == -P ) then
70 if ( $#argv != 4 ) then
71 goto usage
72 endif
73 set PrivateMode
74 set disktype=$argv[2]
75 set template=$argv[3]
76 set dest=$argv[4]
77 if ( $argv[1] == -P ) then
78 set swapsize=1b
79 else
80 set swapsize=16m
81 endif
82
83 # Check that the disk type is valid
84 if ( ! -e $template/etc/fstab.$disktype ) then
85 echo "Unknown disk type" $disktype
86 exit(1)
87 endif
88 else if ( $argv[1] == -s ) then
89 if ( $#argv < 3 ) then
90 goto usage
91 endif
92 set server=$argv[2]
93 shift
94 shift
95 else if ( $argv[1] =~ -* ) then
96 goto usage
97 endif
98
99 # Make sure we have a template to work with
100 if ( ! -d $template ) then
101 echo "New client template $template does not exist"
102 exit(1)
103 endif
104
105 # Process the private partition if that is the mode we are in.
106 if ( $?PrivateMode ) then
107 if ( -e $dest ) then
108 echo "$dest already exists"
109 exit(1)
110 endif
111
112 # Create the destination directory
113 echo -n "Creating ${dest}..."
114 mkdir $dest
115 chmod 775 $dest
116 chown root.staff $dest
117 if ( $status != 0 ) then
118 echo "failed"
119 exit(1)
120 endif
121 echo "[OK]"
122
123 # Copy the template into it
124 echo -n "Copying ${template} into ${dest}..."
125 (cd $template; tar cf - .)|(cd $dest; tar xpBf -)
126 echo "[OK]"
127
128 # Make the device files
129 echo -n "Making devices in ${dest}/dev..."
130 (cd ${dest}/dev; /usr/etc/MAKEDEV NeXT)
131 echo "[OK]"
132
133 # Customize the fstab file
134 echo -n "Installing fstab.$disktype as ${dest}/etc/fstab..."
135 cp -p $dest/etc/fstab.${disktype} $dest/etc/fstab
136 if ( $status != 0 ) then
137 echo "failed"
138 exit(1)
139 endif
140 echo "[OK]"
141
142 # Touch the first 16 Meg of the swapfile
143 echo -n "Preallocating swapfile blocks..."
144 (cd ${dest}/vm; /bin/rm -f swapfile; /usr/etc/mkfile $swapsize swapfile)
145 echo "[OK]"
146
147 exit(0)
148 endif
149
150 #
151 # If we get here, then we are building a list of clients
152 #
153
154 echo $argv[*]
155 foreach client ( $argv[*] )
156 if ( $server == localhost ) then
157 echo "This machine can't be a server until it is given a hostname"
158 exit(1)
159 endif
160 set dest=$CLIENTDIR/$client
161
162 if (! -f /private/tftpboot/mach) then
163 echo Installing /private/tftpboot/mach
164 cp -p /mach /private/tftpboot/mach
165 endif
166 if (! -f /private/tftpboot/boot) then
167 echo Installing /private/tftpboot/boot
168 cp -p /usr/standalone/boot /private/tftpboot/boot
169 endif
170
171 # Check for already existing client directory
172 if ( -e $dest ) then
173 echo $dest already exists
174 continue
175 endif
176
177 # Create the destination directory
178 echo -n "Creating $dest..."
179 mkdir -p -m $dest
180 chown root:staff $dest
181 if ( $status != 0 ) then
182 echo "failed"
183 exit(1)
184 endif
185 echo "[OK]"
186
187 # Copy the template into it.
188 echo -n "Copying $template into ${dest}..."
189 (cd $template; tar cf - .)|(cd $dest; tar xpBf -)
190 echo "[OK]"
191
192 # Make the device files
193 echo -n "Making devices in ${dest}/dev..."
194 (cd $dest/dev; /usr/etc/MAKEDEV NeXT)
195 echo "[OK]"
196
197 # Customize the fstab file
198 echo -n "Installing fstab.client as ${dest}/etc/fstab..."
199 cp -p $dest/etc/fstab.client $dest/etc/fstab
200 sed -e "s/SERVER/$server/g" -e "s/CLIENT/$client/g" $dest/etc/fstab.client > $dest/etc/fstab
201 if ( $status != 0 ) then
202 echo $failed
203 exit(1)
204 endif
205 echo "[OK]"
206
207 # Set up a symbolic link to the kernel
208
209 if (-f ${dest}/tftpboot/mach) then
210 echo -n "Removing ${dest}/tftpboot/mach "
211 rm ${dest}/tftpboot/mach
212 echo "[OK]"
213 endif
214
215 echo -n "Linking /tftpboot/mach to /sdmach "
216 ln -s /sdmach ${dest}/tftpboot/mach
217 echo "[OK]"
218
219 # Touch the first 16 Meg of the swapfile
220 echo -n "Creating swapfile..."
221 (cd ${dest}/vm; /bin/rm -f swapfile; /usr/etc/mkfile 8k swapfile)
222 echo "[OK]"
223
224 end
225
226 exit(0)
227
228 usage:
229 echo "Usage: $0 -p DISKTYPE TEMPLATE DEST"
230 echo " $0 [-s SERVER] CLIENT CLIENT ..."
231 exit(1)
232
233