@Metal_Warrior:
Hm joa, so könnte man es auch machen, aber das wäre unnötige "Duplikation" der Daten...... ansonsten aber eigentlich eine schöne Idee.
----
Ich hab mal was gebastelt..... zumindest die Ordnerstrukturen werden "geklont"
Aber nagelt mich nicht auf das Skript fest, das ist mein Zweitlingswerk
Und Haftung für Schäden werden nicht übernommen, aber es wird auch noch nichts entpackt.... schaue ich mir morgen früh mal an.
Und ja, der Quellordner muss die Daten in einem Unterordner haben, damit das Teil richtig "anspringt" - irgendwie hab ich das noch nicht anders lösen können, weil er sonst mit "mkdir" verucht das Hauptverzeichniss beim ersten "crawlen" anzulegen in dem Zielordner.... nicht sonderlich schön, aber nu.
Update:
Alte Version entfernt, da nicht wirklich tauglich, dafür lüppt diese Variante um so besser
Allerdings werden nur Ordnerstrukturen angelegt, Dateibehandlung ist auf dem Schirm.
Update2:
Neue Version, alten Code entfernt... damit lüppt es nun.... auch mit dem entpacken
[src=bash]#!/bin/bash
#
# The code is provided as is.
#
# Author: theSplit, 2017
#
# Description:
# Mirrors the folder structure from source to target folder and extracting
# found zip archives in those folders, unpacking any packed packed zips using "unzip" tool
#
# Usage:
# bash scriptname.sh /folder1/src /folder2/target
#
#
#
# Minor options
# Verbosity level 0 no verbose, 1 some, 2 extra info
BEVERBOSE=1
# If set to 1 do nothing the app just gives output if verbose, otherwise no actions are taken
DONOTHING=0
#---------------------------------------------------------------------------------------------------------------------------------
echo "Starting..."
# Stop editing here
FOLDERCOUNT=-1
SUBLEVEL=0
declare -a SUBPATHS
shopt -s dotglob
shopt -s nullglob
#---------------------------------------------------------------------------------------------------------------------------------
#
function unpackFile {
cd $1
if [[ $BEVERBOSE -gt 0 ]]; then
echo "Unpacking '$3' to '$2'"
fi
if [[ ! -f $3 ]]; then
return
fi
unzip -qu $3 -d "$2"
if [[ $5 -ne 0 ]]; then
EXTRAPACKED=(*.$4)
while [[ ! -z $EXTRAPACKED ]]; do
unpackSubPacks $2 $4
cd $2
EXTRAPACKED=(*.$4)
done
fi
cd $1
}
function unpackSubPacks {
cd $1
EXTRAPACKED=(*.$2)
for UNPACKEDARCHIVE in ${EXTRAPACKED[@]}
do
unpackFile $1 $1 $UNPACKEDARCHIVE $2 0
rm $UNPACKEDARCHIVE
done
}
function mirrorPathes {
FOLDERCOUNT=$(($FOLDERCOUNT+1))
#-------------------------------------------------------------------------------------------------------------------------------
# Navigate into src dir order
cd $DESTDIR
for SUBDIRECTORY in ${SUBPATHS[@]}
do
if [[ DONOTHING -ne 1 ]]; then
if [[ ! -d $SUBDIRECTORY ]]; then
$(mkdir $SUBDIRECTORY)
fi
cd $SUBDIRECTORY
fi
done
TARGETPATH=$PWD
cd $SRCDIR
for SUBDIRECTORY in ${SUBPATHS[@]}
do
cd $SUBDIRECTORY
done
SOURCEPATH=$PWD
FILESINPATH=(*.zip)
if [[ $DONOTHING -eq 0 ]]; then
for FILE in ${FILESINPATH[@]}
do
if [[ $BEVERBOSE -gt 0 ]]; then
echo "SOURCE: $SOURCEPATH"
echo "TARGET: $TARGETPATH"
echo "FILE: $FILE";
fi
unpackFile "$SOURCEPATH" "$TARGETPATH" "$FILE" zip 1
done
fi
#-------------------------------------------------------------------------------------------------------------------------------
# Some output if present
if [[ BEVERBOSE -gt 1 ]]; then
echo "CURRENT DIRECTORY: $PWD"
fi
#-------------------------------------------------------------------------------------------------------------------------------
# Acquire pathes to crawl into
PATHES=(*/)
for PATHPARTS in ${PATHES[@]}
do
ENTRY=$(basename $PATHPARTS)
if [[ $SUBLEVEL -gt -1 ]]; then
SUBPATHS[$SUBLEVEL]=$ENTRY
SUBLEVEL=$(($SUBLEVEL+1))
fi
mirrorPathes $ENTRY
if [[ $SUBLEVEL -gt 0 ]]; then
SUBPATHS[$SUBLEVEL]=
fi
SUBLEVEL=$(($SUBLEVEL-1))
done
}
# End to mirrorPathes
#---------------------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------------
# Starting
#---------------------------------------------------------------------------------------------------------------------------------
SRCDIR=$1
DESTDIR=$2
if [[ -z $SRCDIR ]]; then
shopt -u dotglob
shopt -u nullglob
echo "Starting directory is missing."
exit
fi
if [[ -z $DESTDIR ]]; then
shopt -u dotglob
shopt -u nullglob
echo "Destination directory is missing."
exit
fi
echo "Starting folder mirroring and extraction of zip files in:"
echo "Source: $SRCDIR"
echo "Target: $DESTDIR"
mirrorPathes $SRCDIR
shopt -u dotglob
shopt -u nullglob
echo "Processed folders: $FOLDERCOUNT"
echo "Finished execution."
exit
[/src]