summaryrefslogtreecommitdiffstats
path: root/urunlevel/my_linux/Trinux/linuxrc
diff options
context:
space:
mode:
Diffstat (limited to 'urunlevel/my_linux/Trinux/linuxrc')
-rwxr-xr-xurunlevel/my_linux/Trinux/linuxrc1261
1 files changed, 1261 insertions, 0 deletions
diff --git a/urunlevel/my_linux/Trinux/linuxrc b/urunlevel/my_linux/Trinux/linuxrc
new file mode 100755
index 0000000..4597234
--- /dev/null
+++ b/urunlevel/my_linux/Trinux/linuxrc
@@ -0,0 +1,1261 @@
1#!/bin/sh
2#
3# linuxrc - main trinux initialization script
4#
5# Author: Matthew Franz <mfranz@cisco.com>
6# Bill Burdick for the User-Mode-Linux fixes
7########################################################################
8#
9# Attempts to do the following:
10#
11# - Determine where trinux booted from [ Floppy/CD-ROM/IDE/UML ]
12# - Mount boot device and copy configuration files to /etc/tux
13# - Initialize and create ramdisks/tmpfs or mount filesystems
14# - Determine where packages are located and to be loaded from
15# - Initialize kernel modules and detect hardware
16# - Configure and enable networking
17# - Load and initialize packages
18# - Initialize system daemons
19#
20########################################################################
21## Define stuff that is probably rejected by busybox
22########################################################################
23
24UMLROOT="/trinux-uml"
25PATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin"
26TERM=linux
27PS1="trinux> "
28PS2='>'
29
30export PATH TERM PS1 PS2 VERSION PKGSRC BOOT PKGSRC BOOTFS FLCFG FXCFG PKGLIST FIXED
31umask 022
32[ -d /etc/proc ] || mkdir -p /etc/proc
33mount -t proc proc /proc
34mkdir -p /lib/modules
35mkdir -p /etc/tux/config
36ln -sf /proc/self/fd/0 /dev/stdin
37ln -sf /proc/self/fd/2 /dev/stderr
38ln -sf /proc/self/fd/1 /dev/stdout
39
40chmod a+w /tmp
41chmod a+w /dev/null
42
43#####################################################################
44## Gather information about system
45#####################################################################
46
47MEMORY=`grep MemTotal /proc/meminfo | cut -d':' -f2 | cut -d'k' -f1`
48KERNEL=`cat /proc/version | cut -d' ' -f3`
49CDEV=`dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq` # CD-ROM devices
50FDEV=`dmesg | grep -v LDM | grep -v "ldm_val" | grep "^ [sh]d[a-f]" | cut -d':' -f2 | sort | uniq` # FIXED
51
52echo "Checking for fixed disks"
53/sbin/chkfixed
54
55
56
57echo "FDEV: $FDEV"
58echo "CDEV: $CDEV"
59sleep 1
60
61echo "$FDEV" > /tmp/fixed
62
63
64for i in `cat /tmp/fixed`
65do
66 echo $i
67done > /etc/proc/fixed
68
69
70[ "$CDEV" ] && echo "$CDEV" >> /etc/proc/fixed
71
72
73#check initial filesytem support
74
75for i in `grep -v nodev /proc/filesystems`
76do
77 echo $i
78done > /etc/proc/filesystems
79
80
81######################################################################
82### Special Probing stuff
83######################################################################
84
85## Did we boot from UML?
86#if dmesg | grep 'User-mode Linux' > /dev/null
87
88if grep ' ubd' /proc/devices > /dev/null
89then
90 echo "Trinux booted via User Mode Linux (UML)"
91 sleep 3
92 UML="true"
93 BOOT="UML"
94fi
95
96## Did we boot from ms-dos loadlin
97
98echo "Checking all vfat partitions for loadlin.exe"
99
100for i in `cat /etc/proc/fixed 2> /dev/null`
101do
102# [ -d /${i} ] || mkdir /${i}
103# echo "Checking $i"
104
105 if mount -o ro -t vfat /dev/${i} /mnt 2> /dev/null
106 then
107 echo -n "VFAT found on $i"
108 if ls /mnt/loadlin.exe 2> /dev/null
109 then
110 echo -n " found loadlin.exe"
111 if [ -d /mnt/trinux ]
112 then
113 echo " found trinux"
114 BOOT="/dev/${i}"
115 BOOTFS="vfat"
116 echo "BOOT=$BOOT"
117 echo "$i" > /etc/proc/fixedpkg
118 LOADLIN="true"
119 cd /
120 umount /mnt 2> /dev/null
121 break
122 fi
123 fi
124
125 fi
126 umount /mnt 2> /dev/null
127done
128
129# Check to see if checking for floppy drive should be disabled
130
131if grep nofloppy /proc/cmdline > /dev/null
132then
133 NOFLOPPY="true"
134 echo "Disabling checks for floppy drive"
135fi
136
137########################################################################
138# Determine where Trinux booted from in order of likelihood
139#
140# /dev/fd0 - floppy (this is normally the case)
141# /dev/hd[alpha] - IDE CD-ROM (usually /dev/hdc)
142# /dev/hd[numeric] - IDE Hard Disk (including flash disk)
143#
144# We assume that if a floppy is present and no-›
145#
146########################################################################
147#
148# first check if CD-ROM is present
149
150if [ "$CDEV" ]
151then
152 echo -n "Attempting to mount CD-ROM at $CDEV:"
153
154 if mount -t iso9660 /dev/${CDEV} /mnt 2> /dev/null > /dev/null
155 then
156 echo "successful"
157 if [ -d /mnt/trinux ]
158 then
159 echo "/trinux found on $CDEV"
160 PKGSRC=$CDEV # we assume packages will be loaded from it
161
162 # Now check and see if we booted from CD-ROM
163
164 if [ -d /mnt/isolinux ]
165 then
166 BOOT=/dev/${CDEV}
167 BOOTFS="iso9660"
168 NOFLOPPY="true"
169 echo $CDEV > /etc/proc/fixedpkg
170 fi
171 cd /
172 umount /mnt 2> /dev/null
173 fi
174 else
175 echo "failed"
176 [ "$UML" ] || BOOT="/dev/fd0"
177 fi
178fi
179
180if [ ! "$NOFLOPPY" ]
181then
182 echo "Checking for floppy in /dev/fd0"
183 sleep 1
184
185 if mount -t vfat /dev/fd0 /boot 2> /dev/null
186 then
187 [ -d /boot/bootpkg ] && BOOT="/dev/fd0"
188 [ -d /boot/tux ] && FLCFG="true"
189 [ -f /boot/tux/options/floppy ] && PKGSRC="/dev/fd0"
190 umount /boot 2> /dev/null
191
192 [ "$BOOT" = "/dev/fd0" ] && echo "Trinux booted from a floppy."
193 [ "$PKGSRC" = "/dev/fd0" ] && echo "Trinux will load packages from one or more floppies."
194 else
195 echo "Unable to mount boot floppy"
196 fi
197else
198 echo "Floppy checking is disabled"
199fi
200
201echo $BOOT > /etc/proc/boot
202echo $BOOTFS > /etc/proc/bootfs
203
204echo
205echo "========================"
206echo "BOOT: $BOOT"
207echo "KERNEL: $KERNEL"
208echo -n "CDEV: "
209
210if [ $CDEV ]
211then
212 echo "$CDEV"
213else
214 echo "none"
215fi
216
217echo -n "FDEV: "
218
219if [ "$FDEV" ]
220then
221 echo $FDEV
222else
223 echo "none"
224fi
225
226
227## Determine boot filesystem type
228
229if [ "$BOOT" = "/dev/fd0" ]
230then
231 BOOTFS="vfat"
232elif [ "$UML" ]
233then
234 BOOTFS="ext2"
235elif [ "$BOOT" = "$CDEV" ]
236then
237 BOOTFS="iso9660"
238fi
239
240echo "BOOTFS: $BOOTFS"
241echo "========================"
242sleep 2
243
244####################################################################
245# Determine where packages should be loaded from. By default, Trinux
246# will look at /etc/tux/config/pkgsrc otherwise it will look at
247# parameters passed from syslinux.cfg (i.e. pkgsrc=/dev/hda1).
248# Otherwise Trinux will assume network package loading unlesss
249# the network is unable to be configured
250####################################################################
251
252if grep 'pkg=floppy' /proc/cmdline > /dev/null
253then
254 PKGSRC="/dev/fd0"
255fi
256
257PKGSRC="network" ## Assume network package loading unless...
258
259#####################################################################
260## Mount the boot filesystem
261## 1) copy config from tux over
262## 2) install kernel module pkgs from kpkg
263#####################################################################
264
265if [ "$UML" ]
266then
267 echo
268 # mount the host ext2 filesystem RO so initial packages can be installed
269 mount none /boot -t hostfs -o $UMLROOT,ro
270else
271 mount -o ro -t $BOOTFS $BOOT /boot
272 VERSION=`cat /boot/version 2> /dev/null`
273 PS1="Trinux $VERSION> "
274fi
275
276[ "$BOOT" != "/dev/fd0" ] && PREFIX="trinux/"
277
278cd /boot
279
280#pwd
281#ls -al
282
283echo "Copying /tux from boot filesystem..."
284cp -a ${PREFIX}tux /etc
285
286
287echo "Copying modules from boot filesystem..."
288
289# support either within /trinux/modules or /trinux/*.o
290
291cp ${PREFIX}*.o /lib/modules 2> /dev/null
292cp ${PREFIX}modules/*.o /lib/modules 2> /dev/null
293cp ${PREFIX}modules/*.gz /lib/modules 2> /dev/null
294
295cd /lib/modules
296
297for i in `ls *.gz`
298do
299 FNAME=`basename $i .gz`
300 echo "Uncompressing $i"
301 gunzip $i
302 mv $FNAME $FNAME.o
303done
304
305if [ -f /etc/tux/version ]
306then
307 VERSION=`cat /etc/tux/version 2> /dev/null`
308else
309 VERSION="unknown"
310fi
311
312cd /boot
313if cd ${PREFIX}kpkg 2> /dev/null
314then
315 echo "Installing kernel module packages from boot device"
316 for i in `ls`
317 do
318 pkgadd $i
319 echo $i >> /etc/proc/kpkg.installed
320 done
321fi
322
323######## Store temporary scripts in scripts directory ###########
324
325if [ -d ${PREFIX}scripts ]
326then
327 echo "Copying local scripts to /bin:"
328 cd ${PREFIX}scripts
329 for i in `ls`
330 do
331 cp $i /bin/
332 chmod u+x /bin/$i
333 done
334fi
335
336cd /
337umount /boot
338
339echo "Unmounting boot filesystem"
340
341# load in kernel modules
342
343#cd /lib/modules
344
345if [ -f /etc/tux/config/modules ]
346then
347 while read i
348 do
349 echo "Installing $i"
350 insmod /lib/modules/$i 2> /dev/null > /dev/null
351 done < /etc/tux/config/modules
352fi
353
354
355echo "Waiting for modules to settle..."
356
357sleep 3
358
359#### Since modules have already been loaded now is a good
360#### time to scour the partitions, checking for devices
361
362echo "Checking for fixed disks"
363
364/sbin/chkfixed
365
366#### Check for a saved fixedpkg to avoid checking all found partitions
367
368if [ -f /etc/tux/config/fixedpkg ]
369then
370 echo -n "Found previously saved fixed package source: "
371 FIXEDPKG=`cat /etc/tux/config/fixedpkg`
372 if [ "$FIXEDPKG" = "cdrom" -o "$FIXEDPKG" = "cd-rom" ]
373 then
374 FIXEDPKG=$CDEV
375 fi
376
377 echo $FIXEDPKG
378 echo $FIXEDPKG > /etc/proc/fixed
379fi
380
381for i in `cat /etc/proc/fixed` # loop through fixed devices
382do
383 [ -d /${i} ] || mkdir /${i} # create mount point
384
385 for j in `cat /etc/proc/filesystems` # loop through supported fstype
386 do
387 #echo -n "Checking $i:"
388 if mount -o ro -t $j /dev/$i /$i 2> /dev/null > /dev/null
389 then
390 #echo " found $j"
391 echo "$i:$j" >> /etc/tux/config/fstab
392 umount /dev/$i 2> /dev/null > /dev/null 2> /dev/null
393 else
394 echo
395 fi
396 done
397done
398
399if [ -f /etc/tux/config/fstab ]
400then
401 echo "The following partitions/filesytems were found:"
402 cat /etc/tux/config/fstab
403 cat /etc/tux/config/fstab | sort | uniq > /tmp/fstab
404 cat /tmp/fstab > /etc/tux/config/fstab
405fi
406
407#########
408# Search filesystems for /trinux directories
409
410if [ -f /etc/proc/fixedpkg ]
411then
412 fixedpkg=`cat /etc/proc/fixedpkg`
413 echo "/trinux already found on $fixedpkg, aborting search"
414 mount
415else
416 if [ -f /etc/tux/config/fstab ]
417 then
418 for i in `cat /etc/tux/config/fstab`
419 do
420 part=`cut -d: -f1 /etc/tux/config/fstab`
421 fstype=`cut -d: -f2 /etc/tux/config/fstab`
422
423 if mount -t $fstype /dev/${part} /mnt 2> /dev/null
424 then
425 echo -n "Checking $part for trinux directory: "
426
427 if [ -d /mnt/trinux/ ]
428 then
429 echo " found"
430 umount /mnt 2> /dev/null
431 echo $part > /etc/proc/fixedpkg
432 break
433 else
434 echo " not found"
435 fi
436
437 cd /; umount /mnt 2> /dev/null
438 else
439 echo -n "Failed to mount $part"
440 fi
441 done
442 fi
443fi
444
445chmod a+x /etc/tux/init/first 2> /dev/null
446if [ -x /etc/tux/init/first ]
447then
448 . /etc/tux/init/first
449fi
450
451#################################################################
452################### Ramdisk building stuff ######################
453#################################################################
454
455if grep ' 2.4' /proc/version 2> /dev/null
456then
457 echo "Found 2.4.x kernel: tmpfs capable"
458 if [ -f /etc/tux/config/tmpfs ]
459 then
460 echo "Using tmpfs"
461 TMPFS="true"
462 fi
463else
464 TMPFS="false"
465fi
466
467#### If /etc/tux/config/corefs is present we use that for
468#### partitions *other* than root. If fstab is blank then
469#### everything is mounted as root. Trinux will attempt to mount
470#### to filesystem and will *not* reformat
471####
472#### An additional file (/etc/tux/config/suppfs) will be mounted
473#### later so that nfs/smbfs can be mounted
474####
475#### corefs format
476#### partition:mount point:size in Kb:filesystem:options
477####
478#### /dev/sda1:/var:512:minix:keep,ro
479####
480####
481#### possible filesystems
482#### vfat, minix, tmpfs, ram (actually minix)
483####
484#### plus anything compiled in your kernel
485
486if [ -f /etc/tux/config/corefs ]
487then
488 for i in `cat /etc/tux/config/corefs`
489 do
490 DEV=`echo $i | cut -d: -f1`
491 MOUNT=`echo $i | cut -d: -f2`
492 SIZE=`echo $i | cut -d: -f3`
493 FSTYPE=`echo $i | cut -d: -f4`
494 OPTIONS=`echo $i | cut -d: -f5`
495
496 echo "[DEV: $DEV]"
497 echo "MOUNT: $MOUNT"
498 echo "SIZE: $SIZE"
499 echo "FSTYPE: $FSTYPE"
500 echo "OPTIONS: $OPTIONS"
501
502 if [ ! "$DEV" ]
503 then
504 # if no device is specified, assume tmpfs
505 mount -n -t tmpfs -o size=${SIZE}000 /dev/null $MOUNT
506 else
507 mkdir $MOUNT 2> /dev/null
508
509 if grep "$FSTYPE" /proc/filesystems > /dev/null
510 then
511 if [ ! "$SIZE" ]
512 then
513
514 # assume entire partition should formatted
515 if [ "$FSTYPE" = "minix" ]
516 then
517 mkfs.minix $DEV
518 mount -t minix $DEV $MOUNT
519 else
520 echo "Currently only minix is supported: skipping $$DEV"
521 fi
522
523 fi # not $SIZE
524 else
525 # if no FSTYPE is specified, assume minix
526 mkfs.minix $DEV # 2> /dev/null > /dev/null
527 mount -t minix $DEV $MOUNT
528 fi
529
530 fi # no $DEV
531 done # loop through each line of corefs
532else
533 #
534 # Autosize ramdisks based on amount of RAM discovered
535 #
536
537 LIB=""
538 VAR=""
539 USR=""
540 USRLOC=""
541 HOMEP=""
542
543 echo "RAM: $MEMORY MB"
544 echo -n "RAM is "
545
546 if [ $MEMORY -lt 16000 ]
547 then
548 echo "< 16MB, you may run into problems"
549 USR="2048"
550 HOMEP="128"
551 VAR="512"
552 PKGMEM="min"
553 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
554 elif [ $MEMORY -lt 24000 ]
555 then
556 echo "> 16MB"
557 USR="4096"
558 HOMEP="256"
559 VAR="512"
560 PKGMEM="16"
561 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
562 elif [ $MEMORY -lt 32000 ]
563 then
564 echo "> 24MB"
565 USR="8192"
566 HOMEP="512"
567 VAR="1024"
568 PKGMEM="24"
569 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
570 elif [ $MEMORY -lt 48000 ]
571 then
572 echo "> 32MB"
573 USR="16384"
574 HOMEP="1024"
575 VAR="1024"
576 LIB="4896"
577 PKGMEM="32"
578
579 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
580 elif [ $MEMORY -lt 64000 ]
581 then
582 echo "> 48MB"
583 USR="16384"
584 LIB="8192"
585 USRLOC="8192"
586 HOMEP="2048"
587 VAR="2048"
588 PKGMEM="48"
589 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
590 elif [ $MEMORY -lt 96000 ]
591 then
592 echo "> 64MB"
593
594 LIB="8192"
595 USR="16384"
596 USRLOC="16384"
597 HOMEP="4096"
598 VAR="2048"
599 PKGMEM="64"
600 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
601 elif [ $MEMORY -lt 128000 ]
602 then
603 echo "> 96MB"
604 LIB="16384"
605 USR="16384"
606 USRLOC="32768"
607 HOMEP="8192"
608 VAR="4192"
609 PKGMEM="96"
610 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
611 else
612 echo "> 128MB"
613 USR="16384"
614 USRLOC="16384"
615 HOMEP="16384"
616 VAR="4192"
617 PKGMEM="128"
618 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
619 fi
620
621 #if [ "$LIB" != "" ]
622 #then
623 # echo "Creating /lib"
624 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
625
626 # if [ "$TMPFS" = "true" ]
627 # then
628 # mount -n -t tmpfs -o size=${LIB}000 /dev/null /lib
629 # else
630 # mkdir /usr 2> /dev/null
631 # mkfs.minix /dev/ram3 $LIB 2> /dev/null > /dev/null
632 # mount -t minix /dev/ram7 /lib
633 # fi
634 #fi
635
636 if [ "$USR" != "" ]
637 then
638 echo "Creating /usr"
639 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
640
641 if [ "$TMPFS" = "true" ]
642 then
643 mount -n -t tmpfs -o size=${USR}000 /dev/null /usr
644 else
645 mkdir /usr 2> /dev/null
646 mkfs.minix /dev/ram3 $USR 2> /dev/null > /dev/null
647 mount -t minix /dev/ram3 /usr
648 fi
649 fi
650
651 if [ "$USRLOC" -gt 0 ]
652 then
653
654 echo "Creating /usr/local"
655 # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
656 mkdir /usr/local 2> /dev/null
657
658 if [ "$TMPFS" = "true" ]
659 then
660 mount -n -t tmpfs -o size=${USRLOC}000 /dev/null /usr/local
661 else
662 mkfs.minix /dev/ram4 $USRLOC 2> /dev/null > /dev/null
663 mount -t minix /dev/ram4 /usr/local
664 fi
665 fi
666
667 if [ "$HOME" != "" ]
668 then
669 echo "Creating /home"
670 mkdir /home 2> /dev/null
671 if [ "$TMPFS" = "true" ]
672 then
673 mount -n -t tmpfs -o size=${HOMEP}000 /dev/null /home
674 else
675 mkfs.minix /dev/ram5 $HOMEP 2> /dev/null > /dev/null
676 mount -t minix /dev/ram5 /home
677 fi
678 fi
679
680 #
681 # Need to add a check for "physical" var
682 #
683
684 if [ "$VAR" != "" ]
685 then
686 echo "Creating /var"
687 mkdir /var 2> /dev/null
688 if [ "$TMPFS" = "true" ]
689 then
690 mount -n -t tmpfs -o size=${VAR}000 /dev/null /var
691 else
692 mkfs.minix /dev/ram5 $VAR 2> /dev/null > /dev/null
693 mount -t minix /dev/ram6 /var
694 fi
695 fi
696
697fi
698
699############################################################################
700#
701# handle /etc/tux/config/permfs
702#
703# mount "permanent filesystems" -- for now these should be umounted
704# manually to avoid corruption
705#
706# partition:mount point:filesystem:options
707#
708############################################################################
709
710
711
712
713if [ -f /etc/tux/config/permfs ]
714then
715 echo "Mounting permanent (non-ramdisk) filesystems based on /etc/tux/config/permfs"
716
717 for i in `/etc/tux/config/permfs`
718 do
719 DEV=`cat /etc/tux/config/permfs | cut -d":" -f1`
720 MOUNT=`cat /etc/tux/config/permfs | cut -d":" -f2`
721 FSTYPE=`cat /etc/tux/config/permfs | cut -d":" -f3`
722
723 if mount -t $FSTYPE $DEV $MOUNT
724 then
725 echo "-- $DEV ($FSTYPE) was mounted at $MOUNT"
726 else
727 echo "-- $DEV ($FSTYPE) failed to mount at $MOUNT!"
728 fi
729 done
730
731 echo "Remember, these must be manually umounted prior to reboot"
732fi
733
734echo "--------------------- FILESYSTEM CONFIGURATION ------------------------"
735df
736sleep 1
737echo "-----------------------------------------------------------------------"
738echo
739
740#################################################################
741#
742# Kludgy stuff to do after the filesystems have been created
743#
744################################################################
745
746echo "Creating misc links and directories..."
747
748mkdir -p /lib/modules/`uname -r`
749touch /lib/modules/`uname -r`/modules.dep
750mkdir /usr/lib/ 2> /dev/null
751ln -sf /lib/terminfo /usr/lib/terminfo
752mkdir /usr/home
753cd /var
754mkdir pkg log spool run 2> /dev/null
755cd log
756cp /dev/null mtp
757cd /
758echo
759
760if [ -f /etc/proc/fixedpkg -o "$UML" ]
761then
762 if [ -f /etc/proc/fixedpkg ]
763 then
764 part=`cat /etc/proc/fixedpkg 2> /dev/null`
765 echo "Trinux packages were found on $part"
766 PKGSRC=$part
767
768 cat /etc/tux/config/fstab | grep $part | cut -d: -f2 2> /dev/null
769
770 fstype=`cat /etc/tux/config/fstab | grep $part | cut -d: -f2 2> /dev/null`
771 fi
772
773 ##echo "[PKGSRC] = $PKGSRC"
774 ##echo "[fstype] = $fstype"
775
776 if [ "$fstype" ]
777 then
778 if mount -t $fstype /dev/${part} /mnt 2> /dev/null
779 then
780 mounted="true"
781 fi
782 fi
783
784
785
786 if [ "$UML" ]
787 then
788 echo -n "Attempting to mount UML host filesystem: "
789 if mount none /mnt -t hostfs -o $UMLROOT,ro
790 then
791 mounted="true"
792 echo "ok"
793 else
794 echo "failed"
795 fi
796 fi
797
798 echo "[mounted] = $mounted"
799
800 if [ "$mounted" ]
801 then
802 echo "Preparing to load base packages from $part"
803 if cd /mnt/trinux/bootpkg 2> /dev/null
804 then
805 for i in `ls *.tgz 2> /dev/null`
806 do
807 pkgadd $i
808 done
809 else
810 "No base packages found, hmmm..."
811 fi
812
813 echo "Preparing to load kernel packages from $part"
814 if cd /mnt/trinux/kpkg 2> /dev/null
815 then
816 if [ -f /etc/tux/conf/kpkglist ]
817 then
818 for i in `cat /etc/tux/conf/pkglist`
819 do
820 pkgadd $i
821 done
822 else
823 echo "No kpkglist found, loading everything"
824 for i in `ls *.tgz 2> /dev/null`
825 do
826 if grep $i /etc/proc/kpkg.installed > /dev/null
827 then
828 echo "$i is already installed."
829 else
830 pkgadd $i
831 fi
832 done
833
834 fi
835 else
836 echo "Kernel package directory not found on $part!"
837 fi
838
839 echo "Preparing to load packages from $part"
840
841 if cd /mnt/trinux/pkg 2> /dev/null
842 then
843 if [ -f /etc/tux/conf/pkglist ]
844 then
845 for i in `cat /etc/tux/conf/pkglist`
846 do
847 pkgadd $i
848 done
849
850 # NOTE: now the desired behavior is to put whatever
851 # you want to load into bootpkg
852 #
853 #else
854 # echo "No pkglist found, loading everything"
855 # for i in `ls *.tgz 2> /dev/null`
856 # do
857 # pkgadd $i
858 # done
859
860 fi
861 else
862 echo "Package directory not found on $part!"
863 fi
864
865 cd /
866 umount /mnt
867 else
868 echo -n "Failed to mount $part"
869 fi
870else
871 ### This should only go for a floppy
872 ### Load required packages from boot device
873 ### echo "For some reason we made it here"
874
875 sleep 1
876
877 if mount -t $BOOTFS $BOOT /boot 2> /dev/null
878 then
879 if [ "$PKGSRC" != "$CDEV" ]
880 then
881 if cd /boot/bootpkg
882 then
883 echo "Installing base packages from boot device"
884 for i in `ls`
885 do
886 pkgadd $i
887 done
888 echo
889 fi
890 fi
891 cd /
892 umount /boot
893 else
894 echo "Unable to mount $BOOT on $BOOTFS"
895 fi
896 cd /
897 umount /boot 2> /dev/null
898fi
899
900
901[ -x /etc/init.d/pcmcia ] && . /etc/init.d/pcmcia
902
903sleep 1
904
905
906
907
908############### Syslog Configuration ###################
909
910LOGHOST=`cat /etc/tux/options/loghost 2> /dev/null`
911if [ "$LOGHOST" ]
912then
913 if [ "$LOGHOST" = "prompt" ]
914 then
915 echo -n "Enter syslog server: "
916 read $LOGHOST
917 fi
918 $REMOTELOG="-R $LOGHOST"
919fi
920
921echo "Starting syslogd"
922[ -x /sbin/syslogd ] && syslogd $REMOTELOG
923
924#
925# At this point we have loaded all the packages if a CD-ROM
926# boot or package load from fixed partition
927# otherwise base packages have been loaded from the
928# floppy. We also have any saved config data. Now we attempt
929# to configure the network, then load packages from an HTTP/FTP server
930#
931
932chmod a+x /etc/tux/init/prenet 2> /dev/null
933if [ -x /etc/tux/init/prenet ]
934then
935 . /etc/tux/init/prenet
936fi
937
938
939##### Attempt to initialize networking #######################
940
941
942ifconfig lo 127.0.0.1 up
943
944
945
946# [ "$IPADDR" ] && echo "Network configured successfully"
947
948
949if [ -f /etc/tux/config/eth0 ]
950then
951 /sbin/net-start
952 IPADDR=`cat /etc/proc/ipaddr 2> /dev/null`
953else
954 echo 'No network configuration found. Type "net-config"'
955fi
956
957if [ -f /etc/tux/config/proxy ]
958then
959 SNARF_PROXY=`cat /etc/tux/config/proxy`
960 export SNARF_PROXY
961 echo "Found proxy: $SNARF_PROXY"
962 echo
963fi
964
965if [ "$PKGSRC" = "network" ]
966then
967
968 if [ "$IPADDR" != "" ]
969 then
970 echo "The network was succesfully configured"
971
972 [ -f /etc/tux/config/pkglist ] && PKGLIST=`cat /etc/tux/config/pkglist`
973
974 # attempt to connect to servers in /etc/tux/config/server
975
976 #snarf $server | grep tgz | cut -d">" -f3 | cut -d"<" -f1 > /tmp/packages
977
978 #echo "3" > /proc/sys/net/ipv4/tcp_syn_retries
979 #echo "3" > /proc/sys/net/ipv4/tcp_retries1
980 #echo "3" > /proc/sys/net/ipv4/tcp_retries2
981
982 if [ -f /etc/tux/config/server ]
983 then
984
985 for SERVER in `cat /etc/tux/config/server`
986 do
987 echo "Contacting $SERVER..."
988 if snarf $SERVER > /dev/null 2> /dev/null
989 then
990 getpkg all
991 # echo; echo "Retrieving base packages from $SERVER"
992 # for i in $PKGLIST
993 # do
994 # getpkg $i $SERVER
995 # done
996
997 if [ -f /etc/tux/config/kpkglist ]
998 then
999 KPKGLIST=`cat /etc/tux/config/kpkglist`
1000 echo "Retrieving Linux $KERNEL packages from $SERVER"
1001 for i in $KPKGLIST
1002 do
1003 getpkg $KERNEL/${i} $SERVER
1004 done
1005 fi
1006
1007 break
1008 fi
1009 done
1010 fi
1011 else
1012 PKGSRC="/dev/fd0"
1013 fi
1014fi
1015
1016if [ "$PKGSRC" = "/dev/fd0" ]
1017then
1018 echo -n "Do you have a package disk? "
1019 read response
1020
1021 until [ "$response" != "y" ]
1022 do
1023 if mount -t vfat -r /dev/fd0 /floppy 2> /dev/null
1024 then
1025 cd /floppy
1026
1027 if ls *.o > /dev/null 2> /dev/null
1028 then
1029 echo "Copying modules from package disk"
1030 cp *.o /lib/modules 2> /dev/null
1031 cp modules/*.o /lib/modules 2> /dev/null
1032 fi
1033
1034 for i in *.tgz
1035 do
1036 cd /floppy
1037 pkgadd $i
1038 done
1039 fi
1040
1041 cd /; umount /floppy
1042 echo -n "Do you have another floppy? "
1043 read response
1044 done
1045
1046
1047 #if ifconfig | grep eth0 /dev/null 2> /dev/null
1048 #then
1049 # echo "Network was sucessfully initialized"
1050 #else
1051 #net-start
1052 # fi
1053else
1054 if echo $PKGSRC | grep "/dev/[sh]d" > /dev/null
1055 then
1056 echo "Packages will be loaded from fixed disk: $PKGSRC"
1057 fi
1058fi
1059
1060
1061if [ -x /etc/tux/init/postnet ]
1062then
1063 chmod a+x /etc/tux/init/postnet 2> /dev/null
1064 . /etc/tux/init/postnet
1065fi
1066
1067# Install modules that end up in /lib/modules
1068# this will include any on the boot disk
1069#
1070# Consult /etc/tux/config/modules for any parameters
1071# (i.e. irq's io's for NIC modules
1072#
1073
1074# This should be moved to /etc/init.d/system
1075
1076echo "Enabling port scan (scanlogd)"
1077[ -x /sbin/scanlogd ] && scanlogd
1078
1079
1080### Fix the linker/library stuff
1081if [ -x /usr/sbin/ldconfig ]
1082then
1083 echo "Rebuilding ld.so.cache one last time"
1084 ldconfig -v 2> /dev/null > /dev/null
1085else
1086 echo "Unable to rebuild run-time link bindings"
1087fi
1088
1089
1090chmod a+x /etc/tux/init/prepkg 2> /dev/null
1091if [ -x /etc/tux/init/prepkg ]
1092then
1093 . /etc/tux/init/prepkg
1094fi
1095
1096[ -x /usr/bin/bash ] && ln -sf /usr/bin/bash /bin/sh
1097
1098
1099
1100## This needs to be fixed *bad*
1101
1102##/sbin/loadmodules # load any last minute kernel modules
1103
1104chmod a+x /etc/tux/init/last 2> /dev/null
1105if [ -x /etc/tux/init/last ]
1106then
1107 . /etc/tux/init/last
1108fi
1109
1110# Increasing syn_retries to something more reasonable
1111echo "7" > /proc/sys/net/ipv4/tcp_syn_retries
1112
1113######################################################################
1114# Set up swap space
1115######################################################################
1116
1117SWAPCONF=`cat /etc/tux/config/swap 2> /dev/null`
1118
1119if [ "$SWAPCONF" ]
1120then
1121 echo "Configuring swap space"
1122
1123 [ -x /sbin/mkswap ] || getpkg swaputil
1124
1125 SWAPFILE=`echo $SWAPCONF | cut -d: -f1`
1126 SWAPSIZE=`echo $SWAPCONF | cut -d: -f2`
1127
1128 [ "$SWAPSIZE" ] || SWAPSIZE=8192 # default to 8MB swap
1129
1130 if echo "$SWAPFILE" | grep "dev" > /dev/null
1131 then
1132 # user specified a partition
1133 echo "Attempting to use $SWAPFILE for swap partition"
1134 else
1135 echo "Using $SWAPFILE as your swap file"
1136 dd if=/dev/zero of=$SWAPFILE bs=512 count=$SWAPSIZE
1137 fi
1138
1139 mkswap $SWAPFILE
1140 swapon $SWAPFILE
1141 free
1142fi
1143
1144
1145####
1146
1147if [ -f /etc/tux/config/ipfwd ]
1148then
1149 echo "Enabling IP forwarding"
1150 echo "1" > /proc/sys/net/ipv4/ip_forward
1151fi
1152
1153if [ -f /etc/tux/config/noping ]
1154then
1155 echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
1156fi
1157
1158
1159
1160#### This stuff should all get moved to the system direcotry ######
1161###
1162#### Notify any emails addr in /etc/tux/options/mailmon that you're up
1163
1164if [ -f /etc/tux/config/monitor/smtp ]
1165then
1166 for ADDR in `cat /etc/tux/config/emaildst`
1167 do
1168 echo | mail $ADDR UP
1169 done
1170fi
1171
1172if [ -f /etc/tux/config/monitor/http ]
1173then
1174 webmon
1175 # add to crontab
1176 echo '0,10,20,30,40,50 * * * * /usr/sbin/webmon' >> /etc/tux/config/crontab
1177fi
1178
1179if [ -f /etc/tux/config/monitor/cdp ]
1180then
1181 echo "Starting CDP (Cisco Discovery Protocol)"
1182 echo '* * * * * /usr/sbin/cdpdump' >> /etc/tux/config/crontab
1183fi
1184
1185
1186if [ -f /etc/tux/config/crontab ]
1187then
1188 if /usr/sbin/crond 2> /dev/null
1189 then
1190 echo "Starting crond"
1191 sort /etc/tux/config/crontab | uniq > /tmp/crontab 2> /dev/null
1192 cat /tmp/crontab > /etc/tux/config/crontab 2> /dev/null
1193 /usr/sbin/crontab /etc/tux/config/crontab 2> /dev/null
1194 crontab -l
1195 echo
1196 else
1197 echo "Unable to start crond"
1198 fi
1199else
1200 echo "No crontab config found, not starting"
1201fi
1202
1203### Erase /floppy/tux/options/console to disable console access
1204###
1205##if [ -f /etc/tux/options/console ]
1206##then
1207## [ -f /etc/tux/config/home ] && gethome
1208##else
1209## grep -v askfirst /etc/inittab > /etc/inittab.new
1210## rm /etc/inittab
1211## mv /etc/inittab.new /etc/inittab
1212##fi
1213
1214### Add a hack for dropbear with fixed partition
1215
1216
1217# check for custom /etc/inittab
1218
1219if [ -f /etc/tux/config/inittab ]
1220then
1221 echo "Found custom inittab"
1222 cp /etc/tux/config/inittab /etc/inittab
1223else
1224 echo "Using default inittab"
1225fi
1226
1227if [ -x /etc/init.d/dropbear ]
1228then
1229 killall dropbear >2
1230 echo "Restarting dropbear"
1231 /etc/init.d/dropbear
1232fi
1233
1234### This shouldn't be necessary, but just in case
1235
1236if [ -x /usr/local/sbin/sshd ]
1237then
1238 if ps | grep -v sshd > /dev/null
1239 then
1240 echo "SSH server failed to start, trying again"
1241 /etc/init.d/opensshd
1242 fi
1243fi
1244
1245cat /README | tr '\t' ' ' > /usr/doc/trinux
1246
1247#################################################################
1248
1249sleep 1
1250clear
1251echo -n "Welcome to Trinux: A Linux Security Toolkit"
1252if [ "$VERSION" ]
1253then
1254 echo -n " (version "
1255 echo -n $VERSION
1256 echo ")"
1257fi
1258echo
1259echo "Type 'man' for a list of help topics or 'man trinux' for docs."
1260echo "ALT-<Left/Right> allows you to view other virtual terminals. "
1261echo