Advertisement
hackloper775

Enviar a Linux

Oct 16th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.31 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. which zenity > /dev/null
  4. if [ ! $? = 0 ]; then
  5.    echo "Falta zenity para poder ejecutar el script" >> /tmp/error_env.txt
  6.    xdg-open /tmp/error_env.txt
  7.    exit
  8. fi
  9.  
  10. # Creamos un archivo para manejar los archivos y evitar el error de espacios
  11.  
  12. perl -e 'open(TXT,"> /tmp/file_s.txt");
  13.        my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
  14.        foreach (@files)
  15.        {
  16.           print TXT "$_\n";
  17.        }
  18.        close TXT;'
  19.  
  20. function crear_seleccion() # Creamos un archivo con los dispositivos conectados
  21. {
  22.     o=0
  23.     df -h | tail -20 > /tmp/dis
  24.     while read linea
  25.     do
  26.         if [[ $linea =~ ^\/.*sd.* ]] # Si alguno es sdx
  27.         then
  28.             RUTA=`awk '{ print $6;print $7;print $8;print $9 }' <<< $linea`
  29.             RUTA=`echo $RUTA`
  30.             if [[ $RUTA  =~ ^\/[a-z] ]] # Y si no es root
  31.             then
  32.                 if [[ `ls -al "$RUTA" | awk '{print $3}' | tail -1` != "root" ]]
  33.                 then
  34.                     DISP[$o]=$linea
  35.                     let o=o+1
  36.                 fi
  37.             fi
  38.         fi
  39.     done < "/tmp/dis"
  40. }
  41.  
  42. declare -a {DISP,RUTA,TAM,USED,DISC} # Creamos unos arrays para guardar los datos de cada disco
  43.  
  44. crear_seleccion && rm /tmp/dis
  45.  
  46. i=0 && o=0;
  47.  
  48. if [ ${#DISP} -eq 0 ] # Si no hay dispositivo salimos
  49. then
  50.     zenity --error --text="No hay discos disponibles"
  51.     exit 1
  52. fi
  53.  
  54. while [[ $i < ${#DISP[*]} ]] # Creamos nuestras rutas
  55. do
  56.     RUTA[$o]=`awk '{ print $6;print $7;print $8}' <<< ${DISP[$i]}`
  57.     DISC[$o]=`awk '{ print $1}' <<< ${DISP[$i]}`
  58.     TAM[$o]=`awk '{ print $2}' <<< ${DISP[$i]}`
  59.     USED[$o]=`awk '{ print $3}' <<< ${DISP[$i]}`
  60.     let i=i+1 && let o=o+1
  61. done
  62.  
  63. i=0;
  64.  
  65. DISPOS=`while [[ $i < ${#DISP[*]} ]] # Seleccionamos un dispositivo
  66. do
  67.     let i=i-1
  68.     echo ${DISC[$i]}
  69.     echo ${TAM[$i]}
  70.     echo ${USED[$i]}
  71. done | zenity --list --title="Enviar a"\
  72.          --text="Selecciona un dispositivo"\
  73.          --column="Dispositivo" \
  74.          --column="Tamaño" \
  75.          --column="Usado"`
  76.  
  77. DISPOS=`awk '{ print $1 }' <<< $DISPOS`; i=0
  78.  
  79. while [[ $i < ${#DISP[*]} ]] # Buscamos el dispositivo
  80. do
  81.     TEM=`awk '{ print $1 }' <<< ${DISP[i]}`
  82.     if [[ $TEM = $DISPOS ]] # Cuando lo encontremos
  83.     then
  84.         RUTA=`echo ${RUTA[$i]}`
  85.         PORCENT=`wc -l /tmp/file_s.txt`
  86.         let PORCENT=$PORCENT/10
  87.         while read files # Recorremos el archivo con las rutas de los archivos
  88.         do
  89.             echo "# $files"
  90.             cp -R "$files" "$RUTA/" # Copiamos
  91.             if [ $? -eq 1 ]
  92.             then
  93.                 NOMBRE_N=`zenity --entry --title="Fichero repetido" \
  94.                 --text="Escribir un nuevo nombre"`
  95.                 if [ $? -eq 1 ]
  96.                 then
  97.                     next
  98.                 else
  99.                     cp -R "$files" "$RUTA/$NOMBRE_N"
  100.                 fi
  101.             fi
  102.         done < "/tmp/file_s.txt" | zenity --progress --title="Enviando" --pulsate # Emulamos el envio con un pipe
  103.        break
  104.     fi
  105.     let i=i+1
  106. done
  107.  
  108. rm /tmp/file_s.txt
  109.  
  110. #This library is free software; you can redistribute it and/or modify it under
  111. #the terms of the GNU Library General Public License as published by the Free
  112. #Software Foundation; either version 2.1 of the License, or (at your option) any
  113. #later version.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement