summaryrefslogtreecommitdiffstats
path: root/urunlevel/my_linux/Trinux/linuxrc
blob: 4597234fa2f1e7c965e124d4d146fa44f4f0fb6a (plain)
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
#!/bin/sh
#
# linuxrc - main trinux initialization script
# 
# Author:	Matthew Franz <mfranz@cisco.com>
#           Bill Burdick for the User-Mode-Linux fixes
########################################################################
#
# Attempts to do the following:
#
# -  Determine where trinux booted from [ Floppy/CD-ROM/IDE/UML ]
# -  Mount boot device and copy configuration files to /etc/tux
# -  Initialize and create ramdisks/tmpfs or mount filesystems
# -  Determine where packages are located and to be loaded from
# -  Initialize kernel modules and detect hardware
# -  Configure and enable networking
# -  Load and initialize packages
# -  Initialize system daemons
#
########################################################################
## Define stuff that is probably rejected by busybox
########################################################################

UMLROOT="/trinux-uml"
PATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin"
TERM=linux
PS1="trinux> "
PS2='>'

export PATH TERM PS1 PS2 VERSION PKGSRC BOOT PKGSRC BOOTFS FLCFG FXCFG PKGLIST FIXED 
umask 022
[ -d /etc/proc ] || mkdir -p /etc/proc
mount -t proc proc /proc
mkdir -p /lib/modules
mkdir -p /etc/tux/config
ln -sf /proc/self/fd/0 /dev/stdin
ln -sf /proc/self/fd/2 /dev/stderr
ln -sf /proc/self/fd/1 /dev/stdout

chmod a+w /tmp
chmod a+w /dev/null

#####################################################################
## Gather information about system
#####################################################################

MEMORY=`grep MemTotal /proc/meminfo | cut -d':' -f2 | cut -d'k' -f1`
KERNEL=`cat /proc/version | cut -d' ' -f3`
CDEV=`dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq`  # CD-ROM devices
FDEV=`dmesg | grep -v LDM | grep -v "ldm_val" | grep "^ [sh]d[a-f]" | cut -d':' -f2 | sort | uniq`  # FIXED

echo "Checking for fixed disks"
/sbin/chkfixed



echo "FDEV: $FDEV"
echo "CDEV: $CDEV"
sleep 1

echo "$FDEV" > /tmp/fixed


for i in `cat /tmp/fixed`
do
	echo $i 
done  > /etc/proc/fixed


[ "$CDEV" ] && echo "$CDEV" >> /etc/proc/fixed


#check initial filesytem support

for i in `grep -v nodev /proc/filesystems`
do
	echo $i 
done > /etc/proc/filesystems


######################################################################
### Special Probing stuff
######################################################################

## Did we boot from UML?
#if dmesg | grep 'User-mode Linux' > /dev/null

if grep ' ubd' /proc/devices > /dev/null
then
	echo "Trinux booted via User Mode Linux (UML)"
    sleep 3
    UML="true"
    BOOT="UML"
fi

## Did we boot from ms-dos loadlin

echo "Checking all vfat partitions for loadlin.exe"

for i in `cat /etc/proc/fixed 2> /dev/null`
do
#	[ -d /${i} ] || mkdir /${i}
#	echo "Checking $i"

	if mount -o ro -t vfat /dev/${i} /mnt 2> /dev/null
	then
		echo -n "VFAT found on $i"
		if ls /mnt/loadlin.exe 2> /dev/null
		then
			echo -n " found loadlin.exe"
			if [ -d /mnt/trinux ]
			then
				echo " found trinux"
				BOOT="/dev/${i}"
				BOOTFS="vfat"
				echo "BOOT=$BOOT"
				echo "$i" > /etc/proc/fixedpkg
				LOADLIN="true"
				cd /
				umount /mnt 2> /dev/null
				break
			fi		
		fi
		
	fi
	umount /mnt 2> /dev/null
done

# Check to see if checking for floppy drive should be disabled

if grep nofloppy /proc/cmdline > /dev/null
then
	NOFLOPPY="true"
	echo "Disabling checks for floppy drive"
fi

