65 lines
1.9 KiB
Bash
Executable File
65 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
#set -x
|
|
# Script para copiar ciertas carpetas de Skrapper
|
|
|
|
## Comprueba los parametros
|
|
if [ "$#" -lt 2 ]; then
|
|
printf "Uso: %s SOURCEDIR DESTDIR\n" "$(basename "$0")"
|
|
exit 0
|
|
else
|
|
readonly ORIGEN="$1"
|
|
readonly DESTINO="$2"
|
|
fi
|
|
|
|
# Comprueba que exista el directorio de origen
|
|
if [ ! -d "$1" ]; then
|
|
printf "El directorio %s no existe\n" "$1"
|
|
exit 0
|
|
fi
|
|
|
|
# Si no existe, crea el directorio de destino
|
|
if [ ! -d "$2" ]; then
|
|
mkdir -p "$2"
|
|
fi
|
|
|
|
# Colores
|
|
WHITE=$(tput setaf 7)
|
|
BLUE_BG=$(tput setab 4)
|
|
LIME_YELLOW=$(tput setaf 190)
|
|
NORMAL=$(tput sgr0)
|
|
BOLD=$(tput bold)
|
|
|
|
MEDIA="cover title screenshot"
|
|
readonly MEDIA
|
|
|
|
# Crea la carpeta de destino
|
|
mkdir -p "${DESTINO}"
|
|
|
|
# Procesa todas las carpetas
|
|
for ITEM in "${ORIGEN}"/*; do
|
|
# Obten el nombre del sistema y lo imprime en pantalla
|
|
SISTEMA=$(basename "${ITEM}")
|
|
printf "\n\n%s\n" "${BOLD}${WHITE}${BLUE_BG} ${SISTEMA} ${NORMAL}"
|
|
# Procesa la lista de carpetas
|
|
for CARPETA in $MEDIA; do
|
|
printf "\n%s\n" "${BOLD}${LIME_YELLOW}${CARPETA}${NORMAL}"
|
|
# Crea el directorio de destino donde copiarlo todo
|
|
mkdir -p "${DESTINO}/${SISTEMA}/${CARPETA}"
|
|
# Copia las imagenes
|
|
rsync -avh --delete --chmod=755 "${ITEM}"/"${CARPETA}/" "${DESTINO}/${SISTEMA}/${CARPETA}/"
|
|
# Copia el gamelist.xml
|
|
rsync -avh --delete --chmod=755 "${ITEM}"/gamelist.xml "${DESTINO}/${SISTEMA}/"
|
|
# Calcula el numero de subcarpetas
|
|
NUM_SUBCARPETAS=$(find "${DESTINO}/${SISTEMA}/${CARPETA}" -mindepth 1 -type d | wc -l)
|
|
# Si existen subcarpetas
|
|
if [ "$NUM_SUBCARPETAS" != 0 ]; then
|
|
# Busca todos los ficheros en la carpeta y subcarpeta y los mueve a la raíz
|
|
find "${DESTINO}/${SISTEMA}/${CARPETA}" -type f -exec mv {} "${DESTINO}/${SISTEMA}/${CARPETA}" \;
|
|
# Borra las subcarpetas
|
|
find "${DESTINO}/${SISTEMA}/${CARPETA}" -mindepth 1 -type d -exec rm -rdf {} \;
|
|
fi
|
|
# Cambia el propietario de los archivos
|
|
chown sergio:sergio "${DESTINO}/${SISTEMA}/${CARPETA}/"*
|
|
done
|
|
done
|