#!/bin/sh

#####instala yum-downloadonly



#yum install yum-fastestmirror
#yum install yum-security
#yum --security update
#yum install yum-presto
#yum --skip-broken update
#yum install yum-skipbroken
#yum install yum-versionlock
#keepcache=1.
#yum install yum-utils
#yumdownloader --source packagename
#yumdownloader --resolve packagename
#yumdownloader --resolve packagename --root /path/to/chroot
#yum clean all

#echo yum -y $@
#yum -y $@
#http://blog.kagesenshi.org/2008/04/12-yum-tips-and-tricks.html

YUM="yum -y "
#yumdownloader
#yum uses rpm

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



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
   # --downloadonly : don't update, just download a rpm file
   # --downloaddir=/path/to/dir : specifies an alternate directory to store packages such as /tmp
  #hacer esto una sola vez, instala un plugin
  echo install yum-downloadonly
  $YUM install yum-downloadonly
  echo  $YUM install  --download-only $PAQS
  $YUM install  --download-only $PAQS
  exit
 fi


OPTS=


if test "x$OS" != x ; then
    echo yumdownloader --source  $PAQS
    yumdownloader --source $PAQS
    # ver -d buildeps -D nonbuilddeps
fi

if test  "x$OND" != x  ; then
    #nodeps
    echo No funciona todavia
    #echo propuesta "$YUM install  --download-only $PAQS; rpm --install --nopeds $PAQS "
    #echo rpm -i --nodeps $PAQS
    # falta ver que es $PAQS    
    #rpm -i --nodeps $PAQS

    #
    exit
 fi

if test "x$ONU" != x ; then
    echo NO SE
    exit
fi
if test  "x$OBD" != x ; then
       echo NO SE
    exit
fi
if test "x$OF" != x ; then
   echo $YUM reinstall   $PAQS;
    $YUM reinstall   $PAQS;
    exit
fi

echo $YUM install   $PAQS;
$YUM install   $PAQS;
    


elif test "x$ACCION" = xsearch ; then
       # las opciones no parecen poder estructurarse aqui
     echo $YUM search  $PAQS
     $YUM search  $PAQS

elif test "x$ACCION" = xinfo  ; then
       #la opcion aca EACCION no parece servir
     echo $YUM info  $PAQS
     $YUM info  $PAQS
     #list
elif test "x$ACCION" = xremove ; then
     echo $YUM erase  $PAQS
     $YUM erase  $PAQS
elif test "x$ACCION" = xspecial ; then
echo $YUM $ACCIONINFO $PAQS
    $YUM $ACCIONINFO $PAQS

elif test "x$ACCION" = xfix; then
   echo No se  
elif test "x$ACCION" = xdepclean; then
   echo No se 
elif test "x$ACCION" = xclean ; then
      echo $YUM clean 
     $YUM clean 
     #apt-cache autoclean only obsolete
elif test "x$ACCION" = xdelrepo ; then
    echo No hecho todavia
elif test "x$ACCION" = xrefresh ; then
    echo $YUM  check-update
    $YUM  check-update
elif test "x$ACCION" = xupdate ; then
    $YUM update
elif test "x$ACCION" = xdistupdate ; then
    $YUM upgrade
elif test "x$ACCION" = xdepclean ; then
echo     NO se
elif test "x$ACCION" = xstats ; then
    echo No se como
elif test "x$ACCION" = xaddrepo ; then
    echo No se
else
 echo $YUM $ACCION $PAQS
  $YUM $ACCION $PAQS 
fi




