Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mirror local files to encrypted Cryptomator's vault
#!/bin/sh
CRYPTOMATOR_PATH="/usr/local/bin/cryptomator-cli.jar"
DIR_TO_SYNC_PATH="$HOME/Private"
MOUNT_PATH="$HOME/VAULT_$RANDOM"
VAULT_PATH="$HOME/PATH/TO/ENCRYPTED/VAULT"
VAULT_PASSWORD="`security find-generic-password -a KEYCHAIN_ENTRY_VAULT_PASSPHRASE -w`"
VAULT_NAME="vault"
BIND_HOST="localhost"
BIND_PORT="8198"
/usr/bin/java -jar $PATH_TO_CRYPTOMATOR \
--vault $VAULT_NAME=$VAULT_PATH \
--password $VAULT_NAME=$VAULT_PASSWORD \
--bind $BIND_HOST \
--port $BIND_PORT &
PID=($!)
echo "Cryptomator started under PID: $PID"
sleep 5
echo "Create new mounting point: $MOUNT_PATH"
mkdir -p $MOUNT_PATH
echo "Attach WebDAV interface to mount point"
n=0
until [ $n -ge 5 ]
do
echo "Try $n: Mount http://$BIND_HOST:$BIND_PORT/$VAULT_NAME/ to $MOUNT_PATH"
/sbin/mount_webdav http://$BIND_HOST:$BIND_PORT/$VAULT_NAME/ $MOUNT_PATH && break
n=$[$n+1]
sleep 1
done
if /sbin/mount | grep $MOUNT_PATH > /dev/null; then
/usr/bin/rsync -hrvtP --update --exclude "~*" $DIR_TO_SYNC_PATH/ $MOUNT_PATH/
/sbin/umount $MOUNT_PATH
else
echo "WebDAV not mounted correctly..."
fi
echo "Removing mounting point"
rm -rf $MOUNT_PATH
echo "Close cryptomator"
kill $PID
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>pl.skrajewski.backup</string>
<key>Program</key>
<string>/usr/local/bin/custom/backup.sh</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>22</integer>
<key>Minute</key>
<integer>45</integer>
</dict>
<key>StandardErrorPath</key>
<string>/var/log/vault-backup.error.log</string>
<key>StandardOutPath</key>
<string>/var/log/vault-backup.log</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment