#!/bin/bash
script=""
for op in $@; do
if [ -f $op ]; then script=$op; fi
done

if [ $script == "" ]; then echo "Usage: sh deepln.sh /path/to/link-target-file"; fi

# script to deep link all directories to indexgen.php
# will place index.php in all subdirectories from where the script is called

# NOTE: call this script from the top of the public directory tree, it must
# be called from the directory you wish to start making changes
# the script does not have to actually be present there, i.e.
# cd directory-to-change
# sh /path/to/script/deepln.sh /path/to/indexgen.php

# if you rename indexgen.sh (or use this shell script for another purpose)
# the last option on the command line that is a normal file will be the
# link target

# remove all index.php and index.html files in all sub-directories
# note I do not usually remove the index.html files so it is commented, but
# if any index.html is present your apache server may use that instead of
# giving preference to the index.php
find . -type f -name index.php -print0 | xargs -0 rm -f
#find . -type f -name index.html -print0 | xargs -0 rm -f

# now link to script in every directory within the tree below working dir
find . -type d -exec ln -f $script "{}/index.php" \;
unset indexgen


