-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnuke.local
More file actions
53 lines (42 loc) · 1.72 KB
/
Copy pathnuke.local
File metadata and controls
53 lines (42 loc) · 1.72 KB
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
#!/bin/sh
##############################################################################
. ${HOME}/.config/SmokeScreen/smokescreen.conf
# If script is already running; abort.
if pidof -o %PPID -x "$(basename "$0")"; then
echo "$(date "+%d.%m.%Y %T") INFO: $(basename "$0") already in progress. Aborting."
exit 3
fi
# Generate file list and iterate through it...
find "${localdir}" -type f |
while read -r n; do
# Find the pathname relative to the root of your remote and store filename
filename="$(echo "$n" | sed -e s@"${localdir}"@@)"
# Skip hidden or partial files.
case "$n" in
(*.partial~) continue ;;
(*_HIDDEN~) continue ;;
(*.QTFS) continue ;;
(*.fuse*) continue ;;
esac
# Get the MD5SUM of our local copy
local_checksum=$(md5sum "$n" | awk '{print $1}')
# If file is opened by another process, wait until it isn't.
while [ "$(lsof "${n}" >/dev/null 2>&1)" ]; do
echo "$(date "+%d.%m.%Y %T") INFO: File -> ${n} in use. Retrying in 10 seconds."
sleep 10
done
# Check remote MD5SUMs
primary_checksum=$($rclonebin md5sum "${primaryremote}:${cloudsubdir}${filename}" 2>&1 | awk '{print $1}' | head --lines=1)
# Check that all MD5SUMs match, and if so, delete local copies.
if [ "$primary_checksum" = "$local_checksum" ]; then
echo "$(date "+%d.%m.%Y %T") INFO: Removing -> ${n}"
rm -f "$n"
else
echo "$(date "+%d.%m.%Y %T") INFO: File -> ${n} not synced."
fi
done
# Nuke empty folders in local media folder
echo "$(date "+%d.%m.%Y %T") INFO: Nuking Empty Folders..."
find ${localdir} -mindepth 2 -type d -empty -delete 2>&1
# success!
exit 0