Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivandeex/038ac805293f44e6859c3c876f586c46 to your computer and use it in GitHub Desktop.
Save ivandeex/038ac805293f44e6859c3c876f586c46 to your computer and use it in GitHub Desktop.
[Unit]
Description=rclone automount mrcry
Before=remote-fs.target
After=network-online.target
[Automount]
Where=/mnt/mysftp
TimeoutIdleSec=30
[Install]
WantedBy=multi-user.target
[Unit]
Description=rclone mount sbsftp
After=network-online.target
[Mount]
Where=/mnt/mysftp
What=mysftp:
Type=rclone
Options=rw,_netdev,gid=911,allow_other,bglog
#!/bin/bash
#set -x
remote="$1"
mountpoint="${2%%/}"
shift 2
rclone="/home/deex/rclone/rclone"
method=mount
args=""
bglog=no
export PATH=/bin:/usr/bin
export RCLONE_CONFIG="/etc/rclone/rclone.conf"
export RCLONE_VERBOSE=0
# --daemon --daemon-timeout=30s
export RCLONE_DAEMON=true
export RCLONE_DAEMON_TIMEOUT=30s
export RCLONE_CACHE_DIR="/var/cache/rclone"
unset RCLONE_VFS_CACHE_MODE
unset RCLONE_DIR_CACHE_TIME
unset RCLONE_UID
unset RCLONE_GID
unset RCLONE_ALLOW_ROOT
unset RCLONE_ALLOW_OTHER
# Process -o parameters
while getopts :o: opts; do
if [ "$opts" != "o" ]; then
echo "invalid option: -${OPTARG}"
continue
fi
params=${OPTARG//,/ }
for param in $params; do
case "$param" in
# generic mount options
rw|ro|dev|nodev|suid|nosuid|exec|noexec|auto|noauto|user)
continue ;;
# systemd options
_netdev|nofail|x-systemd.*)
continue ;;
# wrapper options
proxy=*)
export http_proxy=${param#*=}
export https_proxy=${param#*=} ;;
config=*)
export RCLONE_CONFIG=${param#*=} ;;
verbose=*)
export RCLONE_VERBOSE=${param#*=} ;;
method=*)
method=${param#*=} ;;
bglog*)
bglog=yes ;;
# vfs options
cache-dir=*)
export RCLONE_CACHE_DIR=${param#*=} ;;
vfs-cache-mode=*)
export RCLONE_VFS_CACHE_MODE=${param#*=} ;;
dir-cache-time=*)
export RCLONE_DIR_CACHE_TIME=${param#*=} ;;
# fuse options
uid=*)
export RCLONE_UID=${param#*=} ;;
gid=*)
export RCLONE_GID=${param#*=} ;;
allow_root)
export RCLONE_ALLOW_ROOT=true ;;
allow_other)
export RCLONE_ALLOW_OTHER=true ;;
# other rclone options
*) args="$args --$param" ;;
esac
done
done
if [[ $bglog = yes ]]; then
stamp=$(date "+%y%m%d-%H%M%S")
pid=$$
where=$(basename "$mountpoint")
logfile=/tmp/rclone-${stamp}-${pid}-${where}.log
touch "$logfile"
chmod 666 "$logfile"
# activate verbose background logging
export RCLONE_VERBOSE=1
export RCLONE_LOG_FORMAT="date,time,microseconds"
export RCLONE_LOG_FILE="$logfile"
# deactivate systemd logging in rclone
unset INVOCATION_ID
fi
# shellcheck disable=SC2086
exec "$rclone" "$method" "$remote" "$mountpoint" ${args} </dev/null
#!/bin/bash
#set -x
remote="$1"
mountpoint="${2%%/}"
shift 2
bglog=no
method=mount
rclone="/usr/bin/rclone"
args=""
export PATH=/bin:/usr/bin
export RCLONE_CONFIG="/etc/rclone/rclone.conf"
export RCLONE_VERBOSE=0
export RCLONE_CACHE_DIR="/var/cache/rclone"
unset RCLONE_VFS_CACHE_MODE
unset RCLONE_DIR_CACHE_TIME
unset RCLONE_UID
unset RCLONE_GID
unset RCLONE_ALLOW_ROOT
unset RCLONE_ALLOW_OTHER
# Process -o parameters
while getopts :o: opts; do
if [ "$opts" != "o" ]; then
echo "invalid option: -${OPTARG}"
continue
fi
params=${OPTARG//,/ }
for param in $params; do
case "$param" in
# generic mount options
rw|ro|dev|nodev|suid|nosuid|exec|noexec|auto|noauto|user)
continue ;;
# systemd options
_netdev|nofail|x-systemd.*)
continue ;;
# wrapper options
proxy=*)
export http_proxy=${param#*=}
export https_proxy=${param#*=} ;;
config=*)
export RCLONE_CONFIG=${param#*=} ;;
verbose=*)
export RCLONE_VERBOSE=${param#*=} ;;
method=*)
method=${param#*=} ;;
bglog)
bglog=yes ;;
# vfs options
cache-dir=*)
export RCLONE_CACHE_DIR=${param#*=} ;;
vfs-cache-mode=*)
export RCLONE_VFS_CACHE_MODE=${param#*=} ;;
dir-cache-time=*)
export RCLONE_DIR_CACHE_TIME=${param#*=} ;;
# fuse options
uid=*)
export RCLONE_UID=${param#*=} ;;
gid=*)
export RCLONE_GID=${param#*=} ;;
allow_root)
export RCLONE_ALLOW_ROOT=true ;;
allow_other)
export RCLONE_ALLOW_OTHER=true ;;
# other rclone options
*) args="$args --$param" ;;
esac
done
done
if [[ $bglog = yes ]]; then
stamp=$(date '+%y%m%d-%H%M%S')
pid=$$
where=$(basename "$mountpoint")
logfile=/tmp/rclone-${stamp}-${pid}-${where}.log
touch "$logfile"
chmod 666 "$logfile"
# activate verbose background logging
export RCLONE_VERBOSE=3
export RCLONE_LOG_FORMAT=date,time,microseconds
export RCLONE_LOG_FILE=$logfile
# deactivate systemd log flavor in rclone
unset INVOCATION_ID
fi
# NOTE: --daemon hangs under systemd automount, using `&`
# shellcheck disable=SC2086
"$rclone" "$method" "$remote" "$mountpoint" ${args} </dev/null >&/dev/null &
while [[ $(grep -c " ${mountpoint} fuse.rclone " /proc/mounts) = 0 ]]; do
sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment