#!/usr/bin/env bash
# Created by Tobias Powalowski <tpowa@archlinux.org>

build ()
{
    map add_binary findssl.sh scp sftp ssh-add ssh-agent ssh-copy-id ssh-keygen ssh-keyscan sshd \
	  telnetd rsync exportfs nfsstat rpc.idmapd rpc.mountd rpc.nfsd rpc.statd rpcdebug showmount \
	  sm-notify start-statd rpcbind rpcinfo rpc.gssd mountstats \
	  nfsdcltrack nfsiostat gssproxy screen tmux
    map add_file "/etc/screenrc" "/etc/ssh/ssh_config" "/etc/ssh/sshd_config" "/etc/ssh/moduli" \
        "/etc/rsyncd.conf" "/etc/exports"  "/usr/lib/ssh/sftp-server" "/usr/lib/ssh/ssh-keysign" \
        "/usr/lib/ssh/ssh-pkcs11-helper" "/etc/conf.d/rpcbind" "/etc/gssapi_mech.conf" \
        "/etc/netconfig"
    add_file "/usr/share/archboot/remote/etc/ssh/sshd_config" "/etc/ssh/sshd_config"
    add_full_dir "/usr/lib/libnfsidmap/"
    map add_dir  "/var/empty" "/var/lib/nfs/sm" "/var/lib/nfs/sm.bak" "/var/lib/nfs/v4recovery" \
        "/var/lib/nfs/rpc_pipefs" "/var/lib/rpcbind" "/var/log/gssproxy"
    chmod 700 "$BUILDROOT/var/lib/rpcbind"
    chown 32:32 "$BUILDROOT/var/lib/rpcbind"
    map add_full_dir "/etc/gss" "/etc/gssproxy" "/var/lib/gssproxy"
    # start rpcbind on startup
    add_symlink "/etc/systemd/system/sockets.target.wants/rpcbind.socket" "/usr/lib/systemd/system/rpcbind.socket"
    add_dir "/var/lib/openldap"
    chmod 700 "$BUILDROOT/var/lib/openldap"
    chown 439:439 "$BUILDROOT/var/lib/openldap"
    # start sshd on startup
    add_symlink "/etc/systemd/system/multi-user.target.wants/sshd.service" "/usr/lib/systemd/system/sshd.service"
    # fix licenses
    map add_file "/usr/share/licenses/rpcbind/COPYING" "/usr/share/licenses/libsasl/COPYING" \
        "/usr/share/licenses/libldap/LICENSE" "/usr/share/licenses/nfsidmap/LICENSE" \
        "/usr/share/licenses/libgssglue/COPYING" "/usr/share/licenses/tmux/LICENSE"
}

help ()
{
cat<<HELPEOF
  This hook includes remote tools on an archboot image.
HELPEOF
}
