#!/bin/sh
# Install a package set into a jail
######################################################################

# Source our functions
PROGDIR="`pbreg get /PC-BSD/TheWarden/ProgDir`"

if [ -z "${PROGDIR}" ]
then
   echo "PROGDIR unset! Is The Warden installed properly?"
   exit 155
fi

# Source our variables
. ${PROGDIR}/conf/warden.conf

IP="$1"

if [ -z "${IP}" ]
then
  echo "ERROR: No jail specified to view packages in!"
  exit 5
fi

if [ -z "${JDIR}" ]
then
  echo "ERROR: JDIR is unset!!!!"
  exit 5
fi

if [ ! -d "${JDIR}/${IP}" ]
then
  echo "ERROR: No jail located at $JDIR/$IP"
  exit 5
fi


# Done with error checking, now lets get a package listing
###################################################################

# Create our chroot script

echo "#!/bin/sh
pkg_info 

if [ -d \"/etc/inmates\" ]
then
  echo -e '\nInmate Packages:'
  cd /etc/inmates
  for i in \`ls -d *\`
  do
    if [ -e \"\${i}/inmate-name\" ]
    then
      echo "\${i}"
    fi
  done
fi
" > "${JDIR}/${IP}/.chroot.sh"
chmod 755 ${JDIR}/${IP}/.chroot.sh
chroot "${JDIR}/${IP}" /.chroot.sh
rm ${JDIR}/${IP}/.chroot.sh