########################################################################
# Determine where Trinux booted from in order of likelihood
#
#   /dev/fd0         - floppy (this is normally the case)
#   /dev/hd[alpha]   - IDE CD-ROM (usually /dev/hdc)
#   /dev/hd[numeric] - IDE Hard Disk (including flash disk)
#
#  We assume that if a floppy is present and no-›
#
########################################################################
#
# first check if CD-ROM is present

if [ "$CDEV" ]
then
	echo -n "Attempting to mount CD-ROM at $CDEV:"

	if mount -t iso9660 /dev/${CDEV} /mnt 2> /dev/null > /dev/null
	then
		echo "successful"
		if [ -d /mnt/trinux ]
		then
			echo "/trinux found on $CDEV"
			PKGSRC=$CDEV # we assume packages will be loaded from it
			
			# Now check and see if we booted from CD-ROM

			if [ -d /mnt/isolinux ]
			then
				BOOT=/dev/${CDEV}
				BOOTFS="iso9660"
				NOFLOPPY="true"
				echo $CDEV > /etc/proc/fixedpkg
			fi
			cd /
			umount /mnt 2> /dev/null
		fi
	else
		echo "failed"
		[ "$UML" ] || BOOT="/dev/fd0"
	fi
fi

if [ ! "$NOFLOPPY" ]
then
	echo "Checking for floppy in /dev/fd0"
	sleep 1

	if mount -t vfat /dev/fd0 /boot 2> /dev/null
	then
		[ -d /boot/bootpkg ] && BOOT="/dev/fd0"
		[ -d /boot/tux ] && FLCFG="true"
		[ -f /boot/tux/options/floppy ] && PKGSRC="/dev/fd0"
		umount /boot 2> /dev/null

		[ "$BOOT" = "/dev/fd0" ] && echo "Trinux booted from a floppy."
		[ "$PKGSRC" = "/dev/fd0" ] && echo "Trinux will load packages from one or more floppies."
	else
		echo "Unable to mount boot floppy"
	fi
else
	echo "Floppy checking is disabled"
fi

echo $BOOT > /etc/proc/boot
echo $BOOTFS > /etc/proc/bootfs

echo
echo "========================"
echo "BOOT: $BOOT"
echo "KERNEL: $KERNEL"
echo -n "CDEV: "

if [ $CDEV ]
then
	echo "$CDEV"
else
	echo "none" 
fi

echo -n "FDEV: " 

if [ "$FDEV" ]
then
	echo $FDEV
else
	echo "none" 
fi


## Determine boot filesystem type

if [ "$BOOT" = "/dev/fd0" ] 
then
	BOOTFS="vfat"
elif [ "$UML" ]
then
	BOOTFS="ext2"
elif [ "$BOOT" = "$CDEV" ]
then
	BOOTFS="iso9660"	
fi

echo "BOOTFS: $BOOTFS"
echo "========================"
sleep 2

####################################################################
# Determine where packages should be loaded from. By default, Trinux
# will look at /etc/tux/config/pkgsrc otherwise it will look at 
# parameters passed from syslinux.cfg (i.e. pkgsrc=/dev/hda1). 
# Otherwise Trinux will assume network package loading unlesss
# the network is unable to be configured
####################################################################

if grep 'pkg=floppy' /proc/cmdline > /dev/null
then
	PKGSRC="/dev/fd0"
fi

PKGSRC="network"   ## Assume network package loading unless...

#####################################################################
## Mount the boot filesystem
## 1) copy config from tux over
## 2) install kernel module pkgs from kpkg
#####################################################################

if [ "$UML" ]
then
	echo 
	# mount the host ext2 filesystem RO so initial packages can be installed
	mount none /boot -t hostfs -o $UMLROOT,ro
else
	mount -o ro -t $BOOTFS $BOOT /boot
	VERSION=`cat /boot/version 2> /dev/null`
	PS1="Trinux $VERSION> "
fi

[ "$BOOT" != "/dev/fd0" ] && PREFIX="trinux/"

cd /boot

#pwd
#ls -al

echo "Copying /tux from boot filesystem..." 
cp -a ${PREFIX}tux /etc


echo "Copying modules from boot filesystem..."

# support either within /trinux/modules or /trinux/*.o

