Skip to content
Snippets Groups Projects
Commit 802f7df3 authored by nimrod's avatar nimrod
Browse files

NextCloud mount script.

- nc-mount to mount locally NextCloud folders (using rclone).
- Bash completion for nc-mount.
parent 8c8b20a4
No related branches found
No related tags found
No related merge requests found
Pipeline #2415 failed
# vim: ft=bash
_nc_mount () {
local cur prev words cword opts
_init_completion || return
opts='-a --all -h --help -l --list'
if [[ $cur == -* ]]
then
COMPREPLY=($(compgen -W "$opts" -- "$cur"))
else
local IFS=$'\n'
declare -a candidates
candidates=($(compgen -W "$(nc-mount -l)" -- "$cur"))
if [ ${#candidates[*]} -eq 0 ]
then
COMPREPLY=()
else
COMPREPLY=($(printf '%q\n' "${candidates[@]}"))
fi
fi
}
complete -F _nc_mount nc-mount
#!/bin/sh
set -eu
command -v rclone >/dev/null || { echo 'rclone not found.' >&2; exit 1; }
usage () {
echo "$0: [-a|--all] [-l|--list] [FOLDER]" >&2
exit 1
}
_mount () {
folder="$1"
mkfolder -p "$HOME/$folder"
rclone mount \
--allow-non-empty \
--daemon \
--gid "$(id -g)" \
--vfs-cache-mode full \
--uid "$(id -u)" \
"nextcloud:$folder" \
"$HOME/$folder"
}
[ "$#" -eq 1 ] || usage
folders="$(rclone lsd nextcloud: | cut -c 44- | grep -vx 'System information')"
case "$1" in
-h|--help) usage;;
-l|--list) echo "$folders";;
-a|--all) echo "$folders" | xargs -I % "$0" "%";;
*) if echo "$folders" | grep -qx "$1"
then
_mount "$1"
else
echo "Folder $1 not found in Nextcloud." >&2
exit 1
fi;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment