#!/bin/sh -e
genclass=xfs
suffix=
inclass=xfs-tt
. ${JAILUP_CONF}

if  [ -z "${1}" ]; then
    ${cat} << EOF
#     Usage:
# jailup xfs-tt jailname jailaddr dir [port]
#     where dir relative to ${jailupdir} and ${jailrodir}
#     port is 7101 by default
# installed ports/x11/XFree86 used
EOF
    exit
fi

jailsname="${1}"
jailsaddr="${2}"
jdir="${3}"
port="${4:-7101}"
main_dir="${JAILUPDIR}/${jdir}"
umask 022

${mkdir} "${main_dir}"
${up_mdir} "${main_dir}" ${MTREE}
${up_data} "${main_dir}/etc" /etc << "EOF"
    /localtime
EOF

${up_shlib} "${main_dir}/usr/lib" << "EOF"
    c m stdc++
EOF

${up_libexe} "${main_dir}/usr/libexec" "${PREFIX}/libexec/apache" << EOF
    ld-elf.so.1
    xfstt
EOF

      #####################################
      ####                             ####
      #### Begin of etc fill           ####
      ####                             ####
if  [ ! -e "${main_dir}/etc/group" ]; then
    ${cat} << "EOF" > "${main_dir}/etc/group"
wheel:*:0:root
nogroup:*:65533:
nobody:*:65534:
xfs:*:7100:
EOF
fi

if  [ ! -e "${main_dir}/etc/master.passwd" ]; then
    ${cat} << "EOF" > "${main_dir}/etc/master.passwd"
root:*:0:0::0:0:Charlie &:/:/nonexistent
nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/nonexistent
xfs:*:7100:7100::0:0:X font server:/:/nonexistent
EOF
fi
      ####                             ####
      #### End of etc fill             ####
      ####                             ####
      #####################################

${pwd_mkdb} -d "${main_dir}/etc" -p "${main_dir}/etc/master.passwd"
${mtree} -Ueqxp "${main_dir}" -f ${MTREE}

${cat} << EOF >> "${genconfig}"
#${genclass}	${inclass}	${jdir}	${jailsname}		${jailsaddr}	${port}
EOF

      #####################################
      ####                             ####
      #### Begin of fstab mod          ####
      ####                             ####
${cat} << EOF >> "${etcdir}/fstab"
#/usr/X11R6/lib/X11/fonts/TrueType	${main_dir}/fonts	null	ro,nodev,noexec	0 0
EOF
      ####                             ####
      #### End of fstab mod            ####
      ####                             ####
      #####################################
