-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleanupEverything.sh
executable file
·119 lines (102 loc) · 3.44 KB
/
cleanupEverything.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
#
# Remove all files and directories created by running scripts
# Make sure we are in the correct directory
DIRNAME=$(dirname "$0")
cd "$DIRNAME" || exit
source functions/define_colors
source functions/define_files
source functions/load_functions
function help() {
cat <<EOF
cleanupEverything.sh -- Developer script: Remove files generated by other scripts.
This script makes it easier for developers to get rid of files generated by
running other scripts. It will first ask if you want to delete EVERYTHING,
which will reset this directory to the state a completely new user would
encounter. You can't undo this.
If you hit <cr> or answer "no". It will give you the choice of deleting various
types of files. It always defaults to "No", so just hit <cr> to see what your
choices would be. Or look at the source code for this script.
USAGE:
./cleanupEverything.sh [OPTIONS]
OPTIONS:
-h Print this message.
-i Request confirmation before attempting to remove each file
-v Be verbose when deleting files, showing them as they are removed.
EOF
}
function deleteFiles() {
printf "Deleting ...\n"
# Globbing needs to take place here.
# shellcheck disable=SC2068 # Don't quote $@
rm -rf "$ASK" "$TELL" $@
printf "\n"
}
# Allow switches -v or -i to be passed to the rm command
while getopts ":hiv" opt; do
case $opt in
h)
help
exit
;;
i)
ASK="-i"
;;
v)
TELL="-v"
;;
\?)
printf "==> Ignoring invalid option: -$OPTARG\n\n" >&2
;;
esac
done
shift $((OPTIND - 1))
# Quote filenames so globbing takes place in the "deleteFiles" function,
# i.e. the function is passed the number of parameters seen below, not
# the expanded list which could be quite long.
if waitUntil "$YN_PREF" -N \
"${RED}Delete EVERYTHING created by scripts and users?${NO_COLOR}"; then
deleteFiles "Shows-*.csv" "Credits-*.csv" "Persons-KnownFor*.csv" \
"AssociatedTitles*.csv" "LinksToPersons*.csv" "LinksToTitles*.csv" \
"Episode-Count*.csv" "uniq*.txt" "secondary" "diffs*.txt" \
"baseline" "test_results" "*.tsv.gz" "*.tconst" "*.xlate" ".xref_*"
exit
else
printf "Skipping...\n"
fi
if waitUntil "$YN_PREF" -N \
"Delete primary spreadsheets containing credits, shows, and episodes?"; then
deleteFiles "Shows-*.csv" "Credits-*.csv" "Persons-KnownFor*.csv" \
"AssociatedTitles*.csv" "LinksToPersons*.csv"
else
printf "Skipping...\n"
fi
if waitUntil "$YN_PREF" -N \
"Delete smaller files that contain lists of persons and shows?"; then
deleteFiles "LinksToTitles*.csv" "Episode-Count*.csv" "uniq*.txt"
else
printf "Skipping...\n"
fi
if waitUntil "$YN_PREF" -N "Delete all files generated during debugging?"; then
deleteFiles "secondary" "diffs*.txt" "baseline" "test_results"
else
printf "Skipping...\n"
fi
if waitUntil "$YN_PREF" -N "Delete all the .gz files downloaded from IMDb?"; then
deleteFiles "*.tsv.gz"
else
printf "Skipping...\n"
fi
printf "\n[${RED}Warning${NO_COLOR}] The following files are usually manually created. "
printf "They are ignored by git.\n"
if waitUntil "$YN_PREF" -N \
"Delete all manually maintained .tconst and .xlate files?"; then
deleteFiles "*.tconst" "*.xlate"
else
printf "Skipping...\n"
fi
if waitUntil "$YN_PREF" -N "Delete all user configuration (.xref_*) files?"; then
deleteFiles ".xref_*"
else
printf "Skipping...\n"
fi