2023-01-28 22:07:01 -08:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
### Variables
|
|
|
|
TYPE="$1"
|
|
|
|
USER="$2"
|
|
|
|
MOUNT="$3"
|
2023-01-29 19:09:02 -08:00
|
|
|
|
2023-08-30 14:01:07 -07:00
|
|
|
### Mount variables
|
|
|
|
if [ "$TYPE" = 'user' ]; then
|
|
|
|
MOUNT_REF="$USER-$MOUNT"
|
|
|
|
MOUNT_LOWERCASE="user/$USER-$MOUNT"
|
|
|
|
else
|
|
|
|
MOUNT_REF="$MOUNT"
|
|
|
|
MOUNT_LOWERCASE="$(echo "$MOUNT" | tr "[:upper:]" "[:lower:]")"
|
|
|
|
fi
|
|
|
|
|
2023-01-29 19:09:02 -08:00
|
|
|
### Path definitions
|
2023-01-28 22:07:01 -08:00
|
|
|
if [ "$TYPE" = 'user' ]; then
|
2023-04-18 22:15:21 -07:00
|
|
|
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"
|
2023-08-29 19:55:40 -07:00
|
|
|
LOG_FOLDER="/$USER_FOLDER/$USER/.local/share/rclone"
|
2023-01-28 22:07:01 -08:00
|
|
|
LOG_FILE="$LOG_FOLDER/$MOUNT.log"
|
2023-04-18 22:15:21 -07:00
|
|
|
MOUNT_PATH="/$USER_FOLDER/$USER/.local/mnt/$MOUNT"
|
2023-01-28 22:07:01 -08:00
|
|
|
else
|
2023-01-29 19:09:02 -08:00
|
|
|
CACHE_FOLDER="/var/cache/rclone/$MOUNT"
|
2023-01-28 22:07:01 -08:00
|
|
|
CONFIG_FOLDER="/etc"
|
|
|
|
LOG_FOLDER="/var/log/rclone"
|
|
|
|
LOG_FILE="$LOG_FOLDER/$MOUNT.log"
|
2023-04-18 22:15:21 -07:00
|
|
|
if [ -d /Applications ] && [ -d /System ]; then
|
|
|
|
MNT_FOLDER='Volumes'
|
|
|
|
else
|
|
|
|
MNT_FOLDER='mnt'
|
|
|
|
fi
|
|
|
|
MOUNT_PATH="/$MNT_FOLDER/$MOUNT"
|
2023-01-28 22:07:01 -08:00
|
|
|
fi
|
|
|
|
|
2023-01-29 19:09:02 -08:00
|
|
|
### Ensure folders exist
|
|
|
|
for FOLDER in "$CACHE_FOLDER" "$CONFIG_FOLDER" "$LOG_FOLDER" "$MOUNT_PATH"; do
|
|
|
|
if [ ! -d "$FOLDER" ]; then
|
2023-11-27 15:04:02 -08:00
|
|
|
mkdir -p "$FOLDER" || sudo mkdir -p "$FOLDER"
|
2023-07-16 03:10:04 -07:00
|
|
|
sudo chmod 755 "$FOLDER"
|
2023-11-26 22:46:35 -08:00
|
|
|
if command -v own > /dev/null; then
|
|
|
|
sudo own "$FOLDER"
|
|
|
|
else
|
|
|
|
sudo chown -Rf rclone:rclone "$FOLDER" 2> /dev/null || sudo chown -Rf rclone:$(id -g -n) "$FOLDER"
|
|
|
|
fi
|
2023-01-29 19:09:02 -08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
### Define rcloneignore location
|
2023-01-28 22:07:01 -08:00
|
|
|
RCLONE_IGNORE="$CONFIG_FOLDER/rcloneignore"
|
|
|
|
if [ ! -f "$RCLONE_IGNORE" ] && [ -f "/etc/rcloneignore" ]; then
|
2023-04-18 22:15:21 -07:00
|
|
|
RCLONE_IGNORE='/etc/rcloneignore'
|
2023-01-28 22:07:01 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
### Mount
|
2023-07-16 03:10:04 -07:00
|
|
|
unset AWS_CA_BUNDLE
|
|
|
|
export PATH="$PATH:/usr/local/bin:/usr/bin"
|
2023-07-30 22:31:48 -07:00
|
|
|
# TODO: Only launch with --rc-web-gui if the servers hostname is the {{ .kubernetesHost }}
|
|
|
|
# TODO: Add more secure authentication method
|
2023-07-30 22:33:06 -07:00
|
|
|
sudo rclone --config "$CONFIG_FOLDER/rclone.conf" \
|
2023-01-28 22:07:01 -08:00
|
|
|
mount \
|
2023-07-30 22:31:48 -07:00
|
|
|
--allow-other \
|
|
|
|
--buffer-size 4G \
|
2023-07-30 22:33:06 -07:00
|
|
|
--bwlimit 40M \
|
2023-08-29 19:55:40 -07:00
|
|
|
--cache-chunk-path "$CACHE_FOLDER/$MOUNT_REF-chunks" \
|
|
|
|
--cache-db-path "$CACHE_FOLDER/$MOUNT_REF-db" \
|
|
|
|
--cache-dir "$CACHE_FOLDER/$MOUNT_REF-vfs" \
|
2023-07-30 22:33:06 -07:00
|
|
|
--cache-info-age 60m \
|
2023-08-29 19:55:40 -07:00
|
|
|
--cache-tmp-upload-path "$CACHE_FOLDER/$MOUNT_REF-upload" \
|
2023-07-30 22:33:06 -07:00
|
|
|
--cache-workers 8 \
|
2023-01-28 22:07:01 -08:00
|
|
|
--cache-writes \
|
2023-07-30 22:33:06 -07:00
|
|
|
--checkers 16 \
|
2023-07-30 22:31:48 -07:00
|
|
|
--dir-cache-time 24h \
|
2023-07-30 22:33:06 -07:00
|
|
|
--dir-cache-time 60m \
|
2023-07-30 22:31:48 -07:00
|
|
|
--drive-use-trash \
|
2023-07-30 22:33:06 -07:00
|
|
|
--exclude-from "$RCLONE_IGNORE" \
|
|
|
|
--log-file "$LOG_FILE" \
|
2023-07-30 22:42:42 -07:00
|
|
|
--log-level INFO \
|
2023-01-28 22:07:01 -08:00
|
|
|
--no-modtime \
|
2023-07-30 22:31:48 -07:00
|
|
|
--noapplexattr \
|
2023-07-30 22:54:25 -07:00
|
|
|
--poll-interval 15s \
|
2023-07-30 22:33:06 -07:00
|
|
|
--stats 0 \
|
2023-07-30 22:31:48 -07:00
|
|
|
--vfs-cache-max-age 1000h \
|
2023-11-03 22:14:30 -07:00
|
|
|
--vfs-cache-max-size 5G \
|
2023-01-28 22:07:01 -08:00
|
|
|
--vfs-cache-mode full \
|
2023-11-03 22:14:30 -07:00
|
|
|
--vfs-cache-poll-interval 30s \
|
2023-07-30 22:31:48 -07:00
|
|
|
--vfs-fast-fingerprint \
|
|
|
|
--vfs-read-ahead 128M \
|
|
|
|
--vfs-read-chunk-size 16M \
|
|
|
|
--vfs-read-chunk-size-limit 128M \
|
2023-08-29 19:55:40 -07:00
|
|
|
--volname "$MOUNT_REF" \
|
|
|
|
"$MOUNT_REF":"$MOUNT_LOWERCASE" "$MOUNT_PATH"
|