-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremove_old_moduledirs
executable file
·60 lines (49 loc) · 1.41 KB
/
remove_old_moduledirs
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
#!/usr/bin/env bash
become_path=/shared/ucl/sysops/bin/become
moduledirs_path=/shared/ucl/apps
if (id -Gn | grep -v '\bccsprcop\b') && (whoami | grep -v ccspapp); then
echo "Error: user should be in ccsprcop group to use this script." >&2
exit 1
fi
if (whoami | grep -v ccspapp); then
echo "Becoming ccspapp and re-running..." >&2
$become_path ccspapp <<EOF
$0 "$@"
EOF
exit
fi
# Check if there's a common apps area (e.g. merged Young/Michael)
[[ -d "${moduledirs_path}/../common" ]] \
&& moduledirs_path="${moduledirs_path}/../common"
# v-- gets a list of all directories named .mf_* created more than 7 days ago
mapfile dirs_to_remove < <(find -L $moduledirs_path -maxdepth 1 -type d -name ".mf_*" -ctime +7)
num_dirs="${#dirs_to_remove[@]}"
if [[ $num_dirs -eq 0 ]]; then
echo "No directories found." >&2
exit
fi
while :; do
read -r -n 1 -p "This will delete $num_dirs directories. Are you sure you want to continue? [Y|N|(L)ist] " prompt_response
case "${prompt_response,,*}" in
"y")
for i in "${dirs_to_remove[@]}"; do
if [[ ! -a $i/.keep ]]; then
'rm' -vRf "$i"
else
echo "Not deleting $i : .keep file found"
fi
done
exit
;;
"n")
echo "Okay, doing nothing."
exit
;;
"l")
'ls' -lrtd "${dirs_to_remove[@]}"
;;
*)
echo "Invalid response. Please choose one of y, n, or l."
;;
esac
done