-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseline_creator.sh
executable file
·65 lines (57 loc) · 1.71 KB
/
baseline_creator.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
#!/bin/bash
#This will loop through the files in a directory (Put in loop of directories)
#://askubuntu.com/questions/678914/loop-through-all-files-in-a-folder
createBaseline() {
BASEPATH=$(find / -name $1 2>/dev/null | head -n1)
#Checks to make sure user input is an existing directory
if [ -d "$BASEPATH" ]
then
#stores absolute bath to the Baselines folder
ABSPATH=$(realpath Baselines)
#calls makeBase func and create custom file name
#nameCheck is called to ensure a baseline does not already exist
file=$(makeBase $BASEPATH)
checker=$(nameCheck $file $ABSPATH | head -n 1)
#if there is no baseline file then baselineWrite is called to create it
if [ $checker -ne 1 ]; then
baselineWrite $BASEPATH > "$ABSPATH/$(echo $file)"
else
echo "Oops, you already took this baseline"
fi
else
echo "Oops, that's not a directory!"
fi
}
makeBase() {
prefix=$(echo -n $1 | rev | cut -d "/" -f 1 | rev)
suffix="_baseline.txt"
filename="$prefix$suffix"
echo $filename
}
baselineWrite() {
#Function loops through all files in a folder
#Uses recursion to loop through existing subdirectories
for i in "$1"/*
do
if [ -d "$i" ]; then
ls -lid $i
baselineWrite "$i"
elif [ -e "$i" ]; then
ls -li $i
fi
done
}
nameCheck(){
#Used to make surea baseline doesn't already exist so it doesn't get overwriten
for i in "$2"/*
do
name=$(echo -n "$i" | rev | cut -f 1 -d "/" | rev)
if [ "$name" == "$1" ]; then
echo 1
break
fi
done
echo 0
}
#Call function
createBaseline $1