#!/bin/bash #©keithhedger Mon 2 Feb 12:38:29 GMT 2015 kdhedger68713@gmail.com readWithDefault () { local varname="$1" local varcontents="${!varname}" local message="$2" read -e -p "$message [ ${varcontents} ] " if [ "X$REPLY" != "X" ];then eval "${varname}=$REPLY" fi } if [ $UID -ne 0 ];then echo "You MUST run this script as root ..." exit 100 fi if [ -e ./SystemData ];then . ./SystemData else echo "No SystemData file found ..." exit 100 fi if [[ -z $LFS ]];then echo 'LFS NOT SET!!! Exiting ...' exit 100 else readWithDefault "LFS" "LFS set to \"$LFS\"" if ! mountpoint $LFS;then echo "LFS NOT Mounted, exiting ..." exit 100 fi fi pushd $LFS mkdir -v {dev,proc,sys}||true mknod -m 600 dev/console c 5 1 mknod -m 666 dev/null c 1 3 mkdir -pv {bin,boot,etc/{sysconfig,profile.d},home,mnt,opt,run} mkdir -pv {media/{floppy,cdrom},sbin,srv,var} install -dv -m 0750 root install -dv -m 777 tmp var/tmp mkdir -pv usr/{,local/}{bin,include,lib${LIBDIRSUFFIX},sbin,src} mkdir -pv usr/{,local/}share/{color,dict,doc,info,locale,man} mkdir -v usr/{,local/}share/{misc,terminfo,zoneinfo} mkdir -pv usr/libexec mkdir -pv usr/{,local/}share/man/man{1..8} for dir in usr usr/local do ln -sfnv share/{man,doc,info} $dir done case $(uname -m) in x86_64) ln -sfnv lib${LIBDIRSUFFIX} usr/local/lib ;; esac mkdir -vp run/shm mkdir -v var/{log,mail,spool} ln -sfnv /run var/run ln -sfnv /run/lock var/lock mkdir -pv var/{opt,cache,lib/{color,misc,locate},local} ln -sfnv /proc/self/mounts etc/mtab cat > etc/passwd << "EOF" root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/dev/null:/bin/false daemon:x:6:6:Daemon User:/dev/null:/bin/false messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false nobody:x:99:99:Unprivileged User:/dev/null:/bin/false EOF cat > etc/group << "EOF" root:x:0: bin:x:1:daemon sys:x:2: kmem:x:3: tape:x:4: tty:x:5: daemon:x:6: floppy:x:7: disk:x:8: lp:x:9: dialout:x:10: audio:x:11: video:x:12: utmp:x:13: usb:x:14: cdrom:x:15: adm:x:16: console:x:17 messagebus:x:18: cdrw:x:18 news:x:19 scanner:x:20 wheel:x:21 network:x:22 plugdev:x:23 users:x:24 power:x:25 mail:x:34: nogroup:x:99: EOF mkdir -vp etc/sysconfig cat > etc/sysconfig/ifconfig.eth0 << EOF ONBOOT=yes IFACE=eth0 SERVICE=ipv4-static IP=$IP GATEWAY=$GATEWAY PREFIX=24 BROADCAST=${SUBNET} EOF cat > etc/resolv.conf << EOF # Begin /etc/resolv.conf domain local $(for i in $NAMESERVERS;do echo nameserver $i;done) # End /etc/resolv.conf EOF cat > etc/hosts << EOF # Begin /etc/hosts (network card version) 127.0.0.1 localhost $IP $LFSNAME $LFSNAME.local # End /etc/hosts (network card version) EOF echo "HOSTNAME=$LFSNAME" > etc/sysconfig/network cat > etc/sysconfig/clock << "EOF" # Begin /etc/sysconfig/clock UTC=1 # Set this to any options you might need to give to hwclock, # such as machine hardware clock type for Alphas. CLOCKPARAMS= # End /etc/sysconfig/clock EOF cat > etc/sysconfig/console << EOF # Begin /etc/sysconfig/console KEYMAP=$KEYBOARD #FONT="lat2a-16 -m 8859-2" # End /etc/sysconfig/console EOF cat > etc/profile << EOF # Begin /etc/profile export LANG=$LANGUAGE pathremove () { local IFS=':' local NEWPATH local DIR local PATHVARIABLE=\${2:-PATH} for DIR in \${!PATHVARIABLE} do if [ "\$DIR" != "\$1" ];then NEWPATH=\${NEWPATH:+\$NEWPATH:}\$DIR fi done export \$PATHVARIABLE="\$NEWPATH" } pathprepend () { pathremove \$1 \$2 local PATHVARIABLE=\${2:-PATH} export \$PATHVARIABLE="\$1\${!PATHVARIABLE:+:\${!PATHVARIABLE}}" } pathappend () { pathremove \$1 \$2 local PATHVARIABLE=\${2:-PATH} export \$PATHVARIABLE="\${!PATHVARIABLE:+\${!PATHVARIABLE}:}\$1" } export -f pathremove pathprepend pathappend # Set the initial path export PATH=/bin:/usr/bin export HISTSIZE=1000 export HISTIGNORE="&:[bf]g:exit" if [ \$EUID -eq 0 ];then pathappend /sbin:/usr/sbin #unset HISTFILE fi export XDG_DATA_DIRS=\${XDG_DATA_DIRS:-/usr/share/} export XDG_CONFIG_DIRS=\${XDG_CONFIG_DIRS:-/etc/xdg/} export XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/tmp/xdg-\$USER} # Setup a red prompt for root and a green one for users. NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" if [[ \$EUID == 0 ]] ; then PS1=''\${RED}'\u@\h [ '\${NORMAL}'\w '\${RED}']$'\${NORMAL}' ' else PS1=''\${GREEN}'\u@\h [ '${NORMAL}'\w '\${GREEN}']$'\${NORMAL}' ' fi for script in /etc/profile.d/*.sh do if [ -r \$script ];then . \$script fi done unset script RED GREEN NORMAL # End /etc/profile EOF cat > etc/inputrc << "EOF" # Begin /etc/inputrc # Modified by Chris Lynn # Allow the command prompt to wrap to the next line set horizontal-scroll-mode Off # Enable 8bit input set meta-flag On set input-meta On # Turns off 8th bit stripping set convert-meta Off # Keep the 8th bit for display set output-meta On # none, visible or audible set bell-style none # All of the following map the escape sequence of the value # contained in the 1st argument to the readline specific functions "\eOd": backward-word "\eOc": forward-word # for linux console "\e[1~": beginning-of-line "\e[4~": end-of-line "\e[5~": beginning-of-history "\e[6~": end-of-history "\e[3~": delete-char "\e[2~": quoted-insert # for xterm "\eOH": beginning-of-line "\eOF": end-of-line # for Konsole "\e[H": beginning-of-line "\e[F": end-of-line # End /etc/inputrc EOF swapline="$(lsblk -no UUID $SWAP 2>/dev/null)" && swapline="UID=$(lsblk -no UUID $SWAP 2>/dev/null)" || [ -n $SWAP ] && [ -e "$SWAP" ] && swapline="$SWAP" || swapline="#" cat > etc/fstab << EOF # Begin /etc/fstab #file system mount-point type options dump fsck order UUID=$(findmnt -no UUID $LFS) / $ROOTFSTYPE defaults 1 1 $swapline swap swap pri=1 0 0 proc /proc proc nosuid,noexec,nodev 0 0 sysfs /sys sysfs nosuid,noexec,nodev 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /run tmpfs defaults 0 0 devtmpfs /dev devtmpfs mode=0755,nosuid 0 0 # End /etc/fstab EOF cat > etc/inittab << "EOF" # Begin /etc/inittab id:3:initdefault: si::sysinit:/etc/rc.d/init.d/rc S l0:0:wait:/etc/rc.d/init.d/rc 0 l1:S1:wait:/etc/rc.d/init.d/rc 1 l2:2:wait:/etc/rc.d/init.d/rc 2 l3:3:wait:/etc/rc.d/init.d/rc 3 l4:4:wait:/etc/rc.d/init.d/rc 4 l5:5:wait:/etc/rc.d/init.d/rc 5 l6:6:wait:/etc/rc.d/init.d/rc 6 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now su:S016:once:/sbin/sulogin 1:2345:respawn:/sbin/agetty --noclear tty1 9600 2:2345:respawn:/sbin/agetty tty2 9600 3:2345:respawn:/sbin/agetty tty3 9600 4:2345:respawn:/sbin/agetty tty4 9600 5:2345:respawn:/sbin/agetty tty5 9600 6:2345:respawn:/sbin/agetty tty6 9600 # End /etc/inittab EOF echo $LFSVERSION > etc/lfs-release cat > etc/lsb-release << EOF DISTRIB_ID="Linux From Scratch" DISTRIB_RELEASE="$LFSVERSION" DISTRIB_CODENAME="$LFSNAME" DISTRIB_DESCRIPTION="Linux From Scratch" EOF cat > etc/shells << EOF # Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF if [ ! -e etc/lfspkg.rc ];then cat > etc/lfspkg.rc << EOF LFSVERSION=$LFSVERSION KERNELVERSION=$KERNELVERSION LIBDIRSUFFIX=$LIBDIRSUFFIX SCRIPTLOG=1 OUTPUT=$PKGARCHIVES SOURCEARCHIVES=$SOURCEARCHIVES BUILDSCRIPTS=$BUILDSCRIPTS COMPILEAT=$COMPILEAT CONFIGOPTIONS="--disable-option-checking --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --libdir=/usr/lib\$LIBDIRSUFFIX --disable-debug --disable-nls --disable-static" MESONCONFIGOPTIONS="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --libdir=/usr/lib\$LIBDIRSUFFIX --buildtype=release --default-library=shared" MAKEFLAGS=" -j4 " CHECKETC=0 EOF fi #Set the perms for $LFS will fail for any mounted network tha can't have their perms changed ( eg a samba mount ). chown -R root:root $LFS/* 2>/dev/null||true touch var/log/{btmp,lastlog,wtmp} chmod -v 664 var/log/lastlog chmod -v 600 var/log/btmp chgrp -v utmp var/log/lastlog chmod 777 tmp popd