#hacer tambien txz
ARGUME=$PKGNAME






make_doinst(){
#echo JJJJJJJJJJJJJ
        DOINST=doinst.sh

# esto es un archivo para mover links simbolicos
# Get rid of possible pre-existing trouble:
TMP_DIR=/tmp
INST=$(mktemp $TMP_DIR/pkginfo.XXXXXX)
echo Temp file: $INST

# | cut -b3-

echo "Searching for symbolic links:"
# This requires the ls from coreutils-5.0 (or newer):
$(cd  $UPACKDROOT; find  -type l -exec ls -l --time-style=long-iso {} \; | while read foo ; do echo $foo ; done | cut -f 8- -d ' '| sed 's/^\.\///' | tee $INST)
if [ ! "$(cat $INST)" = "" ]; then
  echo
  echo "Making symbolic link creation script:"
  make_install_script $INST | tee $TMP_DIR/$DOINST
fi

echo "Updating/creating your package $TMP_DIR/$DOINST"
#not prepending

if test -s  $TMP_DIR/$DOINST; then
  cat $TMP_DIR/$DOINST >> $UPACKDROOT/install/$DOINST
fi



# esta tambien la chance de ponerlo antes
# touch install/doinst.sh
# mv install/doinst.sh install/doinst.sh.shipped
# cat doinst.sh > install/doinst.sh
# echo "" >> install/doinst.sh
# cat install/doinst.sh.shipped >> install/doinst.sh
# rm -f install/doinst.sh.shipped

echo "Removing symbolic links:"
find  $UPACKDROOT -type l -exec rm -v {} \;

# ver que borra
#rm -f $TMP_DIR/doinst.sh $INST


#if [ ! "$(cat $INST)" = "" ]; then
#  if [ -r install/doinst.sh ]; then
#    echo "Unless your existing installation script already contains the code"
#    echo "to create these links, you should append these lines to your existing#"
#    echo "install script. Now's your chance. :^)"
#    echo
#    echo "Would you like to add this stuff to the existing install script and"
#    echo -n "remove the symbolic links ([y]es, [n]o)? "
#  else
#    echo "It is recommended that you make these lines your new installation script."
#    echo
#    echo "Would you like to make this stuff the install script for this package"
#    echo -n "and remove the symbolic links ([y]es, [n]o)? "
#  fi
#  if [ ! "$LINKADD" ]; then
#    read LINKADD;
#    echo
#  else
#    echo $LINKADD
#    echo
#  fi
#  if [ "$LINKADD" = "y" ]; then
#    if [ -r install/doinst.sh ]; then
#      UPDATE="t"
#      if [ "$PREPEND" = "y" ]; then
#        touch install/doinst.sh
#        mv install/doinst.sh install/doinst.sh.shipped
#        cat doinst.sh > install/doinst.sh
#        echo "" >> install/doinst.sh
#        cat install/doinst.sh.shipped >> install/doinst.sh
#        rm -f install/doinst.sh.shipped
#      else
#        cat doinst.sh >> install/doinst.sh
#      fi
#    else
#      mkdir -p install
#      cat doinst.sh > install/doinst.sh
 #   fi
#    echo
#    echo "Removing symbolic links:"
#    find . -type l -exec rm -v {} \;
#    echo
#    if [ "$UPDATE" = "t" ]; then
#      if [ "$PREPEND" = "y" ]; then
#        echo "Updating your ./install/doinst.sh (prepending symlinks)..."
#      else
#        echo "Updating your ./install/doinst.sh..."
#      fi
#    else
#      echo "Creating your new ./install/doinst.sh..."
#    fi
#  fi
#else
#  echo "No symbolic links were found, so we won't make an installation script."
#  echo "You can make your own later in ./install/doinst.sh and rebuild the"
#  echo "package if you like."
#fi




}
make_install_script() {
echo -n "KK $1"  > JJJJJ
  COUNT=1
  LINE="$(sed -n "$COUNT p" $1)"
  while [ ! "$LINE" = "" ]; do
   LINKGOESIN="$(echo "$LINE" | cut -f 1 -d " ")" 
   LINKGOESIN="$(dirname $LINKGOESIN)" 
   LINKNAMEIS="$(echo "$LINE" | cut -f 1 -d ' ')"
   LINKNAMEIS="$(basename "$LINKNAMEIS")"
   LINKPOINTSTO="$(echo "$LINE" | cut -f 3 -d ' ')"

echo $1 - $LINE - $LINKGOESIN - $LINKNAMEIS >> JJJJJ
   echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )"
   echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )"
   COUNT=$(expr $COUNT + 1)
   LINE="$(sed -n "$COUNT p" $1)"
  done
}

