#!/bin/sh 

. config.sh
if [ "${CHAIN}" = "Y" ]; then
  printf "\033[1;36m5.last_tuning.sh\033[0m\n"
fi
  

cd ${JAIL_DIR}

if [ "${RELEASE}" = "5" ]; then
  KERNEL_PATH="${JAIL_DIR}/boot/kernel/"
else
  KERNEL_PATH="${JAIL_DIR}/"
fi

echo -n "Stripping and compressing kernel with gzip... " && /usr/bin/tput ch 54
if [ -f "${KERNEL_PATH}kernel.gz" ]; then 
  chflags noschg ${KERNEL_PATH}kernel.gz
  rm -f ${KERNEL_PATH}kernel.gz
fi
chflags noschg ${KERNEL_PATH}kernel
strip ${KERNEL_PATH}kernel
gzip -9 ${KERNEL_PATH}kernel
chflags schg ${KERNEL_PATH}kernel.gz

printf "\033[1;36m[OK]\033[0m\n"

echo -n "Removing unuseful directories... " && /usr/bin/tput ch 54
rm -rf ${JAIL_DIR}/usr/share/zoneinfo
rm -rf ${JAIL_DIR}/usr/share/games
rm -rf ${JAIL_DIR}/usr/share/sendmail
rm -rf ${JAIL_DIR}/usr/share/info
rm -rf ${JAIL_DIR}/usr/share/examples
rm -rf ${JAIL_DIR}/usr/share/isdn
rm -rf ${JAIL_DIR}/usr/share/man
rm -rf ${JAIL_DIR}/usr/share/doc
rm -rf ${JAIL_DIR}/usr/share/calendar
rm -rf ${JAIL_DIR}/usr/share/mk
rm -rf ${JAIL_DIR}/usr/share/me
rm -rf ${JAIL_DIR}/usr/share/nls
rm -rf ${JAIL_DIR}/usr/share/tmac
rm -rf ${JAIL_DIR}/usr/share/tabset
rm -rf ${JAIL_DIR}/usr/share/groff_font
rm -rf ${JAIL_DIR}/usr/share/dict
rm -rf ${JAIL_DIR}/usr/share/locale
rm -rf ${JAIL_DIR}/usr/share/syscons
rm -rf ${JAIL_DIR}/usr/share/skel
rm -rf ${JAIL_DIR}/usr/share/pcvt

printf "\033[1;36m[OK]\033[0m\n"

cd ${START_PATH}
if [ "${CHAIN}" = "Y" ]; then
  sh 6.create_img.sh
fi
