1
0
Fork 0
mirror of https://github.com/kastdeur/pipeband-music.git synced 2024-11-16 08:23:31 +01:00
pipeband-music/shadowdir

57 lines
1.1 KiB
Text
Raw Normal View History

2019-02-03 22:28:59 +01:00
#!/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