Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- which zenity > /dev/null
- if [ ! $? = 0 ]; then
- echo "Falta zenity para poder ejecutar el script" >> /tmp/error_env.txt
- xdg-open /tmp/error_env.txt
- exit
- fi
- # Creamos un archivo para manejar los archivos y evitar el error de espacios
- perl -e 'open(TXT,"> /tmp/file_s.txt");
- my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
- foreach (@files)
- {
- print TXT "$_\n";
- }
- close TXT;'
- function crear_seleccion() # Creamos un archivo con los dispositivos conectados
- {
- o=0
- df -h | tail -20 > /tmp/dis
- while read linea
- do
- if [[ $linea =~ ^\/.*sd.* ]] # Si alguno es sdx
- then
- RUTA=`awk '{ print $6;print $7;print $8;print $9 }' <<< $linea`
- RUTA=`echo $RUTA`
- if [[ $RUTA =~ ^\/[a-z] ]] # Y si no es root
- then
- if [[ `ls -al "$RUTA" | awk '{print $3}' | tail -1` != "root" ]]
- then
- DISP[$o]=$linea
- let o=o+1
- fi
- fi
- fi
- done < "/tmp/dis"
- }
- declare -a {DISP,RUTA,TAM,USED,DISC} # Creamos unos arrays para guardar los datos de cada disco
- crear_seleccion && rm /tmp/dis
- i=0 && o=0;
- if [ ${#DISP} -eq 0 ] # Si no hay dispositivo salimos
- then
- zenity --error --text="No hay discos disponibles"
- exit 1
- fi
- while [[ $i < ${#DISP[*]} ]] # Creamos nuestras rutas
- do
- RUTA[$o]=`awk '{ print $6;print $7;print $8}' <<< ${DISP[$i]}`
- DISC[$o]=`awk '{ print $1}' <<< ${DISP[$i]}`
- TAM[$o]=`awk '{ print $2}' <<< ${DISP[$i]}`
- USED[$o]=`awk '{ print $3}' <<< ${DISP[$i]}`
- let i=i+1 && let o=o+1
- done
- i=0;
- DISPOS=`while [[ $i < ${#DISP[*]} ]] # Seleccionamos un dispositivo
- do
- let i=i-1
- echo ${DISC[$i]}
- echo ${TAM[$i]}
- echo ${USED[$i]}
- done | zenity --list --title="Enviar a"\
- --text="Selecciona un dispositivo"\
- --column="Dispositivo" \
- --column="Tamaño" \
- --column="Usado"`
- DISPOS=`awk '{ print $1 }' <<< $DISPOS`; i=0
- while [[ $i < ${#DISP[*]} ]] # Buscamos el dispositivo
- do
- TEM=`awk '{ print $1 }' <<< ${DISP[i]}`
- if [[ $TEM = $DISPOS ]] # Cuando lo encontremos
- then
- RUTA=`echo ${RUTA[$i]}`
- PORCENT=`wc -l /tmp/file_s.txt`
- let PORCENT=$PORCENT/10
- while read files # Recorremos el archivo con las rutas de los archivos
- do
- echo "# $files"
- cp -R "$files" "$RUTA/" # Copiamos
- if [ $? -eq 1 ]
- then
- NOMBRE_N=`zenity --entry --title="Fichero repetido" \
- --text="Escribir un nuevo nombre"`
- if [ $? -eq 1 ]
- then
- next
- else
- cp -R "$files" "$RUTA/$NOMBRE_N"
- fi
- fi
- done < "/tmp/file_s.txt" | zenity --progress --title="Enviando" --pulsate # Emulamos el envio con un pipe
- break
- fi
- let i=i+1
- done
- rm /tmp/file_s.txt
- #This library is free software; you can redistribute it and/or modify it under
- #the terms of the GNU Library General Public License as published by the Free
- #Software Foundation; either version 2.1 of the License, or (at your option) any
- #later version.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement