#!/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/updates.tmw2.org/legacy/local") LOCAL_DIR="$HOME/.local/share/mana/updates/updates.tmw2.org/legacy/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" else echo "Omitting $PATHNAME: Files match" 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"