Created
August 14, 2023 22:44
-
-
Save Reiikz/46711f9c1b035949692ed5a77ffe959a to your computer and use it in GitHub Desktop.
copies a file in its current dierectory to all subdirectories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script copies an index file to all of your site | |
# copy this file to the root of your website and pass it your index file you want prenset on all of your subdirectories | |
# IE: | |
# cp ~/indexify /srv/http/default | |
# cd /srv/http/default | |
# chmod +x ./indexify | |
# ./indexify ./index.php | |
# in this example you should see the output of -cp -v copying your /srv/http/default/index.php to all subdirectories | |
if [ $# -gt 1 ] || [ $# -le 0 ]; then | |
echo "Wrong arguments pass only the index file to put on every subdirectory" | |
fi | |
if [ ! -f "$1" ]; then | |
echo "$1 is not a file" | |
fi | |
FILE="$(realpath $1)" | |
NAME="$(basename "$FILE")" | |
declare -a DIRS=( [0]="$(realpath ./)" ) | |
function recursiveList { | |
for x in ./"$1"/*; do | |
if [ -d "$x" ]; then | |
DIRS[${#DIRS[@]}]="$(realpath $x)"; | |
recursiveList "$x" | |
fi | |
done | |
} | |
recursiveList | |
for x in ${DIRS[@]}; do | |
target="$x/$NAME" | |
if [ ! -f "$target" ]; then | |
cp -v "$FILE" "$target" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment