# Description: Système de base de NuTyX, contient les répertoires et scripts de demarrage.
# URL: http://www.nutyx.org/
# Maintainer: NuTyX core team
# Packager: thierryn1 at hispeed dot ch
# Depends on:

name=aaabasicfs
version=2009.2
release=1
scriptsversion=lfs-bootscripts-20090817
source=(  http://www.linuxfromscratch.org/lfs/downloads/development/$scriptsversion.tar.bz2\
 hosts clock console fstab inittab message inputrc network xorg.conf \
 profile dircolors.sh extrapaths.sh bash_profile bashrc bashrc.etc lfs-bootscripts-01.patch \
 blfs-bootscripts nu readline.sh unmask.sh X.sh i18n.sh bashrc )


build() {
       # Creating Directories
       
	mkdir -pv $PKG/{dev,proc,sys,bin,boot,etc/{profile.d,opt,skel,default},home,lib,mnt,opt,srv/sources}
	chmod 1777 $PKG/srv/sources
	mkdir -pv $PKG/{media/{floppy,cdrom,key,dvd},sbin,var}
	install -dv -m 0750 $PKG/root	
	install -dv -m 1777 $PKG/tmp 
	install -dv -m 1777 $PKG/var/tmp
	mkdir -pv $PKG/usr/{,local/}{bin,include,lib,sbin,src}
	mkdir -pv $PKG/usr/{,local/}share/{doc,info,locale,man}
	mkdir -v  $PKG/usr/{,local/}share/{misc,terminfo,zoneinfo}
	mkdir -pv $PKG/usr/{,local/}share/man/man{1..8}
	mkdir -p $PKG/usr/ports
	install -dv  $PKG/lib/{firmware,udev/devices/{pts,shm}}
	mknod -m 600 $PKG/lib/udev/devices/console c 5 1
	mknod -m 666 $PKG/lib/udev/devices/null c 1 3
	mknod -m 666 $PKG/lib/udev/devices/zero c 1 5
	mknod -m 666 $PKG/dev/null c 1 3
	mknod -m 600 $PKG/dev/console c 5 1
	for dir in $PKG/usr $PKG/usr/local; do
		ln -sv share/{man,doc,info} $dir
	done
	mkdir -v $PKG/var/{lock,log,mail,run,spool}
	mkdir -pv $PKG/var/{opt,cache,lib/{misc,locate},local}
	touch $PKG/var/log/{kern.log,auth.log,mail.log,user.log,sys.log,daemon.log,wtmp,btmp}
	chmod 640 $PKG/var/log/{kern.log,auth.log,mail.log,user.log,sys.log,daemon.log}
	chmod 0600 $PKG/var/log/btmp
	# Creating essential Files and Symlinks
	touch $PKG/etc/mtab
	ln -sv bash $PKG/bin/sh
	echo "$version-$release" > $PKG/etc/nutyx-version
	cat > $PKG/etc/shells << "EOF"
/bin/sh
/bin/bash
EOF
       cat > $PKG/etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
messagebus:x:18:18:D-BUS Message Daemon User:/dev/null:/bin/false
haldaemon:x:19:19:HAL Daemon User:/dev/null:/bin/false
gdm:x:21:21:GDM Daemon User:/dev/null:/bin/bash
fcron:x:22:22:Fcron User:/dev/null:/bin/false
apache:x:25:25:Apache Server:/dev/null:/bin/false
polkituser:x:27:27:Policy Kit Daemon User:/dev/null:/bin/false
mysql:x:40:40:MySQL Server":/dev/null/:bin/false
policykit:x:62:62:PolicyKit:/:/sbin/nologin
clamav:x:98:98:Clam AntiVirus:/dev/null:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
       cat > $PKG/etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
uucp:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
dialout:x:16:
network:x:17:
messagebus:x:18:
haldaemon:x:19:
named:x:20:
gdm:x:21:
fcron:x:22:
apache:x:25:
polkituser:x:27:
mail:x:34:
mysql:x:40:
rsyncd:x:48:
halusers:x:61:
policykit:x:62:
fuse:x:65:
scanner:x:70:
vboxusers:x:80:
clamav:x:98:
nogroup:x:99:
users:x:100:
EOF
       cat > $PKG/usr/bin/which << "EOF"
#!/bin/bash
type -pa "$@" | head -n 1 ; exit ${PIPESTATUS[0]}
EOF
	chmod -v 755 $PKG/usr/bin/which
	chown 0:0 $PKG/usr/bin/which
	cat > $PKG/etc/default/useradd << "EOF"
# Begin /etc/default/useradd

GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel

# End /etc/default/useradd
EOF
	touch $PKG/var/run/utmp $PKG/var/log/{btmp,lastlog,wtmp}
	chgrp -v 13 $PKG/var/run/utmp $PKG/var/log/lastlog
	chmod -v 664 $PKG/var/run/utmp $PKG/var/log/lastlog
	# Bootscripts
	cd $scriptsversion
	patch -Np1 -i ../lfs-bootscripts-01.patch
	make DESTDIR=$PKG install
	# We want to start the network when init 2
	mv $PKG/etc/rc.d/rc2.d/{K80,S20}network
	cd ..	
	# Remove files which will be installed by xorg7
	rm $PKG/etc/sysconfig/createfiles

	# Configuration files
	cp -v {hosts,fstab,inittab,profile,inputrc,bashrc.etc} $PKG/etc/
	mv $PKG/etc/bashrc.etc $PKG/etc/bashrc
	cp -v {dircolors.sh,extrapaths.sh,readline.sh,unmask.sh,X.sh,i18n.sh}\
	$PKG/etc/profile.d/
	cp -v {clock,console,network} $PKG/etc/sysconfig/
	cp -v bash_profile $PKG/etc/skel/.bash_profile
	cp -v bashrc $PKG/etc/skel/.bashrc
	ln -s /etc/slim.xinitrc $PKG/etc/skel/.xinitrc
	cp -v bash_profile $PKG/root/.bash_profile
	cp -v bashrc $PKG/root/.bashrc
	mkdir -p $PKG/root/bin
	cp -v nu $PKG/root/bin
       # Customise startup scripts
	cp blfs-bootscripts $PKG/etc/
	
	cp -v message $PKG/boot/

	cat > $PKG/etc/skel/.dmrc << "EOF"
[Desktop]
Session=
EOF
	mkdir -v $PKG/etc/X11
	cp -v xorg.conf $PKG/etc/X11/
	cd $PKG/root/
	ln -s ../etc/fstab
	ln -s ../etc/hosts
	ln -s ../boot/grub/menu.lst
	ln -s ../etc/inittab 
	ln -s ../etc/profile 
	ln -s ../etc/inputrc
	ln -s ../etc/bashrc
	ln -s ../etc/hosts.allow
	ln -s ../etc/hosts.deny
	ln -s ../etc/resolv.conf
	ln -s ../etc/modprobe.conf
	ln -s ../etc/shells
	ln -s ../etc/profile.d/dircolors.sh
	ln -s ../etc/profile.d/extrapaths.sh
	ln -s ../etc/profile.d/readline.sh
	ln -s ../etc/profile.d/unmask.sh
	ln -s ../etc/profile.d/X.sh
	ln -s ../etc/profile.d/i18n.sh
	ln -s ../etc/skel/.xinitrc
	ln -s ../etc/profile.d/jdk.sh
	ln -s ../etc/sysconfig/clock
	ln -s ../etc/sysconfig/console
	ln -s ../etc/sysconfig/network
	ln -s ../etc/sysconfig/modules
	ln -s ../etc/X11/xorg.conf
	ln -s ../etc/default/useradd
	ln -s ../etc/prt-get.conf
	ln -s ../etc/pkg-get.conf
	ln -s ../etc/pkgadd.conf
	ln -s ../etc/pkgmk.conf
	for i in rc0.d rc6.d
		do
			mv $PKG/etc/rc.d/$i/S{80,70}swap
			mv $PKG/etc/rc.d/$i/S{70,80}mountfs
	done
	ln -s ../init.d/setclock $PKG/etc/rc.d/rcsysinit.d/S15setclock
	mv $PKG/etc/rc.d/rcsysinit.d/S{20,40}swap
	mv $PKG/etc/rc.d/rcsysinit.d/S{30,20}checkfs
	mv $PKG/etc/rc.d/rcsysinit.d/S{40,30}mountfs
}