2023-05-10 10:38:53 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-06-29 15:43:19 +00:00
|
|
|
#set -eu
|
|
|
|
|
|
|
|
# Sourc some env
|
2023-05-10 10:38:53 +00:00
|
|
|
[ -f .env ] && . ./.env
|
|
|
|
|
2023-06-29 15:43:19 +00:00
|
|
|
# Used env vars
|
|
|
|
[ -z "$NC_SHARE_LINK" ] && echo 'Aucun partage cloud trouvé' && exit 1
|
|
|
|
# NC_SHARE_PASSWORD can be empty
|
|
|
|
|
|
|
|
# Extract data from share link
|
|
|
|
tmp="$(mktemp)"
|
|
|
|
echo "$NC_SHARE_LINK" | sed 's#/s/# #' > "$tmp"
|
|
|
|
read server token <"$tmp"
|
|
|
|
rm "$tmp"
|
|
|
|
|
|
|
|
[ -z "$server" ] && echo 'Aucun serveur trouvé dans le lien de partage' && exit 1
|
|
|
|
[ -z "$token" ] && echo 'Aucun token trouvé dans le lien de partage' && exit 1
|
2023-05-10 10:38:53 +00:00
|
|
|
|
2023-06-29 15:43:19 +00:00
|
|
|
# User may ask for sync way
|
2023-05-10 10:38:53 +00:00
|
|
|
action="$1"
|
|
|
|
|
|
|
|
if [ "$action" = 'pull' ] || [ -z "$action" ] ; then
|
2023-06-29 15:43:19 +00:00
|
|
|
path=":webdav: $CLOUD_LOCAL_PATH"
|
2023-05-10 10:38:53 +00:00
|
|
|
elif [ "$action" = 'push' ] ; then
|
2023-06-29 15:43:19 +00:00
|
|
|
path="$CLOUD_LOCAL_PATH :webdav:"
|
2023-05-10 10:38:53 +00:00
|
|
|
else
|
|
|
|
echo "unknown action: $action"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-29 15:43:19 +00:00
|
|
|
|
|
|
|
# Actual sync
|
|
|
|
rclone sync --create-empty-src-dirs "--webdav-url=$server/public.php/webdav/" "--webdav-user=$token" --webdav-pass="$(rclone obscure "$NC_SHARE_PASSWORD")" --webdav-vendor=nextcloud $path
|
|
|
|
|
|
|
|
echo "SYNC OK"
|