Created
March 4, 2025 07:48
-
-
Save nikurasutan/a10b0f04a6e5e3f16f12dd8c1da61e02 to your computer and use it in GitHub Desktop.
Rclone Systemd Service and Controll Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install gum if not already installed | |
if ! command -v gum &> /dev/null | |
then | |
echo "gum could not be found. Installing gum..." | |
go install github.com/charmbracelet/gum@latest | |
fi | |
# Get the list of rclone remotes | |
remotes=$(rclone listremotes | sed 's/:/ /') | |
# Display the remotes in a choosing dialogue | |
selected_remote=$(echo "$remotes" | gum choose --cursor="➜ " --header="Select a remote") | |
if [ -z "$selected_remote" ]; then | |
echo "Aborted." | |
exit 0 | |
fi | |
echo "You selected: $selected_remote" | |
# Mount the selected remote | |
echo "Mounting $selected_remote..." | |
systemctl --user start rclone@$selected_remote |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
selected_unit=$(systemctl --user list-units --type=service --no-pager --no-legend | awk '{print $1}' | grep rclone@ | gum choose) | |
echo $selected_unit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=rclone: Remote FUSE filesystem for cloud storage config %i | |
Documentation=man:rclone(1) | |
After=network-online.target | |
Wants=network-online.target | |
[Service] | |
Type=notify | |
ExecStartPre=-/usr/bin/mkdir -p %h/Drives/%i | |
ExecStart= \ | |
/home/linuxbrew/.linuxbrew/bin/rclone mount \ | |
--config=%h/.config/rclone/rclone.conf \ | |
--vfs-cache-mode writes \ | |
--vfs-cache-max-size 500M \ | |
--log-level INFO \ | |
--log-file /tmp/rclone-%i.log \ | |
--umask 022 \ | |
--allow-other \ | |
%i: %h/Drives/%i | |
ExecStop=/usr/bin/bash -c "/usr/bin/fusermount -u %h/Drives/%i && /usr/bin/rm -rf %h/Drives/%i" | |
[Install] | |
WantedBy=default.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment