#!/bin/sh
# arreglar --install viene install
#echo slapt-get --install $@
#slapt-get --install $@


#usa pkgtools

for arg in "$@" 
do
      index=`expr $index + 1` 
      if test $index -gt 1 ; then
          # echo RRR $index $arg - $PAQS
          narg=`echo $arg| sed 's/^\"//'| sed 's/\"$//'`
          PAQS="$PAQS $narg"                 
      fi
done  

SLAPT="slapt-get --no-prompt "

TACCION=$1

ACCION=`echo $TACCION|awk -F'-' '{print $1}'`
ACCIONINFO=`echo $TACCION|awk -F'-' '{print $2}'`
EACCION=`echo $ACCIONINFO|awk -F'_' '{print $1}'`
E2ACCION=`echo $ACCIONINFO|awk -F'_' '{print $2}'`
echo Accion: $ACCION, Opciones: $ACCIONINFO Distro: SUSE
echo Paquetes: $PAQS

OS=`echo $EACTION |cut -b1`
OND=`echo $EACTION |cut -b2`
ONU=`echo $EACTION |cut -b3`
OF=`echo $EACTION |cut -b4`
OBD=`echo $EACTION |cut -b5`

if test "x$ACCION" = xinstall ; then
 if test "x$E2ACCION" = xdwld ; then
  echo  $SLAPT  --install --download-only $PAQS
  $SLAPT --install --download-only $PAQS
  exit
 fi

OPTS=

if test "x$OS" != x ; then
    echo

    # no se
    #echo $SLAPT source-install $PAQS
    #$SLAPT source-install $PAQS
    # ver -d buildeps -D nonbuilddeps
fi

if test "x$OND" != x ; then
    #nodeps
    echo No funciona todavia
    #echo rpm -i --nodeps $PAQS
    # falta ver que es $PAQS    
    #rpm -i --nodeps $PAQS
OPTS="$OPTS --no-dep"
    #--ignore-dep
    exit
 fi

if test "x$ONU" != x ; then
 OPTS="$OPTS --no-upgrade"
  
    exit
fi
if test  "x$OBD" != x ; then
     echo NO SE
    exit
fi
if test "x$OF" != x ; then
    OPTS="$OPTS --reinstall"
    exit
fi


echo  $SLAPT  --install $OPTS $PAQS
$SLAPT --install $OPTS $PAQS



elif test "x$ACCION" = xoriginalsourceinstall ; then
   echo esto lo maneja source.sh, mal llamado desde babel

elif test "x$ACCION" = xsearch ; then
  #if test "x$EACCION" = xnames -o "x$EACCION" = x ; then
     echo $SLAPT --search  $PAQS
     $SLAPT --search  $PAQS
  #elif test "x$EACCION" = xall ; then
  #   echo $SLAPT --search -d $PAQS
  #   $SLAPT search -d $PAQS
  #else
  #   echo error opcion $EACCION diferente a la habilitada con search
  #fi
elif test "x$ACCION" = xinfo  ; then
       #la opcion aca EACCION no parece servir
     echo $SLAPT --show $PAQS
     $SLAPT --show  $PAQS
elif test "x$ACCION" = xremove ; then
     echo $SLAPT --remove  $PAQS
     $SLAPT --remove  $PAQS
elif test "x$ACCION" = xspecialp ; then
echo $SLAPT --$ACCIONINFO $PAQS
    $SLAPT --$ACCIONINFO $PAQS
# fix clean specialnp delrepo refresh update distupdate
elif test "x$ACCION" = xspecialnp ; then
  echo $SLAPT --$ACCIONINFO 
  $SLAPT $ACCIONINFO 
elif test "x$ACCION" = xfix ; then
  echo
  # no se como
 # echo $SLAPT --fix-broken
 # $SLAPT --fix-broken
elif test "x$ACCION" = xclean ; then
echo $SLAPTCACHE --clean 
     $SLAPTCACHE --clean 
     # autoclean only obsolete packages
