Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- path="/home/erik/.local/share/plover" #Path to local Plover dictionaries
- dictionaries="user.json,main.json,commands.json,emoji.json,command-line.json,UK-Spellings.json,latex.json" #dictionaries to copy
- mkdir serverDictionaries #Create temporary directory
- sshfs -p 4295 eto@[server-ip]:/home/eto/serverDictionaries ./serverDictionaries/ #Mount the directory
- echo ""
- IFS=',' read -r -a dictionary <<< "$dictionaries" #Turn the dictionary string into an array
- for t in "${dictionary[@]}"; do #Go through each entry in the dictionary array
- if [ ! -f "./serverDictionaries/$t" ]; then #If the dictionary doesn't exist, copy it and skip the rest of the loop
- cp "$path"/"$t" ./serverDictionaries
- echo "$t does not exist on server, copying..."
- continue
- fi
- isDiff=$(diff "$path"/"$t" ./serverDictionaries/"$t")
- local=$(date +%s -r "$path"/"$t")
- server=$(date +%s -r ./serverDictionaries/"$t")
- if [[ "$isDiff" ]]; then #Check if the files are different, ignore if they aren't
- if [[ $server > $local ]]; then #Copy server-side dictionary to local if it has been modified more recently
- echo "The server side $t was modified more recently than the local $t"
- echo "Updating the local $t dictionary..."
- cp ./serverDictionaries/"$t" "$path"/
- elif [[ $server < $local ]]; then #Copy local dictionary to the server if it has been modified recently
- echo "The local $t was modified more recently than $t on the server"
- echo "Updating the server side $t dictionary..."
- cp "$path"/"$t" ./serverDictionaries/
- fi
- echo ""
- else
- echo "$t is the same!"
- echo ""
- fi
- done
- umount ./serverDictionaries/ #Unmount the server dictionaries
- rmdir serverDictionaries #Delete the server dictionaries folder
Add Comment
Please, Sign In to add comment