# Created by Tobias Powalowski <tpowa@archlinux.org>

install ()
{
    SCRIPT="arch_base"
    BINARIES="init agetty mount modprobe modinfo umount basename du clear env head id md5sum nano nc printf tail tee test tr tty uptime w who wc which whoami xargs yes syslog-ng syslog-ng-ctl loggen pdbtool update-patterndb bash swapon uniq cut seq snarf find sort fdisk sfdisk cfdisk parted gawk cp mv shutdown free ls rm sed test less chgrp chmod chown date df dialog dmesg egrep fgrep grep hostname kill killall killall5 more ps pwd rmdir stty sync tar touch uname vim lsmod modinfo rmmod hdparm true mktemp chroot dirname expr bzip2 hwclock depmod su cat cpio dd gzip wget top sdparm tput ifconfig ln losetup mkdir mkfifo mknod readlink echo gunzip zcat reset swapoff halt telinit awk dir reboot poweroff pidof nc lzcat lzcmp lzdiff lzegrep lzfgrep lzgrep lzless lzma lzmadec lzmore unlzma unxz xz xzcat xzdec switch_root false pivot_root sleep arch ctrlaltdel raw gdisk sgdisk findmnt swaplabel cal chkdupexe chrt col colcrt colrm column cytune ddate fallocate flock getopt hexdump i386 ionice ipcmk ipcrm ipcs isosize line linux32 linux64 look lscpu mcookie namei pg rename renice rev script scriptreplay setarch setsid setterm tailf taskset ul unshare uuidgen whereis write addpart delpart fdformat ldattach partx readprofile rtcwake tunelp uuidd sysctl pgrep pkill pmap pwdx skill slabtop
    snice tload vmstat watch"

    ### setting up base structure
    add_dir "/proc"
    add_dir "/sys"
    add_dir "/dev"
    add_dir "/mnt"
    add_dir "/media"
    add_dir "/tmp"
    add_dir "/tmp/install"
    add_dir "/var/run"
    add_dir "/var/lock"
    add_dir "/var/log"
    add_dir "/addons"
    add_dir "/home"
    add_device "/dev/null"    c 1 3
    add_device "/dev/zero"    c 1 5
    add_device "/dev/console" c 5 1
    add_device "/dev/mem"     c 1 1

    ### adding needed programs from running system
    add_file "${CONFIG}" "/config"

    add_file "/usr/share/terminfo/l/linux"
    add_file "/usr/share/archboot/base/init" "/init"
    add_file "/lib/initcpio/init_functions" "/init_functions"
    add_file "/etc/rc.d/functions"
    add_file "/etc/rc.d/syslog-ng"

    ### adding config files of installation system
    for i in $(find /usr/share/archboot/base/etc/* ! -type d); do
        add_file "$i" "$(echo $i | sed -e 's#/usr/share/archboot/base##g')"
    done

    ### fixing network support
    add_file "/lib/libnss_files.so.2"
    add_file "/lib/libnss_dns.so.2"

    ### add copy-mountpoint.sh
    add_file "/usr/bin/copy-mountpoint.sh"

    ### fix syslog-ng
    for i in /usr/lib/syslog-ng/*; do
      add_file "$i"
    done
    add_dir "/var/lib/syslog-ng/"
    add_dir "/etc/syslog-ng/patterndb.d"
    ### fix licenses
    add_file "/usr/share/licenses/bzip2/LICENSE"
    add_file "/usr/share/licenses/hdparm/LICENSE.TXT"
    add_file "/usr/share/licenses/ncurses/license.txt"
    add_file "/usr/share/licenses/pcre/LICENSE"
    add_file "/usr/share/licenses/shadow/COPYING"
    add_file "/usr/share/licenses/sdparm/LICENSE"
    add_file "/usr/share/licenses/vim/license.txt"
    add_file "/usr/share/licenses/zlib/LICENSE"
    add_file "/usr/share/licenses/iana-etc/LICENSE"
}

help ()
{
cat <<HELPEOF
  This hook sets up all initial directories and installs base
  klibc utilities and libraries for a arch boot image. 
  DO NOT remove this one unless you know what you're doing.
HELPEOF
}
