#!/bin/sh -e
# Copyright @BABOLO (C)2002,2003
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id: up,v 1.5 2003/01/16 00:38:22 babolo Exp $
genclass=xfs
suffix=
inclass=xfs-4
. ${JAILUP_CONF}

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

jdir="${1}"
jailsname="${2}"
jailsaddr="${3}"
juid="${4-0}"
jgid="${5-0}"
port="${6:-7100}"
main_dir="${JAILUPDIR}/${jdir}"
conf_dir="${JAILRODIR}/${jdir}"
umask 022

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

${touch} "${main_dir}/var/run/err"

${up_shlib} "${main_dir}/usr/lib" << "EOF"
    c m z Xfont
EOF

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

      #####################################
      ####                             ####
      #### Begin of xfs.conf           ####
      ####                             ####
if  [ ! -e "${conf_dir}/xfs.conf" ]; then
    ${cp} "${TEMPLATE}" "${conf_dir}/${genclass}.conf"
fi
      ####                             ####
      #### End of xfs.conf             ####
      ####                             ####
      #####################################

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

if  [ ! -e "${conf_dir}/master.passwd" ]; then
    ${cat} << "EOF" > "${conf_dir}/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             ####
      ####                             ####
      #####################################

${mtree} -Ueqxp "${main_dir}" -f ${MTREE}
${mtree} -Ueqxp "${conf_dir}" << "EOF"
/set type=dir uname=root gname=wheel mode=0755 flags=none
.
/set type=file mode=0644
    localtime
    group
    master.passwd		mode=0600
    xfs.conf
EOF

${pwd_mkdb} -d "${conf_dir}" -p "${conf_dir}/master.passwd"

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

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