build_slack(){

mkdir -p $UPACKDROOT/install
FILE=$UPACKDROOT/install/slack-desc

CHA=$(echo -n "$PACKAGE" | wc -m)
if [ $CHA -gt "40" ]; then
	echo "Name too long, please change it"
	exit 1
fi

MAX_COL=77
MAX_ROW=6
# limit the columns 
COL=$[$MAX_COL-$CHA]

NCOLSS=`echo  "$PACKAGE ($SUMMARY)" | wc -c`
if test 0$NCOLSS -ge 0$COL; then
       echo SUMMARY muy grande: $NCOLSS, achicar a $COL.
       exit 1
fi

# limit description for slack-desc
# Set the max row for description 
ROW=$(echo $DESCRIPTION | fmt -w $COL | sed -e "s/^/$PACKAGE: &/ " | wc -l)
if [ $ROW -gt "$MAX_ROW" ]; then
	ROW=$MAX_ROW
        echo "La DESCRIPTION es muy larga, tiene $ROW filas, no debe superar $MAX_ROW"
        exit 1;
fi
MAX=$[$MAX_ROW-$ROW]


#build slack-desc
NUM=0
SPACE=$(echo "$ARGUME" | sed -e "s/./ /g")
RULER="|----hardy-ruler----"
N_RULER=$(echo -n "$RULER" | wc -m)

while [ $N_RULER -lt $[$COL+1] ]; do
	LINE=$LINE$(echo -n "-")
	N_RULER=$[N_RULER+1]
done

# slack-desk header	
cat > $FILE <<END
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|' 
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also customary
# to leave one space after the ':'.

$SPACE$RULER$LINE|
END

# Adding package-name and short description to file, (all in one line) 
echo "$ARGUME ($ARGUME)" | fmt -w $COL | sed -n -e "1,1s/^/$ARGUME: &/p " >> $FILE
# Adding a empty row
echo $ARGUME: >> $FILE
# Adding the description in max 7 rows
echo $ARGUME | fmt -w $COL | sed -n -e "1,7s/^/$ARGUME: &/p " >> $FILE
# Adding a empty row before homepage
echo $ARGUME: >> $FILE
# Adding homepage
echo "$ARGUME: (none)" >> $FILE
echo "$ARGUME: Packaged by: none" >> $FILE
# If the rows are minus than 11, add the remaining (empty)
while [ $NUM -lt $MAX ]; do
	echo "$ARGUME:" >> $FILE
	NUM=$[NUM+1]
done



}



# ifexists INFO
#si no existe
#        build_slack
#        make_doinst
        
#	tar -C ${UPACKDROOT} -czf  ${ARGUME}.tgz .




INSTALL=install
DOINST=doinst.sh
#mkdir -p $UPACKDROOT/$INSTALL 
#FILESLACK=$UPACKDROOT/$INSTALL/slack-desc
mkdir -p $TMP_DIR/$INSTALL 
FILESLACK=$TMP_DIR/$INSTALL/slack-desc



#LINKS

make_install_script() {
  COUNT=1
  LINE="$(sed -n "$COUNT p" $1)"
  while [ ! "$LINE" = "" ]; do
   LINKGOESIN="$(echo "$LINE" | cut -f 1 -d " ")" 
   LINKGOESIN="$(dirname $LINKGOESIN)" 
   LINKNAMEIS="$(echo "$LINE" | cut -f 1 -d ' ')"
   LINKNAMEIS="$(basename "$LINKNAMEIS")"
   LINKPOINTSTO="$(echo "$LINE" | cut -f 3 -d ' ')"
   echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )"
   echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )"
   COUNT=$(expr $COUNT + 1)
   LINE="$(sed -n "$COUNT p" $1)"
  done
}

# ver donde crea doinst, etc



# esto es un archivo para mover links simbolicos
# Get rid of possible pre-existing trouble:
INST=$(mktemp $TMP_DIR/pkginfo.XXXXXX)
echo Temp file: $INST