cp ${PREFIX}*.o /lib/modules  2> /dev/null
cp ${PREFIX}modules/*.o /lib/modules  2> /dev/null
cp ${PREFIX}modules/*.gz /lib/modules  2> /dev/null

cd /lib/modules

for i in `ls *.gz`
do
	FNAME=`basename $i .gz`
	echo "Uncompressing $i"
	gunzip $i
	mv $FNAME $FNAME.o
done

if [ -f /etc/tux/version ]
then
	VERSION=`cat /etc/tux/version 2> /dev/null`
else
	VERSION="unknown"
fi

cd /boot
if cd ${PREFIX}kpkg 2> /dev/null
then
	echo "Installing kernel module packages from boot device"
	for i in `ls`
	do
		pkgadd $i 
		echo $i >> /etc/proc/kpkg.installed
	done
fi

######## Store temporary scripts in scripts directory ###########

if [ -d ${PREFIX}scripts ]
then
	echo "Copying local scripts to /bin:"
	cd ${PREFIX}scripts
	for i in `ls`
	do	
		cp $i /bin/
		chmod u+x /bin/$i
	done
fi

cd /
umount /boot

echo "Unmounting boot filesystem"

# load in kernel modules

#cd /lib/modules

if [ -f /etc/tux/config/modules ]
then
	while read i
	do
		echo "Installing $i"
		insmod /lib/modules/$i	2> /dev/null > /dev/null
	done < /etc/tux/config/modules
fi 


echo "Waiting for modules to settle..."

sleep 3

#### Since modules have already been loaded now is a good
#### time to scour the partitions, checking for devices

echo "Checking for fixed disks"

/sbin/chkfixed

#### Check for a saved fixedpkg to avoid checking all found partitions

if [ -f /etc/tux/config/fixedpkg ] 
then
	echo -n "Found previously saved fixed package source: "
	FIXEDPKG=`cat /etc/tux/config/fixedpkg`
	if [ "$FIXEDPKG" = "cdrom" -o "$FIXEDPKG" = "cd-rom" ]
	then
		FIXEDPKG=$CDEV
	fi

	echo $FIXEDPKG	
	echo $FIXEDPKG > /etc/proc/fixed
fi 

for i in `cat /etc/proc/fixed`  # loop through fixed devices
do
	[ -d /${i} ] || mkdir /${i}  # create mount point

	for j in `cat /etc/proc/filesystems` # loop through supported fstype
	do
		#echo -n "Checking $i:" 
        if mount -o ro -t $j /dev/$i /$i  2> /dev/null > /dev/null
	 	then
     	   #echo " found $j"
           echo "$i:$j" >> /etc/tux/config/fstab
           umount /dev/$i 2> /dev/null > /dev/null 2> /dev/null
        else
            echo
        fi
	done
done

if [ -f /etc/tux/config/fstab ]
then 
	echo "The following partitions/filesytems were found:"
	cat /etc/tux/config/fstab
	cat /etc/tux/config/fstab | sort | uniq > /tmp/fstab
	cat /tmp/fstab > /etc/tux/config/fstab
fi

######### 
# Search filesystems for /trinux directories 

if [ -f /etc/proc/fixedpkg ]
then
	fixedpkg=`cat /etc/proc/fixedpkg`
	echo "/trinux already found on $fixedpkg, aborting search"
	mount
else
	if [ -f /etc/tux/config/fstab ]
	then  
		for i in `cat /etc/tux/config/fstab`
		do
			part=`cut -d: -f1 /etc/tux/config/fstab`
			fstype=`cut -d: -f2 /etc/tux/config/fstab`

			if mount -t $fstype /dev/${part} /mnt 2> /dev/null
			then
				echo -n "Checking $part for trinux directory: "

				if [ -d /mnt/trinux/ ]	
				then
					echo " found"	
					umount /mnt 2> /dev/null
					echo $part > /etc/proc/fixedpkg
					break
				else
					echo " not found"
				fi

				cd /; umount /mnt 2> /dev/null
			else
				echo -n "Failed to mount $part"
			fi
		done
	fi
fi

chmod a+x /etc/tux/init/first 2> /dev/null
if [  -x /etc/tux/init/first ]
then
	. /etc/tux/init/first
fi

#################################################################
################### Ramdisk building stuff ######################
#################################################################

if grep ' 2.4' /proc/version 2> /dev/null
then
	echo "Found 2.4.x kernel: tmpfs capable"
	if [ -f /etc/tux/config/tmpfs ]
	then
		echo "Using tmpfs"
		TMPFS="true"
	fi
else
	TMPFS="false"
fi

#### If /etc/tux/config/corefs is present we use that for 
#### partitions *other* than root. If fstab is blank then
#### everything is mounted as root. Trinux will attempt to mount
#### to filesystem and will *not* reformat
####
#### An additional file (/etc/tux/config/suppfs) will be mounted
#### later so that nfs/smbfs can be mounted
####
#### corefs format
#### partition:mount point:size in Kb:filesystem:options 
####
#### /dev/sda1:/var:512:minix:keep,ro
####
####
#### possible filesystems
####   vfat, minix, tmpfs, ram (actually minix)
####
#### plus anything compiled in your kernel

if [ -f /etc/tux/config/corefs ]
then   
	for i in `cat /etc/tux/config/corefs`
	do 
		DEV=`echo $i | cut -d: -f1`
		MOUNT=`echo $i | cut -d: -f2`
		SIZE=`echo $i | cut -d: -f3`
		FSTYPE=`echo $i | cut -d: -f4`
		OPTIONS=`echo $i | cut -d: -f5`

		echo "[DEV: $DEV]"
		echo "MOUNT: $MOUNT"
		echo "SIZE: $SIZE"
		echo "FSTYPE: $FSTYPE"
		echo "OPTIONS: $OPTIONS"

		if [ ! "$DEV"  ]
		then 
			# if no device is specified, assume tmpfs
			mount -n -t tmpfs -o size=${SIZE}000 /dev/null $MOUNT
		else
			mkdir $MOUNT 2> /dev/null

			if grep "$FSTYPE" /proc/filesystems > /dev/null
			then
					if [ ! "$SIZE" ]
					then

						# assume entire partition should formatted
						if [ "$FSTYPE" = "minix" ]
						then
							mkfs.minix $DEV
							mount -t minix $DEV $MOUNT
						else
							echo "Currently only minix is supported: skipping $$DEV"
						fi

					fi # not $SIZE
			else 
				# if no FSTYPE is specified, assume minix
				mkfs.minix $DEV # 2> /dev/null > /dev/null
				mount -t minix $DEV $MOUNT 
			fi

		fi	# no $DEV
	done # loop through each line of corefs
else
	#
	# Autosize ramdisks based on amount of RAM discovered
	#

	LIB=""
	VAR=""
	USR=""
	USRLOC=""
	HOMEP=""

	echo "RAM: $MEMORY MB"
	echo -n "RAM is "

	if [ $MEMORY -lt 16000 ]
	then
		echo "< 16MB, you may run into problems"
		USR="2048"
		HOMEP="128"
		VAR="512"
		PKGMEM="min"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	elif [ $MEMORY -lt 24000 ]
	then
		echo "> 16MB"
		USR="4096"
		HOMEP="256"
		VAR="512"
		PKGMEM="16"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	elif [ $MEMORY -lt 32000 ]
	then
		echo "> 24MB"
		USR="8192"
		HOMEP="512"
		VAR="1024"
		PKGMEM="24"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	elif [ $MEMORY -lt 48000 ]
	then
		echo "> 32MB"
		USR="16384"
		HOMEP="1024"
		VAR="1024"
		LIB="4896"
		PKGMEM="32"

	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	elif [ $MEMORY -lt 64000 ]
	then
		echo "> 48MB"
		USR="16384"
		LIB="8192"
		USRLOC="8192"
		HOMEP="2048"
		VAR="2048"
		PKGMEM="48"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	elif [ $MEMORY -lt 96000 ]
	then
		echo "> 64MB"

		LIB="8192"
		USR="16384"
		USRLOC="16384"
		HOMEP="4096"
		VAR="2048"
		PKGMEM="64" 
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	elif [ $MEMORY -lt 128000 ]
	then
		echo "> 96MB"
		LIB="16384"
		USR="16384"
		USRLOC="32768"
		HOMEP="8192"
		VAR="4192"
		PKGMEM="96"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	else
		echo "> 128MB"
		USR="16384"
		USRLOC="16384"
		HOMEP="16384"
		VAR="4192"
		PKGMEM="128"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
	fi

	#if [ "$LIB" != "" ]
	#then
	#	echo "Creating /lib"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"

	#	if [ "$TMPFS" = "true" ]
	#	then
	#		mount -n -t tmpfs -o size=${LIB}000 /dev/null /lib
	#	else
	#		mkdir /usr 2> /dev/null
	#		mkfs.minix /dev/ram3 $LIB 2> /dev/null > /dev/null
	#		mount -t minix /dev/ram7 /lib
	#	fi
	#fi

	if [ "$USR" != "" ]
	then
		echo "Creating /usr"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"

		if [ "$TMPFS" = "true" ]
		then
			mount -n -t tmpfs -o size=${USR}000 /dev/null /usr
		else
			mkdir /usr 2> /dev/null
			mkfs.minix /dev/ram3 $USR 2> /dev/null > /dev/null
			mount -t minix /dev/ram3 /usr
		fi
	fi

	if [ "$USRLOC" -gt 0 ]
	then

		echo "Creating /usr/local"
	#	echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP"
		mkdir /usr/local 2> /dev/null

		if [ "$TMPFS" = "true" ]
		then
			mount -n -t tmpfs -o size=${USRLOC}000 /dev/null /usr/local
		else
			mkfs.minix /dev/ram4 $USRLOC 2> /dev/null > /dev/null
			mount -t minix /dev/ram4 /usr/local
		fi
	fi

	if [ "$HOME" != "" ]
	then
		echo "Creating /home"
		mkdir /home 2> /dev/null
		if [ "$TMPFS" = "true" ]
		then
			mount -n -t tmpfs -o size=${HOMEP}000 /dev/null /home
		else
			mkfs.minix /dev/ram5 $HOMEP 2> /dev/null > /dev/null
			mount -t minix /dev/ram5 /home
		fi
	fi

	#
	# Need to add a check for "physical" var
	#

	if [ "$VAR" != "" ]
	then
		echo "Creating /var"
		mkdir /var 2> /dev/null
		if [ "$TMPFS" = "true" ]
		then
			mount -n -t tmpfs -o size=${VAR}000 /dev/null /var
		else
			mkfs.minix /dev/ram5 $VAR 2> /dev/null > /dev/null
			mount -t minix /dev/ram6 /var
		fi
	fi

fi

############################################################################
#
# handle /etc/tux/config/permfs
#
# mount "permanent filesystems" -- for now these should be umounted
# manually to avoid corruption 
#
# partition:mount point:filesystem:options 
#
############################################################################




if [ -f /etc/tux/config/permfs ]
then
	echo "Mounting permanent (non-ramdisk) filesystems based on /etc/tux/config/permfs"

	for  i in `/etc/tux/config/permfs`
	do
		DEV=`cat /etc/tux/config/permfs | cut -d":" -f1`
		MOUNT=`cat /etc/tux/config/permfs | cut -d":" -f2`
		FSTYPE=`cat /etc/tux/config/permfs | cut -d":" -f3`

		if mount -t $FSTYPE $DEV $MOUNT
		then
			echo "-- $DEV ($FSTYPE) was mounted at $MOUNT"
		else
			echo "-- $DEV ($FSTYPE) failed to mount at $MOUNT!"
		fi
	done

	echo "Remember, these must be manually umounted prior to reboot"
fi

echo "--------------------- FILESYSTEM CONFIGURATION ------------------------"
df
sleep 1
echo "-----------------------------------------------------------------------"
echo

#################################################################
#
# Kludgy stuff to do after the filesystems have been created
#
################################################################

echo "Creating misc links and directories..."

mkdir -p /lib/modules/`uname -r`
touch /lib/modules/`uname -r`/modules.dep
mkdir /usr/lib/ 2> /dev/null
ln -sf /lib/terminfo /usr/lib/terminfo
mkdir /usr/home
cd /var
mkdir pkg log spool run 2> /dev/null
cd log
cp /dev/null mtp
cd /
echo

if [ -f /etc/proc/fixedpkg -o "$UML" ]
then
	if [ -f /etc/proc/fixedpkg ]
	then
		part=`cat /etc/proc/fixedpkg 2> /dev/null`
		echo "Trinux packages were found on $part"
		PKGSRC=$part

	 	cat /etc/tux/config/fstab | grep $part | cut -d: -f2 2> /dev/null

	 	fstype=`cat /etc/tux/config/fstab | grep $part | cut -d: -f2 2> /dev/null`
	fi
	
	##echo "[PKGSRC] = $PKGSRC"
	##echo "[fstype] = $fstype"

	if [ "$fstype" ]
	then
		if mount -t $fstype /dev/${part} /mnt 2> /dev/null
		then
			mounted="true"	
		fi
	fi



	if [ "$UML" ]
	then
		echo -n "Attempting to mount UML host filesystem: "
	 	if mount none /mnt -t hostfs -o $UMLROOT,ro	 
		then
			mounted="true"
			echo "ok"
		else
			echo "failed"
		fi
	fi

	echo "[mounted] = $mounted"

	if [ "$mounted" ]
	then
		echo "Preparing to load base packages from $part"		
		if cd /mnt/trinux/bootpkg 2> /dev/null
		then
			for i in `ls *.tgz 2> /dev/null` 
			do
				pkgadd $i
			done
		else
			"No base packages found, hmmm..."
		fi

		echo "Preparing to load kernel packages from $part"		
		if cd /mnt/trinux/kpkg 2> /dev/null
		then	
			if [ -f /etc/tux/conf/kpkglist ]
			then	
				for i in `cat /etc/tux/conf/pkglist`
				do
					pkgadd $i
				done
			else
				echo "No kpkglist found, loading everything"
				for i in `ls *.tgz 2> /dev/null` 
				do
					if grep $i /etc/proc/kpkg.installed > /dev/null	
					then
						echo "$i is already installed."
					else
						pkgadd $i
					fi
				done
				
			fi
		else
			echo "Kernel package directory not found on $part!"
		fi

		echo "Preparing to load packages from $part"
		
		if cd /mnt/trinux/pkg 2> /dev/null
		then	
			if [ -f /etc/tux/conf/pkglist ]
			then	
				for i in `cat /etc/tux/conf/pkglist`
				do
					pkgadd $i
				done

			# NOTE: now the desired behavior is to put whatever
			# you want to load into bootpkg
			#
			#else
			#	echo "No pkglist found, loading everything"
			#	for i in `ls *.tgz 2> /dev/null` 
			#	do 
			#		pkgadd $i
			#	done
				
			fi
		else
			echo "Package directory not found on $part!"
		fi

		cd /
		umount /mnt
	else
		echo -n "Failed to mount $part"
	fi
else
	### This should only go for a floppy
	### Load required packages from boot device
	### echo "For some reason we made it here"

	sleep 1

	if mount -t $BOOTFS $BOOT /boot 2> /dev/null
	then
		if [ "$PKGSRC" != "$CDEV" ]
		then 
			if cd /boot/bootpkg 
			then
				echo "Installing base packages from boot device"
				for i in `ls`
				do
					pkgadd $i 
				done
				echo
			fi
		fi
		cd / 
		umount /boot
	else
		echo "Unable to mount $BOOT on $BOOTFS"
	fi
	cd /
	umount /boot 2> /dev/null
fi


[ -x /etc/init.d/pcmcia ] && . /etc/init.d/pcmcia

sleep 1




############### Syslog Configuration ###################

LOGHOST=`cat /etc/tux/options/loghost 2> /dev/null`
if [ "$LOGHOST" ]
then
	if [ "$LOGHOST" = "prompt" ]
	then
		echo -n "Enter syslog server: "
		read $LOGHOST
	fi
	$REMOTELOG="-R $LOGHOST"
fi

echo "Starting syslogd"
[ -x /sbin/syslogd ] && syslogd $REMOTELOG

#
# At this point we have loaded all the packages if a CD-ROM
# boot or package load from fixed partition
# otherwise base packages have been loaded from the 
# floppy.  We also have any saved config data. Now we attempt 
# to configure the network, then load packages from an HTTP/FTP server 
#

chmod a+x /etc/tux/init/prenet 2> /dev/null
if [  -x /etc/tux/init/prenet ]
then
	. /etc/tux/init/prenet
fi


##### Attempt to initialize networking #######################


ifconfig lo 127.0.0.1 up



# [ "$IPADDR" ] && echo "Network configured successfully"


if [ -f /etc/tux/config/eth0 ]
then 
	/sbin/net-start
	IPADDR=`cat /etc/proc/ipaddr 2> /dev/null`
else
	echo 'No network configuration found. Type "net-config"'
fi

if [ -f /etc/tux/config/proxy ] 
then
	SNARF_PROXY=`cat /etc/tux/config/proxy`
	export SNARF_PROXY
	echo "Found proxy: $SNARF_PROXY"
	echo
fi

if [ "$PKGSRC" = "network" ]
then
	
	if [ "$IPADDR" != "" ]
	then
		echo "The network was succesfully configured"

		[ -f /etc/tux/config/pkglist ] && PKGLIST=`cat /etc/tux/config/pkglist`

		# attempt to connect to servers in /etc/tux/config/server

		#snarf $server | grep tgz | cut -d">" -f3 | cut -d"<" -f1 > /tmp/packages

		#echo "3" > /proc/sys/net/ipv4/tcp_syn_retries
		#echo "3" > /proc/sys/net/ipv4/tcp_retries1
		#echo "3" > /proc/sys/net/ipv4/tcp_retries2

		if [ -f /etc/tux/config/server ]
		then

				for SERVER in `cat /etc/tux/config/server`
				do
					echo "Contacting $SERVER..."
					if snarf $SERVER > /dev/null 2> /dev/null
					then
						getpkg all
				#			echo; echo "Retrieving base packages from $SERVER"
				#		for i in $PKGLIST
				#		do
				#			getpkg $i $SERVER
				#		done
				
						if  [ -f /etc/tux/config/kpkglist ] 
						then
							KPKGLIST=`cat /etc/tux/config/kpkglist`
							echo "Retrieving Linux $KERNEL packages from $SERVER"
							for i in $KPKGLIST
							do
								getpkg $KERNEL/${i} $SERVER
							done
						fi

						break
					fi
				done
		fi
	else		
		PKGSRC="/dev/fd0"
	fi
fi 

if [ "$PKGSRC" = "/dev/fd0" ]
then
	echo -n "Do you have a package disk? "
	read response

	until  [ "$response" != "y" ]
	do
		if mount -t vfat -r /dev/fd0 /floppy 2> /dev/null
		then
			cd /floppy

			if ls *.o > /dev/null 2> /dev/null
			then
				echo "Copying modules from package disk"
				cp *.o /lib/modules 2> /dev/null
				cp modules/*.o  /lib/modules 2> /dev/null
			fi

			for i in *.tgz
			do
				cd /floppy
				pkgadd $i
			done	
		fi
		
		cd /; umount /floppy
		echo -n "Do you have another floppy? "
		read response
	done


	#if ifconfig | grep eth0 /dev/null 2> /dev/null
	#then
	#		echo "Network was sucessfully initialized"
	#else
	#net-start
	# fi
else
	if echo $PKGSRC | grep "/dev/[sh]d" > /dev/null
	then
		echo "Packages will be loaded from fixed disk: $PKGSRC"
	fi
fi


if [  -x /etc/tux/init/postnet ]
then
	chmod a+x /etc/tux/init/postnet 2> /dev/null
	. /etc/tux/init/postnet
fi

# Install modules that end up in /lib/modules
# this will include any on the boot disk
#
# Consult /etc/tux/config/modules for any parameters
# (i.e. irq's io's for NIC modules
#

# This should be moved to /etc/init.d/system

echo "Enabling port scan (scanlogd)"
[ -x /sbin/scanlogd ] && scanlogd


### Fix the linker/library stuff
if [ -x /usr/sbin/ldconfig ]
then
	echo "Rebuilding ld.so.cache one last time"
	ldconfig -v 2> /dev/null > /dev/null
else
	echo "Unable to rebuild run-time link bindings"
fi


chmod a+x /etc/tux/init/prepkg 2> /dev/null
if [  -x /etc/tux/init/prepkg ]
then
	. /etc/tux/init/prepkg
fi

[ -x /usr/bin/bash ] && ln -sf /usr/bin/bash /bin/sh



## This needs to be fixed *bad*

##/sbin/loadmodules # load any last minute kernel modules

chmod a+x /etc/tux/init/last 2> /dev/null
if [  -x /etc/tux/init/last ]
then
	. /etc/tux/init/last
fi

# Increasing syn_retries to something more reasonable
echo "7" > /proc/sys/net/ipv4/tcp_syn_retries

######################################################################
# Set up swap space
######################################################################

SWAPCONF=`cat /etc/tux/config/swap 2> /dev/null`

if [ "$SWAPCONF" ]
then
	echo "Configuring swap space"

	[ -x /sbin/mkswap ] || getpkg swaputil

	SWAPFILE=`echo $SWAPCONF | cut -d: -f1`
	SWAPSIZE=`echo $SWAPCONF | cut -d: -f2`

	[ "$SWAPSIZE" ] || SWAPSIZE=8192     # default to 8MB swap
	
	if echo "$SWAPFILE" | grep "dev" > /dev/null 	
	then
		# user specified a partition
		echo "Attempting to use $SWAPFILE for swap partition"
	else
		echo "Using $SWAPFILE as your swap file"
		dd if=/dev/zero of=$SWAPFILE bs=512 count=$SWAPSIZE
	fi

	mkswap $SWAPFILE
	swapon $SWAPFILE
	free
fi


####

if [ -f /etc/tux/config/ipfwd ]
then
	echo "Enabling IP forwarding"
	echo "1" > /proc/sys/net/ipv4/ip_forward
fi

if [ -f /etc/tux/config/noping ]
then
	echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all	
fi



#### This stuff should all get moved to the system direcotry ######
###
#### Notify any emails addr in /etc/tux/options/mailmon that you're up

if [ -f /etc/tux/config/monitor/smtp ]
then
    for ADDR in `cat /etc/tux/config/emaildst`
    do
        echo | mail $ADDR UP
    done
fi

if [ -f /etc/tux/config/monitor/http ]
then
	webmon
	# add to crontab
	echo '0,10,20,30,40,50 * * * * /usr/sbin/webmon' >> /etc/tux/config/crontab
fi

if [ -f /etc/tux/config/monitor/cdp ]
then
	echo "Starting CDP (Cisco Discovery Protocol)"
	echo '* * * * * /usr/sbin/cdpdump' >> /etc/tux/config/crontab
fi


if [ -f /etc/tux/config/crontab ]
then
	if /usr/sbin/crond 2> /dev/null
	then
		echo "Starting crond"
		sort /etc/tux/config/crontab | uniq > /tmp/crontab 2> /dev/null
		cat /tmp/crontab > /etc/tux/config/crontab 2> /dev/null
		/usr/sbin/crontab /etc/tux/config/crontab 2> /dev/null
		crontab -l
		echo
	else
		echo "Unable to start crond"
	fi
else
	echo "No crontab config found, not starting"
fi

### Erase /floppy/tux/options/console to disable console access
### 
##if [ -f /etc/tux/options/console ]
##then
##	[  -f /etc/tux/config/home ] && gethome
##else
##	grep -v askfirst /etc/inittab > /etc/inittab.new
##	rm /etc/inittab
##	mv /etc/inittab.new /etc/inittab 
##fi

### Add a hack for dropbear with fixed partition


# check for custom /etc/inittab

if [ -f /etc/tux/config/inittab ]
then
	echo "Found custom inittab"
	cp /etc/tux/config/inittab /etc/inittab
else
	echo "Using default inittab"
fi

if [ -x /etc/init.d/dropbear ]
then
	killall dropbear >2
	echo "Restarting dropbear"
	/etc/init.d/dropbear
fi

### This shouldn't be necessary, but just in case

if [ -x /usr/local/sbin/sshd ]
then
	if ps | grep -v sshd > /dev/null
	then
		echo "SSH server failed to start, trying again"
		/etc/init.d/opensshd	
	fi
fi

cat /README | tr '\t' ' ' >  /usr/doc/trinux

#################################################################

sleep 1 
clear
echo -n "Welcome to Trinux: A Linux Security Toolkit" 
if [ "$VERSION" ]
then
	echo -n " (version "
	echo -n $VERSION
	echo ")"
fi
echo
echo "Type 'man' for a list of help topics or 'man trinux' for docs."
echo "ALT-<Left/Right> allows you to view other virtual terminals. " 
echo