73 lines
2 KiB
Bash
73 lines
2 KiB
Bash
#!/usr/bin/env sh
|
|
|
|
### Variables
|
|
TYPE="$1"
|
|
USER="$2"
|
|
MOUNT="$3"
|
|
|
|
### Path definitions
|
|
if [ "$TYPE" = 'user' ]; then
|
|
if [ -d /Applications ] && [ -d /System ]; then
|
|
USER_FOLDER='Users'
|
|
else
|
|
USER_FOLDER='home'
|
|
fi
|
|
CACHE_FOLDER="/$USER_FOLDER/$USER/.cache/rclone"
|
|
CONFIG_FOLDER="/$USER_FOLDER/$USER/.config/rclone"
|
|
LOG_FOLDER="/$USER_FOLDER/$USER/.local/log"
|
|
LOG_FILE="$LOG_FOLDER/$MOUNT.log"
|
|
MOUNT_PATH="/$USER_FOLDER/$USER/.local/mnt/$MOUNT"
|
|
else
|
|
CACHE_FOLDER="/var/cache/rclone/$MOUNT"
|
|
CONFIG_FOLDER="/etc"
|
|
LOG_FOLDER="/var/log/rclone"
|
|
LOG_FILE="$LOG_FOLDER/$MOUNT.log"
|
|
if [ -d /Applications ] && [ -d /System ]; then
|
|
MNT_FOLDER='Volumes'
|
|
else
|
|
MNT_FOLDER='mnt'
|
|
fi
|
|
MOUNT_PATH="/$MNT_FOLDER/$MOUNT"
|
|
fi
|
|
|
|
### Ensure folders exist
|
|
for FOLDER in "$CACHE_FOLDER" "$CONFIG_FOLDER" "$LOG_FOLDER" "$MOUNT_PATH"; do
|
|
if [ ! -d "$FOLDER" ]; then
|
|
sudo mkdir -p "$FOLDER" || echo "ERROR: Need permissions for $FOLDER"
|
|
sudo chmod 755 "$FOLDER"
|
|
sudo chown -Rf rclone:rclone "$FOLDER"
|
|
fi
|
|
done
|
|
|
|
### Define rcloneignore location
|
|
RCLONE_IGNORE="$CONFIG_FOLDER/rcloneignore"
|
|
if [ ! -f "$RCLONE_IGNORE" ] && [ -f "/etc/rcloneignore" ]; then
|
|
RCLONE_IGNORE='/etc/rcloneignore'
|
|
fi
|
|
|
|
### Mount
|
|
MOUNT_LOWERCASE="$(echo "$MOUNT" | tr "[:upper:]" "[:lower:]")"
|
|
unset AWS_CA_BUNDLE
|
|
export PATH="$PATH:/usr/local/bin:/usr/bin"
|
|
sudo rclone --config="$CONFIG_FOLDER/rclone.conf" \
|
|
mount \
|
|
--cache-tmp-upload-path="$CACHE_FOLDER/$MOUNT-upload" \
|
|
--cache-chunk-path="$CACHE_FOLDER/$MOUNT-chunks" \
|
|
--cache-workers=8 \
|
|
--cache-writes \
|
|
--cache-dir="$CACHE_FOLDER/$MOUNT-vfs" \
|
|
--cache-db-path="$CACHE_FOLDER/$MOUNT-db" \
|
|
--daemon \
|
|
--noapplexattr \
|
|
--log-file="$LOG_FILE" \
|
|
--no-modtime \
|
|
--drive-use-trash \
|
|
--stats=0 \
|
|
--checkers=16 \
|
|
--bwlimit=40M \
|
|
--dir-cache-time=60m \
|
|
--vfs-cache-mode full \
|
|
--volname "$MOUNT" \
|
|
--cache-info-age=60m \
|
|
--filter-from="$RCLONE_IGNORE" \
|
|
"$MOUNT_LOWERCASE":"$MOUNT_LOWERCASE" "$MOUNT_PATH"
|