2023-01-28 22:07:01 -08:00
|
|
|
{{- if ne .host.distro.family "windows" -}}
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
2023-01-29 20:44:55 -08:00
|
|
|
if command -v rclone > /dev/null; then
|
2023-01-28 22:07:01 -08:00
|
|
|
logg info 'Ensuring /var/cache/rclone exists'
|
|
|
|
sudo mkdir -p /var/cache/rclone
|
|
|
|
sudo chmod 700 /var/cache/rclone
|
2023-01-29 20:44:55 -08:00
|
|
|
sudo chown -Rf rclone:rclone /var/cache/rclone
|
2023-01-28 22:07:01 -08:00
|
|
|
|
2023-01-28 22:55:46 -08:00
|
|
|
logg info 'Ensuring /var/log/rclone exists'
|
|
|
|
sudo mkdir -p /var/log/rclone
|
|
|
|
sudo chmod 700 /var/log/rclone
|
2023-01-29 20:44:55 -08:00
|
|
|
sudo chown -Rf rclone:rclone /var/log/rclone
|
2023-01-28 22:07:01 -08:00
|
|
|
|
|
|
|
logg info 'Adding ~/.local/bin/rclone-mount to /usr/local/bin'
|
|
|
|
sudo cp -f "$HOME/.local/bin/rclone-mount" /usr/local/bin/rclone-mount
|
|
|
|
sudo chmod +x /usr/local/bin/rclone-mount
|
|
|
|
|
2023-01-28 22:55:46 -08:00
|
|
|
logg info 'Adding ~/.config/rclone/rcloneignore to /etc/rcloneignore'
|
|
|
|
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/rcloneignore" /etc/rcloneignore
|
|
|
|
sudo chmod 644 /etc/rcloneignore
|
|
|
|
|
2023-01-29 20:44:55 -08:00
|
|
|
logg info 'Adding ~/.config/rclone/system-rclone.conf to /etc/rclone.conf'
|
2023-01-31 22:02:56 -08:00
|
|
|
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/system-rclone.conf" /etc/rclone.conf
|
2023-01-28 22:07:01 -08:00
|
|
|
|
2023-01-29 20:44:55 -08:00
|
|
|
### Add / configure service files
|
|
|
|
if [ -d /etc/systemd/system ]; then
|
|
|
|
find "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/system" -mindepth 1 -maxdepth 1 -type f | while read RCLONE_SERVICE; do
|
|
|
|
### Add systemd service file
|
|
|
|
logg info "Adding S3 system mount service defined at $RCLONE_SERVICE"
|
|
|
|
FILENAME="$(basename "$RCLONE_SERVICE")"
|
|
|
|
SERVICE_ID="$(echo "$FILENAME" | sed 's/.service//')"
|
|
|
|
sudo cp -f "$RCLONE_SERVICE" "/etc/systemd/system/$(basename "$RCLONE_SERVICE")"
|
|
|
|
|
|
|
|
### Ensure mount folder is created
|
|
|
|
logg info "Ensuring /mnt/$SERVICE_ID is created with proper permissions"
|
|
|
|
sudo mkdir -p "/mnt/$SERVICE_ID"
|
|
|
|
sudo chmod 770 "/mnt/$SERVICE_ID"
|
|
|
|
sudo chown -Rf rclone:rclone "/mnt/$SERVICE_ID"
|
|
|
|
|
|
|
|
### Enable / restart the service
|
2023-01-31 22:02:56 -08:00
|
|
|
logg info "Enabling / restarting the $SERVICE_ID S3 service"
|
2023-01-29 20:44:55 -08:00
|
|
|
sudo systemctl enable "$SERVICE_ID"
|
|
|
|
sudo systemctl restart "$SERVICE_ID"
|
|
|
|
done
|
|
|
|
|
|
|
|
### Add user Rclone mount
|
2023-01-28 22:55:46 -08:00
|
|
|
logg info 'Adding user S3 rclone mount (available at ~/.local/mnt/s3)'
|
|
|
|
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/rclone/s3-user.service" "/etc/systemd/system/${USER}-s3.service"
|
|
|
|
logg info 'Enabling / restarting the S3 user mount'
|
|
|
|
sudo systemctl enable "${USER}-s3"
|
|
|
|
sudo systemctl restart "${USER}-s3"
|
|
|
|
fi
|
2023-01-28 22:07:01 -08:00
|
|
|
else
|
|
|
|
logg info '`rclone` is not available'
|
|
|
|
fi
|
|
|
|
|
|
|
|
{{ end -}}
|