#!/bin/sh
#150813 fix paths to work in target.

[ ! -d diet ] && exit
[ ! -d bacon ] && exit

#150813
ROOTFSSKEL=''
[ -d ../woof-code/rootfs-skeleton/usr/share/doc ] && ROOTFSSKEL='../woof-code/rootfs-skeleton'
[ -d ../rootfs-skeleton/usr/share/doc ] && ROOTFSSKEL='../rootfs-skeleton'
[ "$ROOTFSSKEL" == "" ] && exit

TODAY="`date +%Y%m%d`"

echo "Creating ../../pup-tools-${TODAY}.tar.gz ..."

[ -d ../../pup-tools-${TODAY} ] && rm -rf ../../pup-tools-${TODAY}
mkdir ../../pup-tools-${TODAY}
[ -f ../../pup-tools-${TODAY}.tar.gz ] && rm -f ../../pup-tools-${TODAY}.tar.gz

cp -a bacon ../../pup-tools-${TODAY}/
cp -a diet ../../pup-tools-${TODAY}/
cp -a gcc ../../pup-tools-${TODAY}/

cp -a readme.txt ../../pup-tools-${TODAY}/

#some settings for the particular puplet:
echo
echo "You need a single word to describe the puplet. This will for example"
echo "appear in the 'welcome1stboot' window, in the title text, for example"
echo 'of Quirky: "This is the first time you are running Quirky!"'
echo 'Suggest, if uncertain, for most puplets, type "Puppy"'
echo -n "Type one-word to describe this puplet [Quirky]: "
read PUP_TOOLS_DISTRO_ONE_NAME
[ "$PUP_TOOLS_DISTRO_ONE_NAME" == "" ] && PUP_TOOLS_DISTRO_ONE_NAME='Quirky'
echo "PUP_TOOLS_DISTRO_ONE_NAME='${PUP_TOOLS_DISTRO_ONE_NAME}'" > CUSTOMIZE

for LOGOSIZE in 96 48
do
 echo
 echo "Choose the filename of a ${LOGOSIZE}x${LOGOSIZE} pixel logo that will be located at"
 echo "/usr/share/doc in the final build"
 PUPLOGOS="$(find ${ROOTFSSKEL}/usr/share/doc -mindepth 1 -maxdepth 1 -name "*${LOGOSIZE}.png" -o -name "*${LOGOSIZE}.jpg" -o -name "*${LOGOSIZE}.xpm" | rev | cut -f 1 -d '/' | rev)"
 if [ ! "$PUPLOGOS" ];then
  echo
  echo "Sorry, but there should be at least one image of the format *${LOGOSIZE}.png|jpg|xpm"
  echo "at ${ROOTFSSKEL}/usr/share/doc"
  echo "As nothing found, the logo in welcome1stboot and other apps cannot be"
  echo "customized. Continuing without customizing ${LOGOSIZE}x${LOGOSIZE} logo."
 else
  FIRSTLOGO="$(echo "$PUPLOGOS" | head -n 1)"
  echo
  echo "Choose a ${LOGOSIZE}x${LOGOSIZE} logo that will appear in welcome1stboot and other apps."
  CNT=1
  for ALOGO in `echo -n "$PUPLOGOS" | tr '\n' ' '`
  do
   echo "$CNT $ALOGO"
   CNT=`expr $CNT + 1`
  done
  echo -n "Please type a number from left column [1]: "
  read LOGONUM
  [ "$LOGONUM" == "" ] && LOGONUM=1
  [ $LOGONUM -gt $CNT ] && LOGONUM=1
  CHOSENLOGO="$(echo "$PUPLOGOS" | head -n "$LOGONUM" | tail -n 1)"
  echo "...ok, '${CHOSENLOGO}' chosen"
  echo "PUP_TOOLS_DISTRO_${LOGOSIZE}_LOGO='${CHOSENLOGO}'" >> CUSTOMIZE
 fi
done

cp -a CUSTOMIZE ../../pup-tools-${TODAY}/

sync
cd ..
cd ..
dir2tgz pup-tools-${TODAY}
sync
rm -rf pup-tools-${TODAY}


echo
echo "Done: ../../pup-tools-${TODAY}.tar.gz created."
