-
Notifications
You must be signed in to change notification settings - Fork 1
/
clean_gdrive_slack.sh
executable file
·47 lines (43 loc) · 1.22 KB
/
clean_gdrive_slack.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
#!/bin/sh
# Clean local files {{{
PREV_MD5=""
PREV_PATH=""
CURRENT_MD5=""
CURRENT_PATH=""
# get hashes, and sort by hash
find /var/opt/slack-parrotbot/files -type f | xargs md5sum | sort \
| while read current_line
do
CURRENT_MD5=$(echo "$current_line" | awk '{print $1}')
CURRENT_PATH=$(echo "$current_line" | awk '{print $2}')
if [ "$CURRENT_MD5" = "$PREV_MD5" ] ; then
echo "DELETE: $CURRENT_PATH"
sudo rm $CURRENT_PATH
else
PREV_MD5=$CURRENT_MD5
PREV_PATH=$CURRENT_PATH
fi
done
# }}}
# Clean gdrive {{{
PREV_MD5=""
PREV_PATH=""
CURRENT_MD5=""
CURRENT_PATH=""
# get hashes, remove empty (gdocs etc) and sort by hash
rclone md5sum parrotbot-gdrive:slack-staging \
| grep '[^0-9a-f]' | sort - \
| while read current_line ; do
CURRENT_MD5=$(echo "$current_line" | cut -c -32)
CURRENT_PATH=$(echo "$current_line" | cut -c 35-)
if [ "$CURRENT_MD5" = "$PREV_MD5" ] ; then
echo "DELETE: parrotbot-gdrive:slack-staging/$CURRENT_PATH"
rclone -v delete "parrotbot-gdrive:slack-staging/$CURRENT_PATH"
else
PREV_MD5=$CURRENT_MD5
PREV_PATH=$CURRENT_PATH
fi
done
# }}}
# Resync
sudo rclone sync /var/opt/slack-parrotbot/files parrotbot-gdrive:slack-staging