-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncjanitor.sh
executable file
·100 lines (90 loc) · 2.07 KB
/
syncjanitor.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
#!/usr/bin/env -S bash
set -e -u
set -o pipefail
# delete expected files after syncthing sync
# run me on laptop
function usage()
{
cat << EOF
Usage: ${0##*/}" [OPTION]...
Options: --help, -h: show this help dialog
-u USER: only run for this user
EOF
}
function sync_janitor ()
{
user="${1}"; shift
basedir="${android}/storage/emulated/${user}/TRASH"
whitelisted_deletions=(
WhatsApp/.Thumbs
WhatsApp/Backups
WhatsApp/Databases
WhatsApp/.Shared
WhatsApp/Media/.Statuses
Documents/Media/Signal
Documents/oandbackups
Movies/.thumbnails
Notifications
Pictures/.thumbnails
.DS_Store
)
rmdir_p=(
Documents/Media
Documents
Movies
Pictures
WhatsApp
)
if [ -d "${basedir}" ]; then
for i in "${whitelisted_deletions[@]}"; do
rm -r "${basedir}/$i" 2>/dev/null || true
done
cd "${basedir}"
for i in "${rmdir_p[@]}"; do
rmdir -p "${i}" 2>/dev/null || true
done
rmdir "${basedir}"
fi
}
function main()
{
user=all
while getopts "hu:-:" opt; do
case ${opt} in
h) # help message
usage
exit 0
;;
u)
user="${OPTARG}"
;;
-)
case "${OPTARG}" in
help)
usage
exit 0
;;
*)
printf 'Unknown option, exiting now\n' >&2
exit 1
;;
esac
;;
?)
printf 'Unknown option, exiting now\n' >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
[[ ${1:-} == '--' ]] && shift
if [ "${user}" == all ]; then
sync_janitor 0
sync_janitor 10
else
sync_janitor "${user}"
fi
}
if [ "${BASH_SOURCE[0]}" == "$0" ]; then
main "$@"
fi