elif test "x$ACCION" = xdelrepo ; then
    echo No hecho todavia
elif test "x$ACCION" = xrefresh ; then
echo $SLAPT --update
    $SLAPT --update
elif test "x$ACCION" = xupdate ; then
echo  $SLAPT --upgrade
    $SLAPT --upgrade
elif test "x$ACCION" = xdistupdate ; then
    echo $SLAPT --dist-upgrade
    $SLAPT --dist-upgrade
elif test "x$ACCION" = xdepclean ; then
   echo $SLAPT --remove-obsolete  no es lo mismo
   #$SLAPT --remove-obsolete
elif test "x$ACCION" = xstats ; then
    echo $SLAPT --show-stats
    $SLAPT --show-stats
    echo no es lo mismo         Show the download statistics

elif test "x$ACCION" = xaddrepo ; then
     echo OJO poner lo del update en una llamad global al fnalde los repos en babel 
     #FILE=/etc/slapt-get/slapt-getrc
     #echo $1 >>$FILE
     #slapt-get --update

elif test "x$ACCION" = xINI ; then
######### PASAR A ROSETTA
#usar source.sh
VERSION=`cat /etc/slackware-version |awk -F' ' '{print $2}'| awk -F'.' '{print $1"."$2}'`
mkdir /tmp/instalar
cd /tmp/instalar
#wget http://curl.haxx.se/download/curl-7.19.7.tar.bz2
wget http://slackware.mirrors.tds.net/pub/slackware/slackware-$VERSION/slackware/n/curl-7.19.2-i486-1.tgz
wget http://slackware.mirrors.tds.net/pub/slackware/slackware-$VERSION/slackware/n/gnupg-1.4.9-i486-1.tgz
wget http://software.jaos.org/slackpacks/$VERSION/slapt-get-0.10.2b-i386-1.tgz
#wget http://slackware.mirrors.tds.net/pub/slackware/slackware-12.2/slackware/n/gpgme-1.1.6-i486-1.tgz
#installpkg gpgme-1.1.4-i486-1.tgz
#installpkg libassuan-1.0.1-i486-1.tgz
installpkg curl-7.19.2-i486-1.tgz
installpkg gnupg-1.4.9-i486-1.tgz
installpkg slapt-get-0.10.2b-i386-1.tgz
FILE=/etc/slapt-get/slapt-getrc
mv $FILE ./$FILE.vieja
DATOS=<<EOF
WORKINGDIR=/var/slapt-get
EXCLUDE=^aaa_elflibs,^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64
SOURCE=http://slackware.mirrors.tds.net/pub/slackware/slackware-$VERSION/
SOURCE=http://software.jaos.org/slackpacks/$VERSION/
EOF

echo $DATOS >$FILE
slapt-get --update

#tar -jxvf curl-7.19.7.tar.bz2
#cd curl-7.19.7
#configure --prefix=/usr  
#make 
#make install
#sudo no esta
## Working directory for local storage/cache.
## Exclude package names and expressions.
## To exclude pre and beta packages, add this to the exclude:
##   [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
#
##EXCLUDE=^kernel-.*,^alsa-.*,^glibc.*,.*-[0-9]+dl$,^devs$,^udev$,aaa_elflibs,x86_64
#
##SOURCE=http://slacky.uglyplace.org/repository/slackware-12.2/
#
#http://www.linuxquestions.org/questions/slackware-14/tex-live-in-slackware-635217/


########## PARA VERSIONES
#http://www.linuxpackages.net/mirrors.php
#ftp://slackware.mirrors.tds.net/pub/slackware/slackware-12.2/slackware/n/
#ftp://ftp.de-mirror.org/linuxpackages/Slackware-12.0-i386/jasorg/slapt-get/


else
 echo $SLAPT $ACCION $PAQS
  $SLAPT $ACCION $PAQS 
fi






#verify: sugiere
# no: locks

#otras acciones con otros scripts: update global, dup, addrepo fix clean
