-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.sh
86 lines (79 loc) · 2.26 KB
/
cleanup.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
81
82
83
84
85
86
#!/usr/bin/env bash
# Set shell options
set -eou pipefail
#set -x # for debugging purposes - this prints the command that is to be executed before the command is executed
USAGE_func() {
echo "usage"
}
TMP_FILE_REMOVED_SUCCESSFULLY=""
SUPPRESS=""
VERBOSE=""
while getopts "d:xvshf:" opt; do
case "$opt" in
d) DIRECTORIES+=("$OPTARG");;
f) FILETYPES+=("$OPTARG");;
x) set -x;;
v) VERBOSE="1";;
s) SUPPRESS="1";;
h) USAGE_func;;
*) USAGE_func;;
esac
done
shift $((OPTIND -1))
REMOVE_TMP_func() {
if [[ -n $(printf "$TMP_FILE_REMOVED_SUCCESSFULLY" | grep -w "$TMP_FILE") ]]; then
:
else
if [[ -a "$TMP_FILE" ]]; then
rm -r "$TMP_FILE"
if [[ -a "$TMP_FILE" ]]; then
if [[ -n "$SUPPRESS" ]]; then
:
else
echo "CLEAENUP ERROR: File "$TMP_FILE" could not be removed/still somehow exists after removal."
fi
exit 5
else
if [[ -n "$VERBOSE" ]]; then
echo "CLEAENUP INFO: File "$TMP_FILE" removed successfully."
else
:
fi
TMP_FILE_REMOVED_SUCCESSFULLY+=" "$TMP_FILE""
fi
else
if [[ -n "$VERBOSE" ]]; then
echo "CLEAENUP INFO: File "$TMP_FILE" doesn't exist."
else
:
fi
fi
fi
}
if [[ -n "${DIRECTORIES[@]}" ]]; then
for DIRECTORY in "${DIRECTORIES[@]}"; do
for TMP in "$@"; do
TMP_FILE="$DIRECTORY"/"$TMP"
REMOVE_TMP_func
done
for FILETYPE in ${FILETYPES[@]}; do
if [[ -n $(find "$DIRECTORY" -name "*"$FILETYPE"" -type f) ]]; then
for TMP_FILE in $(find "$DIRECTORY" -name "*"$FILETYPE"" -type f); do
REMOVE_TMP_func
done
else
if [[ -n "$VERBOSE" ]]; then
echo "CLEAENUP INFO: Couldn't find any '"$FILETYPE"' filetype within directory "$DIRECTORY"."
else
:
fi
fi
done
done
else
:
fi
for TMP_FILE in "$@"; do
REMOVE_TMP_func
done
exit 0