#!/bin/sh
#
# mkpkglist - make a TeX package list for the manual
#

VERSION="1.0"

if [ "$1" = "-h" -o "$1" = "--help" ]; then
  echo "Usage: mkpkglist..."
  echo "Make a nice package list for the ROOT manual, using the"
  echo "file versions found in the present directory."
  echo
  echo " -h, --help		print this help and exit"
  echo " -v, --version		output version information and exit"
  echo
  echo "Report bugs to <johne@rootlinux.org>."
  exit
fi

if [ "$1" = "-v" -o "$1" = "--version" ]; then
  echo "mkpkglist $VERSION"
  exit
fi

if [ ! -d /usr/rl/rootlinux-unstable/i586/files/rl/pkgs/base ]; then
  echo "couldn't find package directories..."
  exit 1
fi

# Set a nice $FILE variable
#FILE=$PWD/`basename $1`

FILE=$PWD/packagelist.tex

echo >$FILE
cat << EOF >>$FILE
\begin{center}
\begin{longtable}{|l|l|l|l|}
EOF

echo "\hline" >>$FILE
echo "\textbf{Package} & \textbf{Version} & \textbf{Category} & \textbf{Size (B)} \\\\" >>$FILE

cd /usr/rl/rootlinux-unstable/i586/files/rl/pkgs/base
for i in base opt net mmedia gnbase gnopt kde x wmaker nonfree; do \
cd ../$i
for file in *.gz; do
A=`echo $file | cut -f2 -d\#`
B=`echo $A | cut -f1 -d\-`
N=`echo $file | cut -f1 -d\#`
M=`echo $N | wc -m`
S=`vdir $file | cut -f6 -d\ `

echo "\hline" >> $FILE
echo "$N & $B & $i & $S \\\\" >> $FILE
#echo "$B \\\\" >> $FILE

done
# lägg till nåt mellan kategorierna här?
done
echo "\hline" >> $FILE
cd ..

cat << EOF >>$FILE
\end{longtable}
\end{center}

EOF

sed s/"_"/"\\\_"/ -i $FILE

# EOF

