]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/picobsd/build/build
Additional cleanup of the picobsd scripts.
[FreeBSD/FreeBSD.git] / release / picobsd / build / build
1 #!/bin/sh -
2
3 #
4 #       $Id: build,v 1.14 1999/08/22 21:42:30 dwhite Exp $
5 #
6 # You can set the SRC variable which points to your source tree. It's
7 # /usr/src by default (most people shouldn't change it).
8 SRC=/usr/src
9
10 # --------- YOU SHOULD NOT NEED TO CHANGE ANYTHING BELOW -----------
11 # The "build" script will ask you for parameters. Just run it... :-)
12 # --------- YOU SHOULD NOT NEED TO CHANGE ANYTHING BELOW -----------
13
14 # EDITOR is the editor you use
15 EDITOR=${EDITOR:-vi}
16 # LANGUAGE     language to be used (en or pl)
17 LANGUAGE=en
18 # SITE         site-specific files
19 SITE=
20
21 # FLOPPY_SIZE  floppy size in KB (default to 1440)
22 FLOPPY_SIZE=1440
23
24 # DEVFS is currently broken. Always set this.
25 #
26 NO_DEVFS=yes
27
28 # RISU is where dialog replies go.
29 RISU=.build.reply
30
31 # abort in case of error...
32 set -e
33
34 . ../Version
35
36 # assign default values to variables.
37 set_defaults() {
38     TYPE=${TYPE:-dial} # PicoBSD type (isp, router, net, custom, ...
39
40     while read name suff sz init mfs_in floppy_in ; do
41         if [ "$name" != "#" -a $name != "" ] ; then
42             eval ${name}_suffix=$suff
43             eval ${name}_DFLT_SIZE=$sz
44             eval ${name}_INIT=$init
45             eval ${name}_MFS_INODES=$mfs_in
46             eval ${name}_FLOPPY_INODES=$floppy_in
47         fi
48     done <<__eof__
49 # build MFS             - Byte/inode -
50 # name          suffix  DFLT_SZ init    MFS     FLOPPY
51 dial            -D      1600    init    4096    32768
52 router          -R      820     oinit   3072    32768
53 net             -N      2200    init    4096    32768
54 isp             -I      2400    init    4096    32768
55 custom          -C      2400    init    8192    32768
56 __eof__
57 }
58
59 set_msgs() {
60     MSG1="Type: ${TYPE}"
61     if [ "X${TYPE}" = "Xcustom" ] ; then
62         MSG1="${MSG1} (from ${CUST_DIR})"
63     fi
64
65     MSG="PicoBSD build -- Current parameters:\n\n\t1.  ${MSG1}\n\
66 \t2.  MFS size: ${SIZE} kB\n\t3.  Language: ${LANGUAGE}\n\
67 \t4.  Site-info: ${SITE}\n"
68 }
69
70
71 # Main build procedure. It calls another scripts (stage1)
72 main() {
73
74     export suffix
75
76     clear
77     set_msgs
78     printf "${MSG}"
79     echo "-> We'll use the sources living in ${SRC}"
80     echo ""
81     echo "-> I hope you have checked the ../${TYPE}/PICOBSD config file..."
82     echo ""
83     echo ""
84     sleep 2
85
86     export SIZE LANGUAGE TYPE SRC NO_DEVFS INIT
87     export SITE MFS_INODES FLOPPY_INODES FLOPPY_SIZE
88
89     # Build the kernel, if necessary
90     echo ""
91     echo "-> Checking if we have to build the PICOBSD kernel..."
92     (cd ../${TYPE}; make -f ../build/Makefile.conf )
93     echo ""
94
95     ./stage1 2>&1 | tee stage1.out
96     if [ "X$?" != "X0" ] ; then
97         echo "\a"
98         echo "-> ERROR in \"${i}\" script. Aborting the build process."
99         echo -n "-> Cleaning temporary files... "
100         umount -f /mnt
101         vnconfig -u /dev/rvn0
102         ./clean ${TYPE}
103         echo "Done."
104         exit 10
105     fi
106     echo "==================== ${i} completed ====================="
107 }
108
109 # check for existing custom config directory and ask user if they want to use it
110
111 check_for_old_custom() {
112    KEEP_CUSTOM=no
113    if [ ! -d ../custom ] ; then
114        return
115    fi
116    clear
117    echo "                   Custom directory setup"
118    echo ""
119    echo "There is an existing custom configuration linked to"
120    ls -l ../custom | awk -F\> '{ print $2 }' | awk '{ print $1 }'
121    echo ""
122    read -p "Do you wish to use the existing custom directory? (yes/no): " KEEP_CUSTOM
123 }
124
125 # Ask for, and set the custom config directory
126
127 set_custom() {
128     dialog --title "Custom directory setup" --inputbox \
129     "Please enter the full path to the directory containing your \
130     custom setup. \
131     This directory tree must be laid out exactly like the standard \
132     ones. (E.g. you can type in /home/abial/work/custom, which \
133     should contain crunch1/, floppy.tree/, lang/ )." \
134     10 70 2> ${RISU}
135     CUST_DIR=`cat ${RISU}`
136 }
137
138 # Set type of floppy interactively. Also set the various defaults
139 # associated to each type. We can override them manually afterwards.
140
141 set_type() {
142
143     eval SIZE=$"${TYPE}_DFLT_SIZE"
144     eval INIT=$"${TYPE}_INIT"
145     eval MFS_INODES=$"${TYPE}_MFS_INODES"
146     eval FLOPPY_INODES=$"${TYPE}_FLOPPY_INODES"
147     eval suffix=$"${TYPE}_suffix"
148
149     case ${TYPE} in
150     custom)
151         check_for_old_custom
152         if [ "X${KEEP_CUSTOM}" != "Xyes" ] ; then
153             [ -r ../custom ] && rm -f ../custom
154             set_custom
155             (cd ..; ln -sf ${CUST_DIR} custom)
156         fi
157         ;;
158     esac
159         
160 }
161
162
163 build_package() {
164     touch build.status
165     echo "##############################################" >>build.status
166     echo "## `date` ">>build.status
167     echo "##############################################" >>build.status
168     ./clean dial
169     for y in en pl ; do
170         for z in dial router net isp ; do
171             TYPE=${z}
172             LANGUAGE=${y}
173             set_type
174             echo "---------------------------------------------">>build.status
175             echo "Building TYPE=${z}, LANGUAGE=${y}, SIZE=${SIZE}" >>build.status
176             main
177             if [ "X$?" != "X0" ] ; then
178                 echo "  ** FAILED! **">>build.status
179             else
180                 echo "  (ok)">>build.status
181             fi
182             mv picobsd.bin pb_${y}${suffix}.bin
183             echo "Calling ./clean for ${TYPE}, ${LANGUAGE}, ${SIZE}">>build.status
184             ./clean ${TYPE}
185         done
186     done
187     exit 0
188 }
189
190 # Set build parameters interactively
191
192 main_dialog() {
193   while [ true ] ; do
194     set_msgs
195     dialog --menu "PicoBSD build menu -- ver ${VER} (22aug1999)" 19 70 12 \
196         N "No change, build it" \
197         T "${MSG1}" \
198         K "edit Kernel config file for ${TYPE}" \
199         E "Edit crunch.conf file for ${TYPE}" \
200         S "MFS Size: ${SIZE}kB" \
201         L "Language: ${LANGUAGE}" \
202         I "Init type: ${INIT}" \
203         F "Floppy size: ${FLOPPY_SIZE}kB" \
204         M "MFS bytes per inode: ${MFS_INODES}" \
205         U "UFS bytes per inode: ${FLOPPY_INODES}" \
206         $ "Site-info: ${SITE}" \
207         Q "Quit" \
208         2> ${RISU}
209     ans=`cat ${RISU}`
210     rm ${RISU}
211     case ${ans} in
212     T)
213         dialog --menu "Setup the type of configuration" 12 70 5 \
214             dial "dialin (ppp etc.)" \
215             router "router/bridge/mrouter" \
216             net "net admin tool" \
217             isp "isp (ppp and terminal server)" \
218             custom "custom config (need pathname)" 2> ${RISU} || rm ${RISU}
219         if [ -f ${RISU} ] ; then
220             TYPE=`cat ${RISU}`
221             set_type
222         fi
223         ;;
224     I)
225         dialog --menu "Choose your init(8) program" \
226         10 70 2 init "Standard init (requires getty)" \
227         oinit "small init from TinyWare" 2> ${RISU} || rm ${RISU}
228         if [ -f ${RISU} ] ; then
229             INIT=`cat ${RISU}`
230         fi
231         ;;
232
233     K) ${EDITOR} ../${TYPE}/PICOBSD ;;
234
235     E) ${EDITOR} ../${TYPE}/crunch1/crunch.conf ;;
236
237     S)
238         dialog --title "MFS Size setup" --inputbox \
239 "MFS size depends on what you need to put on the MFS image. Typically \
240 ranges between 820kB (for very small bridge/router images) to \
241 as much as 2500kB kB for a densely packed image. \
242 Keep in mind that this memory is \
243 totally lost to other programs. Usually you want to keep \
244 this as small as possible. " 10 70 2> ${RISU} || rm ${RISU}
245         if [ -f ${RISU} ] ; then
246             SIZE=`cat ${RISU}`
247             if [ "${SIZE}" = "" ] ; then
248                 eval SIZE=$"${TYPE}_DFLT_SIZE"
249             fi
250         fi
251         ;;
252
253     L)
254         dialog --menu "Please choose language" \
255         10 40 2 en English pl Polish 2> ${RISU} || rm ${RISU}
256         if [ -f ${RISU} ] ; then
257             LANGUAGE=`cat ${RISU}`
258         fi
259         ;;
260
261     \$)
262         dialog --title "Site info setup" --inputbox \
263         "Please enter the full path to the directory \
264         containing site-specific setup. \
265         This directory tree must contain files that replace \
266         standard ones in floppy.tree/ and mfs.tree/ . " \
267         10 70 2> ${RISU} || rm ${RISU}
268         if [ -f ${RISU} ] ; then
269             SITE=`cat ${RISU}`
270         fi
271         ;;
272
273     F)
274         dialog --menu "Set floppy size" 15 70 4 \
275                 1440 "1.44MB" 1720 "1.72MB" \
276                 2880 "2.88MB" 4096 "4MB" 2> ${RISU} || rm ${RISU}
277         if [ -f ${RISU} ] ; then
278             FLOPPY_SIZE=`cat ${RISU}`
279         fi
280         ;;
281
282     M)
283         dialog --title "MFS bytes per inode:" --inputbox \
284         "Enter MFS bytes per inode (typically 4096..65536). \
285         A larger value means fewer inodes but more space on MFS" \
286         10 70 2> ${RISU} || rm ${RISU}
287         if [ -f ${RISU} ] ; then
288             MFS_INODES=`cat ${RISU}`
289             if [ "${MFS_INODES}" = "" ] ; then
290                 eval MFS_INODES=$"${TYPE}_DFLT_MFS_INODES"
291             fi
292         fi
293         ;;
294
295     U)
296         dialog --title "Floppy bytes per inode:" --inputbox \
297         "Enter floppy bytes per inode (typically 3072..65536). \
298         A larger value means fewer inodes but more space on the floppy." \
299         10 70 2> ${RISU} || rm ${RISU}
300         if [ -f ${RISU} ] ; then
301             FLOPPY_INODES=`cat ${RISU}`
302             if [ "${FLOPPY_INODES}" = "" ] ; then
303                 eval FLOPPY_INODES=$"${TYPE}_DFLT_FLOPPY_INODES"
304             fi
305         fi
306         ;;
307
308     N) break 2
309         ;;
310
311     Q) exit 0 ;;
312
313     *) echo "\aUnknown option \"${ans}\". Try again."
314         sleep 2
315         clear
316         ;;
317     esac
318   done
319 }
320
321 # Call the build procedure
322 # Install image
323 do_install() {
324     dialog --title "Build ${TYPE} completed" --inputbox \
325 "\nThe build process was completed successfuly.\n\
326 Now we are going to install the image on the floppy.\n\
327 Please insert a blank floppy in /dev/fd0.\\n
328 WARNING: the contents of the floppy will be permanently erased!\n\
329 \n\
330 Your options:\n\
331         * ^C or [Cancel] to abort,\n\
332         * Enter to install \"${FILENAME}\",\n\
333         * name of other file to install.\n\
334 " 20 70 2> ${RISU}
335     if [ "$?" = "0" ]; then
336         FILENAME=`cat ${RISU}`
337         if [ "${FILENAME}" = "" ] ; then
338             FILENAME=picobsd.bin
339         fi
340         echo "Writing ${FILENAME}..."
341         dd if=${FILENAME} of=/dev/rfd0
342     else
343         echo "Ok, the image is in picobsd.bin"
344     fi
345     echo "Done."
346 }
347
348 #-------------------------------------------------------------------
349 # Main entry of the script
350
351 interactive="YES"
352 if [ "$1" = "-n" ] ; then
353     interactive="NO"
354     shift
355 fi
356 TYPE=$1
357 set_defaults
358 set_type
359
360 # If $1="package", it creates a neat set of floppies
361
362 if [ "$1" = "package" ] ; then
363     build_package
364 fi
365 if [ "$interactive" = "YES" ] ; then
366     main_dialog
367 fi
368 main    # build ${TYPE}
369 do_install
370 exit 0