echo "Searching for symbolic links:"
# This requires the ls from coreutils-5.0 (or newer):
find  $UPACKDROOT -type l -exec ls -l --time-style=long-iso {} \; | while read foo ; do echo $foo ; done | cut -f 8- -d ' ' | cut -b3- | tee $INST
if [ ! "$(cat $INST)" = "" ]; then
  echo
  echo "Making symbolic link creation script:"
  make_install_script $INST | tee $TMP_DIR/$DOINST
fi

echo "Updating/creating your package ./install/doinst.sh..."
#not prepending

if test -s  $TMP_DIR/$DOINST; then
  cat $TMP_DIR/$DOINST >> $UPACKDROOT/$INSTALL/$DOINST
fi



# esta tambien la chance de ponerlo antes
# touch install/doinst.sh
# mv install/doinst.sh install/doinst.sh.shipped
# cat doinst.sh > install/doinst.sh
# echo "" >> install/doinst.sh
# cat install/doinst.sh.shipped >> install/doinst.sh
# rm -f install/doinst.sh.shipped

echo "Removing symbolic links:"
find  $UPACKDROOT -type l -exec rm -v {} \;

# ver que borra
#rm -f $TMP_DIR/doinst.sh $INST


#if [ ! "$(cat $INST)" = "" ]; then
#  if [ -r install/doinst.sh ]; then
#    echo "Unless your existing installation script already contains the code"
#    echo "to create these links, you should append these lines to your existing#"
#    echo "install script. Now's your chance. :^)"
#    echo
#    echo "Would you like to add this stuff to the existing install script and"
#    echo -n "remove the symbolic links ([y]es, [n]o)? "
#  else
#    echo "It is recommended that you make these lines your new installation script."
#    echo
#    echo "Would you like to make this stuff the install script for this package"
#    echo -n "and remove the symbolic links ([y]es, [n]o)? "
#  fi
#  if [ ! "$LINKADD" ]; then
#    read LINKADD;
#    echo
#  else
#    echo $LINKADD
#    echo
#  fi
#  if [ "$LINKADD" = "y" ]; then
#    if [ -r install/doinst.sh ]; then
#      UPDATE="t"
#      if [ "$PREPEND" = "y" ]; then
#        touch install/doinst.sh
#        mv install/doinst.sh install/doinst.sh.shipped
#        cat doinst.sh > install/doinst.sh
#        echo "" >> install/doinst.sh
#        cat install/doinst.sh.shipped >> install/doinst.sh
#        rm -f install/doinst.sh.shipped
#      else
#        cat doinst.sh >> install/doinst.sh
#      fi
#    else
#      mkdir -p install
#      cat doinst.sh > install/doinst.sh
 #   fi
#    echo
#    echo "Removing symbolic links:"
#    find . -type l -exec rm -v {} \;
#    echo
#    if [ "$UPDATE" = "t" ]; then
#      if [ "$PREPEND" = "y" ]; then
#        echo "Updating your ./install/doinst.sh (prepending symlinks)..."
#      else
#        echo "Updating your ./install/doinst.sh..."
#      fi
#    else
#      echo "Creating your new ./install/doinst.sh..."
#    fi
#  fi
#else
#  echo "No symbolic links were found, so we won't make an installation script."
#  echo "You can make your own later in ./install/doinst.sh and rebuild the"
#  echo "package if you like."
#fi








#    * A    :    Basic Linux System
#    * AP   :    Applications that don't need X
#    * D    :    Development tools and utilities
#    * E    :    Emacs
#    * F    :    FAQs and HOWTOs
#    * GNOME:    The GNOME desktop and GTK+
#    * KDE  :    The K Desktop Environment and Qt
#    * KDEI :    KDE international packages
#    * L    :    Various libraries, including GLIBC
#    * N    :    Network programs, utilities, servers, and clients
#    * T    :    teTeX, LaTeX, and related typesetting software
#    * TCL  :    TCL and Tk
#    * X    :    Base X Window system
#    * XAP  :    X Window system applications and window managers
#    * Y    :    BSD games


brand=slack

if test x$brand = "xslack"; then 
    PKG_GROUP=$PKG_DISKSET_SLACK
#    PKGTYPE="txz"
fi
if test "x$PKG_GROUP" = "x"; then 
     PKG_GROUP="nose"                 
fi
echo PKGTYPE $PKGTYPE
echo PKG_GROUP $PKG_GROUP


