# Description: Root filesystem package
# URL: https://crux.nu
# Maintainer: CRUX System Team, core-ports at crux dot nu

name=filesystem
version=3.8
release=3
source=(issue motd shells group passwd shadow securetty fstab mime.types)

build() {
    # Directory structure
    install -d $PKG/bin
    install -d $PKG/sbin
    install -d $PKG/boot
    install -d $PKG/dev
    install -d $PKG/dev/pts
    install -d $PKG/proc
    install -d $PKG/sys
    install -d $PKG/etc
    install -d $PKG/mnt
    install -d $PKG/run
    install -d $PKG/lib{,32}
    ln -s lib $PKG/lib64
    install -d $PKG/lib/modules
    install -d $PKG/opt
    install -d $PKG/opt/bin
    install -d $PKG/opt/sbin
    install -d $PKG/usr
    install -d $PKG/usr/{bin,include,lib{,32},sbin,share,src}
    ln -s lib $PKG/usr/lib64
    install -d -p $PKG/usr/share/man/man{1,2,3,4,5,6,7,8}
    ln -s ../var $PKG/usr/var
    install -d $PKG/var
    install -d $PKG/var/cache
    install -d $PKG/var/lib
    install -d $PKG/var/lib/pkg
    install -d $PKG/var/log
    install -d $PKG/var/log/old
    ln -s ../run/ $PKG/var/run
    install -d $PKG/var/spool
    install -d $PKG/var/ftp
    install -d $PKG/var/www
    install -d $PKG/var/empty
    ln -s spool/mail $PKG/var/mail
    install -d $PKG/home

    install -d -m 1777 $PKG/tmp
    install -d -m 0750 $PKG/root
    install -d -m 1777 $PKG/var/lock
    install -d -m 1777 $PKG/var/spool/mail
    install -d -m 1777 $PKG/var/tmp
    install -d -m 1777 $PKG/dev/shm

    # /dev
    mknod $PKG/dev/console c 5 1
    chmod 0600 $PKG/dev/console

    # /etc
    install -m 0644 issue $PKG/etc
    install -m 0644 motd $PKG/etc
    install -m 0644 shells $PKG/etc
    install -m 0644 group $PKG/etc
    install -m 0644 passwd $PKG/etc
    install -m 0640 shadow $PKG/etc
    install -m 0644 securetty $PKG/etc
    install -m 0644 fstab $PKG/etc
    install -m 0644 mime.types $PKG/etc
    ln -s ../proc/self/mounts $PKG/etc/mtab

    # /usr/bin/crux
    cat > $PKG/usr/bin/crux << EOF
#!/bin/sh

echo "CRUX version $version"

# End of file
EOF
    chmod 755 $PKG/usr/bin/crux

    # /etc/os-release
    cat > $PKG/etc/os-release << EOF
NAME=CRUX
VERSION_ID="$version"
ID=crux
PRETTY_NAME="CRUX"
HOME_URL="https://crux.nu"
DOCUMENTATION_URL="https://crux.nu/Main/Handbook$(echo $version | awk '{ gsub(/\./, "-", $1); print $1 }')"
BUG_REPORT_URL="https://crux.nu/bugs"
EOF
}
