aericktoes

Dictionary Updater

Sep 8th, 2020 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #!/bin/bash
  2. path="/home/erik/.local/share/plover" #Path to local Plover dictionaries
  3. dictionaries="user.json,main.json,commands.json,emoji.json,command-line.json,UK-Spellings.json,latex.json" #dictionaries to copy
  4.  
  5. mkdir serverDictionaries #Create temporary directory
  6.  
  7. sshfs -p 4295 eto@[server-ip]:/home/eto/serverDictionaries ./serverDictionaries/ #Mount the directory
  8.  
  9. echo ""
  10.  
  11. IFS=',' read -r -a dictionary <<< "$dictionaries" #Turn the dictionary string into an array
  12.  
  13. for t in "${dictionary[@]}"; do #Go through each entry in the dictionary array
  14.  
  15.     if [ ! -f "./serverDictionaries/$t" ]; then #If the dictionary doesn't exist, copy it and skip the rest of the loop
  16.         cp "$path"/"$t" ./serverDictionaries
  17.         echo "$t does not exist on server, copying..."
  18.         continue
  19.     fi
  20.  
  21.     isDiff=$(diff "$path"/"$t" ./serverDictionaries/"$t")
  22.     local=$(date +%s -r "$path"/"$t")
  23.     server=$(date +%s -r ./serverDictionaries/"$t")
  24.  
  25.     if [[ "$isDiff" ]]; then #Check if the files are different, ignore if they aren't
  26.         if [[ $server > $local ]]; then #Copy server-side dictionary to local if it has been modified more recently
  27.             echo "The server side $t was modified more recently than the local $t"
  28.             echo "Updating the local $t dictionary..."
  29.             cp ./serverDictionaries/"$t" "$path"/
  30.  
  31.         elif [[ $server < $local ]]; then #Copy local dictionary to the server if it has been modified recently
  32.             echo "The local $t was modified more recently than $t on the server"
  33.             echo "Updating the server side $t dictionary..."
  34.             cp "$path"/"$t" ./serverDictionaries/
  35.         fi
  36.         echo ""
  37.        
  38.     else
  39.         echo "$t is the same!"
  40.         echo ""
  41.     fi
  42.  
  43. done
  44.  
  45. umount ./serverDictionaries/ #Unmount the server dictionaries
  46.  
  47. rmdir serverDictionaries #Delete the server dictionaries folder
  48.  
Add Comment
Please, Sign In to add comment