rclone_mount.sh hinzugefügt
This commit is contained in:
96
rclone_mount.sh
Normal file
96
rclone_mount.sh
Normal file
@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
MOUNT_BASE="$HOME/SYM"
|
||||
declare -A REMOTES
|
||||
|
||||
while IFS= read -r remote; do
|
||||
remote="${remote%:}"
|
||||
REMOTES["$remote"]="$MOUNT_BASE/$remote"
|
||||
done < <(rclone listremotes)
|
||||
|
||||
if [[ ${#REMOTES[@]} -eq 0 ]]; then
|
||||
echo "Keine rclone-Remotes gefunden. Abbruch."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
is_mounted() {
|
||||
mountpoint -q "${REMOTES[$1]}"
|
||||
}
|
||||
|
||||
status_dot() {
|
||||
is_mounted "$1" && echo "🟢" || echo "🔴"
|
||||
}
|
||||
|
||||
mount_remote() {
|
||||
local remote=$1
|
||||
local mount_path="${REMOTES[$remote]}"
|
||||
|
||||
if is_mounted "$remote"; then
|
||||
gum style --foreground 212 "⚠️ ${remote} ist bereits gemountet unter ${mount_path}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p "$mount_path"
|
||||
gum spin --title "Mounting ${remote}..." -- rclone mount \
|
||||
--vfs-cache-mode full \
|
||||
--dir-cache-time 1h \
|
||||
--daemon \
|
||||
"$remote": "$mount_path"
|
||||
|
||||
if is_mounted "$remote"; then
|
||||
gum style --foreground 10 "✅ ${remote} wurde erfolgreich gemountet unter ${mount_path}"
|
||||
else
|
||||
gum style --foreground 9 "❌ Fehler beim Mounten von ${remote}. Bitte rclone-Log prüfen."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
unmount_remote() {
|
||||
local remote=$1
|
||||
local mount_path="${REMOTES[$remote]}"
|
||||
|
||||
if ! is_mounted "$remote"; then
|
||||
gum style --foreground 212 "⚠️ ${remote} ist nicht gemountet."
|
||||
return 0
|
||||
fi
|
||||
|
||||
gum spin --title "Unmounting ${remote}..." -- fusermount -u "$mount_path"
|
||||
|
||||
if ! is_mounted "$remote"; then
|
||||
gum style --foreground 10 "✅ ${remote} wurde erfolgreich ungemountet."
|
||||
else
|
||||
gum style --foreground 9 "❌ Fehler beim Unmounten von ${remote}."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
unmount_all() {
|
||||
local any_mounted=false
|
||||
for remote in "${!REMOTES[@]}"; do
|
||||
if is_mounted "$remote"; then
|
||||
any_mounted=true
|
||||
unmount_remote "$remote"
|
||||
fi
|
||||
done
|
||||
if ! $any_mounted; then
|
||||
gum style --foreground 212 "⚠️ Keine Remotes gemountet."
|
||||
fi
|
||||
}
|
||||
|
||||
while true; do
|
||||
menu_items=()
|
||||
for remote in "${!REMOTES[@]}"; do
|
||||
menu_items+=("$(status_dot "$remote") ${remote}")
|
||||
done
|
||||
menu_items+=("⏏️ Alle Remotes trennen" "Beenden")
|
||||
|
||||
choice=$(gum choose --header "🚀 rclone Mount-Menü" "${menu_items[@]}")
|
||||
|
||||
case "$choice" in
|
||||
"⏏️ Alle Remotes trennen") unmount_all ;;
|
||||
"Beenden") exit 0 ;;
|
||||
*)
|
||||
selected="${choice#* }"
|
||||
is_mounted "$selected" && unmount_remote "$selected" || mount_remote "$selected"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Reference in New Issue
Block a user