mirror of
https://github.com/kastdeur/pipeband-music.git
synced 2024-12-22 08:13:31 +01:00
Script to create a shadow directory
This commit is contained in:
parent
1c05f8ba65
commit
7801ead508
1 changed files with 56 additions and 0 deletions
56
shadowdir
Executable file
56
shadowdir
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
|
||||
FROMDIR="../$1"
|
||||
TODIR=${2:-$(pwd)}
|
||||
TODIR=${TODIR%/}
|
||||
|
||||
OrigLDIRLINK=".dirlink"
|
||||
DIRLINK="$TODIR/$OrigLDIRLINK"
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "Usage: $0 FROM TO"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# Create the TODIR
|
||||
[ -d "$TODIR" ] || mkdir -p "$TODIR"
|
||||
|
||||
# Create the dirlink
|
||||
ln -sf "$FROMDIR" "$DIRLINK"
|
||||
|
||||
# Copy Directory Structure
|
||||
find "$DIRLINK/" -print0 |
|
||||
while IFS= read -d "" oname;
|
||||
do
|
||||
case "$oname" in
|
||||
*.git*) continue;;
|
||||
*.pdf ) continue;;
|
||||
*.png ) continue;;
|
||||
esac
|
||||
|
||||
name="${oname/$DIRLINK\/}"
|
||||
lname="${oname/$TODIR\/}"
|
||||
|
||||
# Create directory
|
||||
if [ -d "$oname" ]; then
|
||||
mkdir -p "$TODIR/$name"
|
||||
continue;
|
||||
fi
|
||||
|
||||
# Create softlink
|
||||
if [ -f "$oname" ]; then
|
||||
fname="${name##*/}"
|
||||
dname="${name%/*}"
|
||||
ndots="$(echo $name | awk -F"/" 'NF > max {max = NF} END {print max-1}')"
|
||||
dots=$(printf '%*s' $ndots | sed 's; ;../;g')
|
||||
|
||||
to=$dots$OrigLDIRLINK/$name
|
||||
from=$TODIR/$name
|
||||
ln -s "$to" "$from" 2> /dev/null
|
||||
continue;
|
||||
fi
|
||||
done
|
||||
|
||||
echo "#!/bin/bash" > $TODIR/update_shadow_dir
|
||||
echo "./.dirlink/shadowdir ./.dirlink/ ." >> $TODIR/update_shadow_dir
|
||||
chmod +x $TODIR/update_shadow_dir
|
Loading…
Reference in a new issue