source: scripts/target-scripts/target-final-prep.sh@ 60454e2

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 60454e2 was 617118d, checked in by Jim Gifford <clfs@…>, 19 years ago

r561@server (orig r559): root | 2005-06-05 02:38:49 -0700
Fixed Directory Structure

  • Property mode set to 100755
File size: 7.1 KB
Line 
1#!/bin/bash
2
3# cross-lfs final target partition prep
4# -------------------------------------
5# $LastChangedBy$
6# $LastChangedDate$
7# $LastChangedRevision$
8# $HeadURL$
9#
10
11test x${LFS} != x || barf
12
13LOG=final-prep-target.log
14max_log_init "Final prep" "" "target" ${INSTLOGS} ${LOG}
15
16### Final Prep for chroot ###
17
18mkdir -p ${LFS}/{bin,boot,dev/pts,/dev/shm,etc/opt,home,lib,mnt,proc}
19mkdir -p ${LFS}/{root,sbin,tmp,usr/local,var,opt}
20
21case ${KERNEL_VER} in
22 2.5* | 2.6* ) mkdir -p ${LFS}/sys ;;
23esac
24
25for dirname in ${LFS}/usr ${LFS}/usr/local
26 do
27
28 mkdir -p $dirname/{bin,etc,include,lib,sbin,share,src}
29 # Apparently not FHS compliant but without these LFS breaks (RO)
30 ln -sf share/{man,doc,info} $dirname
31
32 # More FHS compliant but breaks LFS builds
33 #mkdir -p $dirname/{bin,include,lib,sbin,share,src}
34
35 mkdir -p $dirname/share/{dict,doc,info,locale,man}
36 mkdir -p $dirname/share/{nls,misc,terminfo,zoneinfo}
37 mkdir -p $dirname/share/man/man{1,2,3,4,5,6,7,8}
38done
39mkdir -p ${LFS}/usr/local/games
40ln -sf share/man ${LFS}/usr/local
41mkdir -p ${LFS}/var/{lock,log,mail,run,spool} &&
42mkdir -p ${LFS}/var/{tmp,opt,cache,lib/misc,local} &&
43mkdir -p ${LFS}/opt/{bin,doc,include,info} &&
44mkdir -p ${LFS}/opt/{lib,man/man{1,2,3,4,5,6,7,8}} &&
45
46touch ${LFS}/var/run/utmp ${LFS}/var/log/{btmp,lastlog,wtmp} &&
47chmod 644 ${LFS}/var/run/utmp ${LFS}/var/log/{btmp,lastlog,wtmp}
48
49chmod 0750 ${LFS}/root &&
50chmod 1777 ${LFS}/tmp ${LFS}/var/tmp
51
52if [ ! "${USE_SYSROOT}" = "Y" ]; then
53 # setup bash symlinks
54 ln -sf ..${TGT_TOOLS}/bin/bash ${LFS}/bin
55 ln -sf bash ${LFS}/bin/sh
56
57 # Required for glibc build
58 ln -sf ..${TGT_TOOLS}/bin/pwd ${LFS}/bin
59 ln -sf ../..${TGT_TOOLS}/bin/perl ${LFS}/usr/bin
60 # added for glibc make check
61 ln -sf ..${TGT_TOOLS}/bin/cat ${LFS}/bin
62
63 # added for binutils ar test
64 ln -sf ..${TGT_TOOLS}/bin/stty ${LFS}/bin
65 # ln -sf ../..${TGT_TOOLS}/bin/msgfmt ${LFS}/usr/bin
66 # ln -sf ../..${TGT_TOOLS}/bin/xgettext ${LFS}/usr/bin
67 # ln -sf ../..${TGT_TOOLS}/bin/msgmerge ${LFS}/usr/bin
68 ln -sf ../..${TGT_TOOLS}/bin/install ${LFS}/usr/bin
69 ln -sf ../usr/bin/install ${LFS}/bin
70
71 # Added for ch6 findutils locate tests
72 ln -sf ..${TGT_TOOLS}/bin/echo ${LFS}/bin
73
74 ## CHECK IF FINDUTILS STILL NEEDS AWK/SED SYMLINKS ##
75 ln -sf ..${TGT_TOOLS}/bin/sed ${LFS}/bin
76 ln -sf ..${TGT_TOOLS}/bin/awk ${LFS}/bin
77
78 # ch6 ed make check needs cmp
79 ln -sf ../..${TGT_TOOLS}/bin/cmp ${LFS}/usr/bin
80
81 # for ch6 coreutils user checks
82 ln -sf ..${TGT_TOOLS}/bin/su ${LFS}/bin
83
84 # For the bootscripts
85 ln -sf ../..${TGT_TOOLS}/bin/find ${LFS}/usr/bin
86 ln -sf ..${TGT_TOOLS}/sbin/fsck ${LFS}/sbin
87 ln -sf ..${TGT_TOOLS}/bin/grep ${LFS}/bin
88 ln -sf ..${TGT_TOOLS}/bin/ls ${LFS}/bin
89 ln -sf ..${TGT_TOOLS}/bin/ln ${LFS}/bin
90 ln -sf ..${TGT_TOOLS}/bin/mkdir ${LFS}/bin
91 ln -sf ..${TGT_TOOLS}/bin/rm ${LFS}/bin
92 ln -sf ..${TGT_TOOLS}/bin/sleep ${LFS}/bin
93 ln -sf ..${TGT_TOOLS}/bin/chown ${LFS}/bin
94 ln -sf ..${TGT_TOOLS}/bin/chmod ${LFS}/bin
95
96 # for hotplug...
97 ln -sf ..${TGT_TOOLS}/bin/uname ${LFS}/bin
98 ln -sf ../..${TGT_TOOLS}/bin/env ${LFS}/usr/bin
99 ln -sf ../..${TGT_TOOLS}/bin/cut ${LFS}/usr/bin
100 ln -sf ../..${TGT_TOOLS}/bin/od ${LFS}/usr/bin
101 ln -sf ../..${TGT_TOOLS}/bin/wc ${LFS}/usr/bin
102 ln -sf ../..${TGT_TOOLS}/bin/readlink ${LFS}/usr/bin
103fi
104
105if [ ! -f ${LFS}/etc/passwd ]; then
106 # Our new root user will be called "root".
107 # NOTE root password field should be "x" if shadow is installed.
108 echo "root::0:0:root:/root:/bin/bash" > ${LFS}/etc/passwd
109 echo "plfstest:x:1000:100:root:/root:/bin/bash" >> ${LFS}/etc/passwd
110 echo "nobody:x:65534:65534:nobody:/home:/bin/false" >> ${LFS}/etc/passwd
111fi
112
113chmod 644 ${LFS}/etc/passwd
114
115if [ ! -f ${LFS}/etc/shadow ]; then
116 # Get number of seconds since epoch
117 LASTCHG=`date +%s`
118 # Convert to days since epoch
119 LASTCHG=`expr ${LASTCHG} / 86400`
120
121 echo "root::${LASTCHG}:0:99999:7:::" > ${LFS}/etc/shadow
122 echo "plfstest:!:${LASTCHG}:0:99999:7:::" >> ${LFS}/etc/shadow
123 echo "nobody:!:${LASTCHG}:0:99999:7:::" >> ${LFS}/etc/shadow
124fi
125
126chmod 600 ${LFS}/etc/shadow
127
128# Note: these are from LFS book CVS 2003-03-24, but with some modifications
129if [ ! -f ${LFS}/etc/group ]; then
130 cat > ${LFS}/etc/group << "EOF"
131root:x:0:
132bin:x:1:
133sys:x:2:
134kmem:x:3:
135tty:x:4:
136tape:x:5:
137daemon:x:6:
138floppy:x:7:
139disk:x:8:
140lp:x:9:
141dialout:x:10:
142audio:x:11:
143wheel:x:12:
144users:x:100:
145nogroup:x:65534:
146EOF
147fi
148
149chmod 644 ${LFS}/etc/group
150
151# Create initial nsswitch.conf file
152
153cat > ${LFS}/etc/nsswitch.conf << "EOF"
154passwd: files
155shadow: files
156group: files
157hosts: files dns
158EOF
159
160# Create files required for NSS
161
162# ${LFS}/etc/hosts should have been created when target-lfs-bootscripts was run.
163# If it wasnt (???) create one here
164
165test -f ${LFS}/etc/hosts ||
166 echo -e "127.0.0.1\tlocalhost.localdomain\tlocalhost" > ${LFS}/etc/hosts
167
168chmod 644 ${LFS}/etc/hosts
169
170# TODO: need to install
171test -f ${LFS}/etc/resolv.conf ||
172 touch ${LFS}/etc/resolv.conf
173
174chmod 644 ${LFS}/etc/resolv.conf
175
176# This fstab is merely a template, you will have to edit the / entry before
177# attempting to boot a rw root filesystem.
178
179cat > ${LFS}/etc/fstab << "EOF"
180#/dev/BOOT /boot ext2 noauto,noatime 1 1
181#/dev/ROOT / xfs noatime 0 0
182#/dev/SWAP none swap sw 0 0
183#/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
184#/dev/fd0 /mnt/floppy auto noauto 0 0
185none /proc proc defaults 0 0
186none /dev/pts devpts gid=4,mode=620 0 0
187none /dev/shm tmpfs defaults 0 0
188EOF
189
190case ${KERNEL_VER} in
191 2.5* | 2.6* )
192 echo "none /sys sysfs defaults 0 0" >> ${LFS}/etc/fstab
193 ;;
194esac
195
196chmod 644 ${LFS}/etc/fstab
197
198# We create /etc/shells for the benefit of inetutils ftpd
199
200cat > ${LFS}/etc/shells << "EOF"
201/bin/sh
202/bin/bash
203EOF
204
205chmod 644 ${LFS}/etc/shells
206
207# TODO: need to create some (if not all) of the following
208# NSSFILES="ethers netmasks networks rpc netgroup automount aliases"
209
210# Unfortunately we can't just chown to root only the stuff owned by the user
211# running the build. That is because some installers created files with
212# certain group and user rights (bin, tty, etc). This gets screwed up if
213# the build host doesn't have identical system accounts to those in the
214# passwd file we just installed. So we chown the whole damn thing to root, being
215# careful of sticky, SGID and SUID files. Some systems clear those bits upon
216# chown.
217# The ch. 6 build will have to overwrite all of the problems this causes.
218
219cd ${LFS}
220( echo "These SUID files are having their user changed to root:"
221find . -user 0 -o \( -perm +4000 -print \)
222echo "These SGID files are having their group changed to root:"
223find . -group 0 -o \( -perm +2000 -print \)
224echo "These sticky directories are having their user/group changed to root:"
225find . \( -user 0 -group 0 \) -o \( -perm +1000 -print \)
226echo "These world writable executables are being made non-world writable:"
227find . -type f -perm +111 -perm -2 -print
228find . -type f -perm +111 -perm -2 -exec chmod o-w \{\} \; ) | tee -a ${LOGFILE}
229chown -R 0 ${LFS}
230chgrp -R 0 ${LFS}
231
232echo export PS1="'"'\u@\h \W$ '"'" >${LFS}/etc/profile
233echo export PATH=/bin:/usr/bin:/sbin:/usr/sbin:${TGT_TOOLS}/bin:${TGT_TOOLS}/sbin:${TGT_TOOLS}/usr/bin >>${LFS}/etc/profile
234
235echo " o All OK"
Note: See TracBrowser for help on using the repository browser.