# fss-0002
# TODO: allow for auto-handling simple and maintenance initrds for different archs, such as ps3: like /boot/initrd-simple-ps3.cpio.lzo

main:
  mkdir -vp ${WO}initrd
  tkis_local_push work initrd/

  mkdir -vp dev/
  mkdir -vp mnt/
  mkdir -vp proc/
  mkdir -vp etc/
  mkdir -vp this/
  mkdir -vp tmp/
  mkdir -vp sys/
  mkdir -vp squashed/
  mkdir -vp boot/

  mkchroot . /bin/bash
  mkchroot . /bin/mount
  mkchroot . /sbin/pivot_root
  mkchroot . /sbin/fsck
  mkchroot . /sbin/e2fsck
  mkchroot . /bin/sed
  mkchroot . /bin/ls
  mkchroot . /bin/cat
  mkchroot . /bin/chroot
  mkchroot . /bin/umount
  mkchroot . /bin/tvi
  mkchroot . /bin/touch
  mkchroot . /bin/mkdir
  mkchroot . /bin/rm
  mkchroot . /bin/rmdir
  mkchroot . /bin/tree
  mkchroot . /bin/dircolors
  mkchroot . /bin/more
  mkchroot . /bin/less
  mkchroot . /sbin/e2label
  mkchroot . /sbin/mkswap
  mkchroot . /sbin/mke2fs
  mkchroot . /sbin/mknod
  mkchroot . /bin/dd
  mkchroot . /sbin/grub
  mkchroot . /bin/nano
  mkchroot . /bin/tar
  mkchroot . /bin/gzip
  mkchroot . /bin/lzop
  mkchroot . /bin/bzip2
  mkchroot . /bin/lzip
  mkchroot . /bin/xz
  mkchroot . /bin/ping
  mkchroot . /bin/ping6
  mkchroot . /bin/traceroute
  mkchroot . /bin/ncat
  mkchroot . /sbin/ip
  mkchroot . /sbin/iw
  mkchroot . /sbin/brctl
  mkchroot . /sbin/dhcpclient
  mkchroot . /sbin/dhcpclient-script
  mkchroot . /sbin/netnamer
  mkchroot . /sbin/dmnamer
  mkchroot . /sbin/mmcnamer
  mkchroot . /bin/network
  mkchroot . /bin/firewall
  mkchroot . /sbin/iptables
  mkchroot . /sbin/modprobe
  mkchroot . /sbin/lsmod
  mkchroot . /bin/top
  mkchroot . /bin/ln
  mkchroot . /bin/df
  mkchroot . /bin/cp
  mkchroot . /bin/mv
  mkchroot . /bin/chgrp
  mkchroot . /bin/chown
  mkchroot . /bin/chmod
  mkchroot . /bin/lsattr
  mkchroot . /bin/attr
  mkchroot . /bin/chattr
  mkchroot . /bin/getfattr
  mkchroot . /bin/setfattr
  mkchroot . /bin/grep
  mkchroot . /bin/mksquashfs
  mkchroot . /bin/unsquashfs
  mkchroot . /sbin/hwclock
  mkchroot . /sbin/firmware.sh
  mkchroot . /sbin/blkid
  mkchroot . /bin/sleep
  mkchroot . /sbin/kexec
  mkchroot . /bin/sha256sum
  mkchroot . /bin/sha512sum
  mkchroot . /sbin/cryptsetup
  mkchroot . /sbin/mdadm
  mkchroot . /sbin/shred
  mkchroot . /sbin/udevadmn
  mkchroot . /sbin/udevd
  mkchroot . /sbin/touch
  mkchroot . /sbin/mkfs.hfs
  mkchroot . /sbin/fsck.hfs
  mkchroot . /sbin/fsck.cramfs
  mkchroot . /sbin/fsck.minix
  mkchroot . /sbin/mkfs.cramfs
  mkchroot . /sbin/mkfs.jffs
  mkchroot . /sbin/mkfs.jffs2
  mkchroot . /sbin/mkfs.minix
  mkchroot . /sbin/ddrescue
  mkchroot . /bin/dmesg
  mkchroot . /bin/uname
  mkchroot . /sbin/lvm
  mkchroot . /sbin/parted
  mkchroot . /sbin/partclone.dd
  mkchroot . /sbin/partclone.extfs
  mkchroot . /sbin/partclone.fat
  mkchroot . /sbin/partclone.hfsp
  mkchroot . /sbin/partclone.info
  mkchroot . /sbin/partclone.ntfs
  mkchroot . /sbin/partclone.ntfsfixboot
  mkchroot . /sbin/partclone.restore
  mkchroot . /sbin/badblocks
  mkchroot . /bin/sync
  mkchroot . /bin/fss_basic_list_read
  mkchroot . /bin/fss_basic_read
  mkchroot . /bin/fss_extended_read
  mkchroot . /sbin/mdadm
  mkchroot . /bin/cpio

  mv -v bin/tvi bin/vi
  ln -vsf e2fsck sbin/fsck.ext2
  ln -vsf e2fsck sbin/fsck.ext3
  ln -vsf e2fsck sbin/fsck.ext4
  ln -vsf mke2fs sbin/mkfs.ext2
  ln -vsf mke2fs sbin/mkfs.ext3
  ln -vsf mke2fs sbin/mkfs.ext4
  ln -vsf bash bin/sh
  ln -vsf profile etc/bashrc
  ln -vsf xz bin/lzma
  ln -vsf vi bin/vim

  mkdir -vp lib/scripts
  cp -vR /lib/scripts/turtle_kevux lib/scripts/
  cp -vR /lib/xtables lib/
  cp -v ${PR}fstab-initrd etc/fstab
  cp -vf ${PR}tvimrc etc/tvimrc
  cp -vf ${PR}profile-simple etc/profile
  cp -Rvf ${PR}profile.d-simple etc/profile.d
  cp -Rvf ${PR}dircolors-simple etc/dircolors
  chown 0:0 -R etc/dircolors etc/profile.d etc/profile
  cp -vf /sbin/initrd_init sbin/init
  cp -vR /etc/udev/ etc/
  cp -v /sbin/{live,settings}_init /sbin/find_device sbin/
  chmod u+x sbin/{live,settings}_init sbin/find_device
  mkdir -p etc/network/
  cp -v /etc/network/default-device etc/network/
  cp -v /etc/network/default-firewall etc/network/
  mkdir -vp share/terminfo/l/
  cp -v /share/terminfo/l/linux share/terminfo/l/
  cp -v /etc/group etc/
  cp -v /etc/passwd etc/
  cp -v /etc/timezone etc/
  sed -i -e "s|^$root_user_name:x:0:0:System Administrator:$root_user_home_dir:/bin/bash|initrder:x:0:0::/:/bin/bash|" etc/passwd
  sed -i -e "s|^$root_user_name:x:0:|initrder:x:0:|" etc/group

  strip --strip-debug bin/* || true
  strip --strip-debug lib/*.so* || true
  strip --strip-debug sbin/* || true

  tkis_local_pop
  tkis_local_push work initrd/dev/
  bash ${PR}make_devices
  bash ${PR}make_devices_permissions

  # The initramfs way
  tkis_local_pop
  tkis_local_push work initrd
  find . | cpio --quiet -H newc -o | $initrd_compression_command > ${WO}turtle-maintenance-$kernel_build_architecture.initrd
  tkis_local_pop
  mv -v ${WO}turtle-maintenance-$kernel_build_architecture.initrd /boot/
  chgrp d_boot /boot/turtle-maintenance-$kernel_build_architecture.initrd

  rm -Rf ${WO}initrd/


simple:
  mkdir -vp ${WO}initrd
  tkis_local_push work initrd/

  mkdir -vp dev/
  mkdir -vp mnt/
  mkdir -vp proc/
  mkdir -vp etc/
  mkdir -vp this/
  mkdir -vp tmp/
  mkdir -vp sys/
  mkdir -vp squashed/
  mkdir -vp boot/

  mkchroot . /bin/bash
  mkchroot . /bin/mount
  mkchroot . /sbin/pivot_root
  mkchroot . /bin/ls
  mkchroot . /bin/cat
  mkchroot . /bin/chroot
  mkchroot . /bin/umount
  mkchroot . /bin/touch
  mkchroot . /bin/mkdir
  mkchroot . /bin/rm
  mkchroot . /bin/rmdir
  mkchroot . /sbin/mknod
  mkchroot . /sbin/lsmod
  mkchroot . /bin/ln
  mkchroot . /bin/cp
  mkchroot . /bin/mv
  mkchroot . /bin/sed
  mkchroot . /bin/chgrp
  mkchroot . /bin/chown
  mkchroot . /bin/chmod
  mkchroot . /bin/grep
  mkchroot . /bin/unsquashfs
  mkchroot . /sbin/firmware.sh
  mkchroot . /sbin/blkid
  mkchroot . /bin/sleep
  mkchroot . /sbin/kexec
  mkchroot . /sbin/cryptsetup
  mkchroot . /bin/uname
  mkchroot . /sbin/ip
  mkchroot . /sbin/iw
  mkchroot . /sbin/brctl
  mkchroot . /sbin/dhcpclient
  mkchroot . /sbin/dhcpclient-script
  mkchroot . /sbin/netnamer
  mkchroot . /sbin/dmnamer
  mkchroot . /sbin/mmcnamer
  mkchroot . /bin/network
  mkchroot . /bin/firewall
  mkchroot . /sbin/iptables
  mkchroot . /bin/sync
  mkchroot . /bin/fss_basic_list_read
  mkchroot . /bin/fss_basic_read
  mkchroot . /bin/fss_extended_read
  mkchroot . /sbin/mdadm
  mkchroot . /bin/less
  mkchroot . /bin/dmesg

  ln -vsf bash bin/sh
  ln -vsf profile etc/bashrc

  mkdir -vp lib/scripts
  cp -vR /lib/scripts/turtle_kevux lib/scripts/
  cp -vR /lib/xtables lib/
  cp -v ${PR}fstab-initrd etc/fstab
  cp -vf ${PR}profile-simple etc/profile
  cp -Rvf ${PR}profile.d-simple etc/profile.d
  cp -Rvf ${PR}dircolors-simple etc/dircolors
  chown 0:0 -R etc/dircolors etc/profile.d etc/profile
  cp -vf /sbin/initrd_init sbin/init
  cp -vR /etc/udev/ etc/
  cp -v /sbin/{live,settings}_init /sbin/find_device sbin/
  chmod u+x sbin/{live,settings}_init sbin/find_device
  mkdir -vp share/terminfo/l/
  cp -v /share/terminfo/l/linux share/terminfo/l/
  cp -v /etc/group etc/
  cp -v /etc/passwd etc/
  cp -v /etc/timezone etc/
  mkdir -p etc/network/
  cp -v /etc/network/default-device etc/network/
  cp -v /etc/network/default-firewall etc/network/
  sed -i -e "s|^$root_user_name:x:0:0:System Administrator:$root_user_home_dir:/bin/bash|initrder:x:0:0::/:/bin/bash|" etc/passwd
  sed -i -e "s|^$root_user_name:x:0:|initrder:x:0:|" etc/group

  strip --strip-debug bin/* || true
  strip --strip-debug lib/*.so* || true
  strip --strip-debug sbin/* || true

  tkis_local_pop
  tkis_local_push work initrd/dev/
  bash ${PR}make_devices
  bash ${PR}make_devices_permissions

  tkis_local_pop
  tkis_local_push work initrd
  find . | cpio --quiet -H newc -o | $initrd_compression_command > ${WO}turtle-simple-$kernel_build_architecture.initrd
  tkis_local_pop
  mv -v ${WO}turtle-simple-$kernel_build_architecture.initrd /boot/
  chgrp d_boot /boot/turtle-simple-$kernel_build_architecture.initrd

  rm -Rf ${WO}initrd/
