#!/bin/sh
# Author: Didier Spaier, Paris, France
#
# Before running this script, adapt MIRROR* and SLINTREPO below to your
# installation.
#
CWD=$(pwd)
SLACKVERSION="14.2"
SLINTVERSION="14.2"
usage() {
  printf %b "Usage: $0 32|64\n"
  exit
}
MIRROR=http://slackware.uk/salix
if [ $# -ne 1 ]; then usage; fi
if [ $1 -ne 32 ] && [ $1 -ne 64 ]; then usage; fi
if [ $1 -eq 32 ]; then
	MIRRORSALIX=/storage/salix/i486/$SLACKVERSION/salix
	MIRROREXTRA=$MIRROR/i486/extra-$SLACKVERSION
else
	MIRRORSALIX=/storage/salix/x86_64/$SLACKVERSION/salix
	MIRROREXTRA=$MIRROR/x86_64/extra-$SLACKVERSION
fi
SFX=$(echo $1|grep 64)
SLINTREPO=../../../../..
MIRRORSLACKWARE=/storage/slackware${SFX}-$SLACKVERSION
DATESTAMP=`date -u +%Y%m%d`
rm -rf pkg_lists/$1/$DATESTAMP
mkdir pkg_lists/$1/$DATESTAMP
(cd pkg_lists/$1/$DATESTAMP
wget $MIRROREXTRA/PACKAGES.TXT
mv PACKAGES.TXT PACKAGESExtra.txt
cp ../../replaced_packages replaced
for SERIES in a ap d e f k kde l n t tcl x xap xfce y; do
  for i in $(find $MIRRORSLACKWARE/slackware$SFX/$SERIES/ -name "*t?z"); do
	echo $i >> slackware
  done
done
for i in $(find $MIRRORSLACKWARE/slackware$SFX/kdei/ -name "*t?z"); do
  echo $i >> slackware_locales
done
for i in $(find $MIRRORSLACKWARE/extra/aspell-word-lists/ -name "*t?z"); do
  echo $i >> slackware_locales
done
for i in $(find $SLINTREPO/slint -name "*t?z"|grep -v installer); do
    echo $i >> slint
done
# Do not include the nosmp kernel headers that are in
# MIRRORSLACKWARE/patches/packages. They should not be installed.
for i in $(find $MIRRORSLACKWARE/patches/packages -name "*t?z"); do
    echo $i >> patches
done
sed /nosmp/d patches > patches2
mv patches2 patches
for i in $(<../../Salix); do
  find $MIRRORSALIX -name "${i}*t?z" >> salix
done
for i in $(<../../SalixLocales); do
  find $MIRRORSALIX -name "${i}*t?z" >> salix_locales
done
for i in $(<../../Extra); do
	sed -n "/PACKAGE NAME: *$i/{
		s/PACKAGE NAME: *//
		N
		s@\([^\n]*\)\nPACKAGE LOCATION: *.\(.*\)@\2/\1@p
		}" PACKAGESExtra.txt >> salix_extra
done
)
echo "All done."
