-
Notifications
You must be signed in to change notification settings - Fork 0
/
correct_paths.sh
executable file
·81 lines (68 loc) · 2.47 KB
/
correct_paths.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#Colours
greenColour="\e[0;32m\033[1m"
endColour="\033[0m\e[0m"
redColour="\e[0;31m\033[1m"
blueColour="\e[0;34m\033[1m"
yellowColour="\e[0;33m\033[1m"
purpleColour="\e[0;35m\033[1m"
turquoiseColour="\e[0;36m\033[1m"
grayColour="\e[0;37m\033[1m"
# Initialize variables to store the directory and subdirectory
directory=""
subdirectory=""
star=$(echo -e -n "${greenColour}[${blueColour}*${greenColour}]${endColour}")
plus=$(echo -e -n "${greenColour}[${blueColour}+${greenColour}]${endColour}")
errorsym=$(echo -e -n "${redColour}[${yellowColour}!${redColour}]${endColour}")
# Parse arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--directory)
directory="$2"
shift
;;
--name)
name="$2"
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done
# Check if directory argument is provided
if [ -z "$directory" ]; then
echo -e "${errorsym} Please provide a directory using --directory flag."
exit 1
fi
# Check if name argument is provided
if [ -z "$name" ]; then
echo "${errorsym} Please provide a name for the module using --name flag."
exit 1
fi
# Check if the provided directory exists and is a directory
if [ ! -d "$directory" ]; then
echo "${errorsym} Directory '$directory' does not exist or is not a directory."
exit 1
fi
echo -e "${grayColour}==================================================${endColour}"
echo "${star} Directory: $directory"
echo -e "${star} Name: ${name}"
echo -e "${grayColour}==================================================${endColour}"
# Counter variable
let counter=0
# Use find command to get all the index.html files recursively
# Then loop through each file and use sed to replace the word
while IFS= read -r file; do
# Replace the word "href=/images/" with "href=/your_variable/images/"
sed -i "s/href=\/images\//href=\/$name\/images\//g" "$file"
sed -i "s/src=\/images\//src=\/$name\/images\//g" "$file"
sed -i 's/type=image\/svg\+xml\ href=\/pentesting\/images\/favicon\.svg/type=image\/png\ href=\/pentesting\/images\/favicon-32x32\.png/g' "$file"
echo -e "${plus} Updated file: $file"
((counter++)) # Increment counter
done < <(find "$directory" -type f -name 'index.html' 2>/dev/null)
echo -e "\n${redColour}---${yellowColour}>${endColour} Total files modified: $counter"
echo -e "${grayColour}==================================================${endColour}"