#echo "$PACKAGE: $SUMARY"
#echo "$PACKAGE: "
#echo -e "$PACKAGE: $DESCRIPTION"
#echo "$PACKAGE: ($URL)"
#echo "$PACKAGE:  Packaged by: $MAINTAINER" "

#http://www.slacky.eu/wikislack/index.php?title=Crea_file_slack-desc
#    *  Data 16/03/2009
#    * Autore Naitso
#    * Thanks to Marco Pessotto a.k.a. melmothX 


# Set file name


CHA=$(echo -n "$PACKAGE" | wc -m)
if [ $CHA -gt "40" ]; then
	echo "Name too long, please change it"
	exit 1
fi

MAX_COL=77
MAX_ROW=6
# limit the columns 
COL=$[$MAX_COL-$CHA]

NCOLSS=`echo  "$PACKAGE ($SUMMARY)" | wc -c`
if test 0$NCOLSS -ge 0$COL; then
       echo SUMMARY muy grande: $NCOLSS, achicar a $COL.
       exit 1
fi

# limit description for slack-desc
# Set the max row for description 
ROW=$(echo $DESCRIPTION | fmt -w $COL | sed -e "s/^/$PACKAGE: &/ " | wc -l)
if [ $ROW -gt "$MAX_ROW" ]; then
	ROW=$MAX_ROW
        echo "La DESCRIPTION es muy larga, tiene $ROW filas, no debe superar $MAX_ROW"
        exit 1;
fi
MAX=$[$MAX_ROW-$ROW]



FILE=$FILESLACK

#build slack-desc
NUM=0
SPACE=$(echo "$PACKAGE" | sed -e "s/./ /g")
RULER="|----hardy-ruler----"
N_RULER=$(echo -n "$RULER" | wc -m)

while [ $N_RULER -lt $[$COL+1] ]; do
	LINE=$LINE$(echo -n "-")
	N_RULER=$[N_RULER+1]
done

# slack-desk header	
cat > $FILE <<END
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|' 
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also customary
# to leave one space after the ':'.

$SPACE$RULER$LINE|
END

# Adding package-name and short description to file, (all in one line) 
echo "$PACKAGE ($SUMMARY)" | fmt -w $COL | sed -n -e "1,1s/^/$PACKAGE: &/p " >> $FILE
# Adding a empty row
echo $PACKAGE: >> $FILE
# Adding the description in max 7 rows
echo $DESCRIPTION | fmt -w $COL | sed -n -e "1,7s/^/$PACKAGE: &/p " >> $FILE
# Adding a empty row before homepage
echo $PACKAGE: >> $FILE
# Adding homepage
echo "$PACKAGE: ($PRIMARYSITE)" >> $FILE
echo "$PACKAGE: Packaged by: $MAINTAINER" >> $FILE
# If the rows are minus than 11, add the remaining (empty)
while [ $NUM -lt $MAX ]; do
	echo "$PACKAGE:" >> $FILE
	NUM=$[NUM+1]
done
#cat $FILE

#gzip those man pages

#gzip info pages, remove the /usr/info/dir file if it is there. This is the main index file for the info system and you should not replace it. If you want to add to it see the doinst howto on this site for instructions on using the info system to add the new info file. 

#After receiving emails about the build scripts we decided to add this part. Since at this time there is no standard location for these we have asked many in the community and came up with install build script to /usr/src/slackbuilds. If you have a build script that you use to create your package include it in the package. The location to place the file is /usr/src/slackbuilds/packagename.

#/install/slack-required (this is optional see below)
# /install/slack-conflicts (this is optional see below)
# /install/slack-suggests (this is optional see below)
# /usr/doc/package-version/ 
#slack-required:
#The structure of this file is one entry per line in the following format:
#package_name
#or
#[package_name] [condition] [version]
#where [condition] is
#=, >=, =<, <, or >
#<= and =< should both work, just in case of editing errors.
#example
#man >= 1.5l-i386-1
#Notice that we have included the version arch and build number this will help with version checking. Don't worry th#e condition statement takes care of things if there is a newer version available.#

#slack-conflicts:
#The format of this file is just simply the same as the slack-required file. Follow the above format for this file.

#slack-suggests:
#The format of this file is simply the program name nothing more:
#gnome-spell












# ifexists INFO
#si no existe
        build_slack
        make_doinst
        
	tar -C ${UPACKDROOT} -czf  ${PKGNAME} .
