blob: a14176283e1a05281be32e562d65ad9ce335912a (
plain) (
blame)
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
|
#!/bin/bash
###This script will update files from the M+ local directory only if the file exists in the TMW extracted directory. This prevents files from local from being written to
###TMW if it doesn't exist in TMW. cmp is used to compare files and overwrites the TMW file with the local one only if they differ.
#Required apps check
REQUIRED_APPS='cmp sed sort'
for APP in $REQUIRED_APPS; do
REQ_APP_CHECK=$(find '/bin' '/usr/bin' -name "$APP")
if [[ "$REQ_APP_CHECK" == '' ]]; then
echo -e "$APP must be installed in order for tmw-cmp-update to work\nRequired Apps: $REQUIRED_APPS" >&2
exit 0
fi
done
#Confirmation
while :; do
echo -e "This script will update files from the M+ local directory only if the file exists in the TMW extracted directory. This prevents files from local from being \
written to TMW if it doesn't exist in TMW. cmp is used to compare files and overwrites the TMW file with the local one only if they differ."
read -p 'Do you wish to continue? (y/n)' ANS1
case $ANS1 in
[Yy]* ) break;;
[Nn]* ) exit 0;;
* ) echo "Invalid response: Y/y(anything) for yes or N/n(anything) for no.";;
esac
done
###Variables you may want to change###
#The (sub)directory where the TMW files extracted from TMW.zip reside. I prefer to make a backup of a directory and work from there. (Default "$HOME/Desktop/TMW")
TMW_DIR="$HOME/Desktop/TMW"
#The (sub)directory where local files are found. (Default: "$HOME/.local/share/mana/updates/themanaworld.github.io/tmwa-server-data/local")
LOCAL_DIR="$HOME/.local/share/mana/updates/themanaworld.github.io/tmwa-server-data/local"
#Log for files that exist in TMW, but not in local
MISSING_FROM_LOCAL="$HOME/Desktop/missing_from_local.txt"
#Log for files that exist in local, but not in TMW
MISSING_FROM_TMW="$HOME/Desktop/missing_from_tmw.txt"
###
: > "$MISSING_FROM_LOCAL"
: > "$MISSING_FROM_TMW"
for FILE in $(find "$TMW_DIR" -type f); do
PATHNAME=$(echo "$FILE" | sed "s,^$TMW_DIR/,,")
LOCAL_FILE=$(find "$LOCAL_DIR" -type f -path "*$PATHNAME")
if [[ "$LOCAL_FILE" != '' ]]; then
if [[ $(cmp "$FILE" "$LOCAL_FILE") != '' ]]; then
cp -fv "$LOCAL_FILE" "$FILE"
fi
elif [[ "$LOCAL_FILE" == '' ]]; then
#List files in tmw directory that are not in the local directory
echo "$PATHNAME" >> "$MISSING_FROM_LOCAL"
fi
done
#List files in local directory that are not in the TMW directory
for FILE in $(find "$LOCAL_DIR" -type f); do
PATHNAME=$(echo "$FILE" | sed "s,^$LOCAL_DIR/,,")
TMW_FILE=$(find "$TMW_DIR" -type f -path "*$PATHNAME")
if [[ "$TMW_FILE" == '' ]]; then
echo "$PATHNAME" >> "$MISSING_FROM_TMW"
fi
done
sort -n "$MISSING_FROM_LOCAL" > "$MISSING_FROM_LOCAL"'_tmp'
mv -f "$MISSING_FROM_LOCAL"'_tmp' "$MISSING_FROM_LOCAL"
sort -n "$MISSING_FROM_TMW" > "$MISSING_FROM_TMW"'_tmp'
mv -f "$MISSING_FROM_TMW"'_tmp' "$MISSING_FROM_TMW"
|