From 22b71a2f59da068c986b8323b8b9aa2552439e48 Mon Sep 17 00:00:00 2001 From: dqnid Date: Sun, 9 Apr 2023 20:46:09 +0200 Subject: [PATCH] Sync fixed --- System/sincV8.sh | 112 +++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/System/sincV8.sh b/System/sincV8.sh index 012141e..4465d83 100755 --- a/System/sincV8.sh +++ b/System/sincV8.sh @@ -2,56 +2,72 @@ # To-do: Add Eww widgets or other interface -theme="~/Scripts/Temas/" +theme="~/Scripts/rofi/" server_routes=("Anotaciones" "Universidad/Segundo[[:space:]]Cuatrimestre/" "Universidad/TFG/") -local_full=("Documents/Anotaciones/" "Documents/Proyectos/" "Documents/Universidad/" "Images/Carteles[[:space:]]OZ/" "Images/Proyectos/") +images=("Images/Carteles[[:space:]]OZ/" "Images/Proyectos/" "Images/Croquis[[:space:]]Heras[[:space:]]C.B") +docs=("Documents/Anotaciones/" "Documents/Proyectos/" "Documents/Universidad/") +music="Music/" +videos=("Videos/Proyectos/") -dotfiles=(".bashrc" ".config/nvim/" ".config/polybar/" ".config/i3/" ".config/mpd/" ".config/ncmpcpp/" ".config/mpv/" ".config/nemo/" ".config/dunst/" ".config/glava/" ".config/ranger/" ".config/sxhkd/" ".config/picom.conf") +ask_operation(){ + rofi -no-config -no-lazy-grab -sep "|" -dmenu -i -p 'Action' -width 12 -line-padding 3 -lines 2 -theme /home/danih/Scripts/rofi/sinc.rasi <<< "PUSH|PULL" +} +ask_net(){ + rofi -no-config -no-lazy-grab -sep "|" -dmenu -i -p 'Network' -width 12 -line-padding 3 -lines 2 -theme /home/danih/Scripts/rofi/sinc.rasi <<< "LAN|WAN" +} -net="$(rofi -no-config -no-lazy-grab -sep "|" -dmenu -i -p 'Network' -width 12 -line-padding 3 -lines 2 -theme /home/danih/Scripts/Temas/sinc.rasi <<< "LAN|WAN")" -case "$net" in - LAN) - operation="$(rofi -no-config -no-lazy-grab -sep "|" -dmenu -i -p 'Action' -width 12 -line-padding 3 -lines 2 -theme /home/danih/Scripts/Temas/sinc.rasi <<< "PUSH|PULL")" - case "$operation" in - PUSH) - origin="/home/danih/" - dest="dqnid@192.168.0.109:/home/dqnid/" - ;; - PULL) - dest="/home/danih/" - origin="dqnid@192.168.0.109:/home/dqnid/" - ;; - esac - files_to_sync="$(rofi -no-config -no-lazy-grab -sep "|" -dmenu -i -p 'Files To Sync' -width 12 -line-padding 3 -lines 2 -theme /home/danih/Scripts/Temas/sinc.rasi <<< "Documents|Images|Videos|Music|Dotfiles|All")" - case "$files_to_sync" in - Documents | Images | Videos | Music) - for dir in "$origin$files_to_sync"/* - rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after $origin/$dir $dest/$dir - ;; - Dotfiles) - for i in "${dotfiles[@]}" - do - rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after $origin/$i $dest/$i - if test $? -eq 0; then - notify-send "Éxito - $i" "$i sincronizadas correctamente" - else - notify-send "Error - $i" "Fallo en sincronización de $i" - fi - done - ;; - esac - ;; - WAN) - for i in "${server_routes[@]}" - do - rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after /home/danih/Documents/$i dqnid@dqnid.com:/home/dqnid/Documents - if test $? -eq 0; then - notify-send "Éxito - $i" "$i sincronizadas correctamente" - else - notify-send "Error - $i" "Fallo en sincronización de $i" - fi - done - ;; -esac +ask_what_to_sync(){ + rofi -no-config -no-lazy-grab -sep "|" -dmenu -i -p 'Files To Sync' -width 12 -line-padding 3 -lines 2 -theme /home/danih/Scripts/rofi/sinc.rasi <<< "Full|Documents|Images|Videos|Music" +} + +net=$(ask_net &) +operation=$(ask_operation &) +files_to_sync=$(ask_what_to_sync &) +if test "$net" == "WAN"; then + for i in "${server_routes[@]}" + do + rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after /home/danih/Documents/$i dqnid@dqnid.com:/home/dqnid/Documents + if test $? -eq 0; then + notify-send "Éxito - $i" "$i sincronizadas correctamente" + else + notify-send "Error - $i" "Fallo en sincronización de $i" + fi + done + exit 0 +else + case "$operation" in + PUSH) + origin="/home/danih/" + dest="dqnid@192.168.0.109:/home/dqnid/" + ;; + PULL) + dest="/home/danih/" + origin="dqnid@192.168.0.109:/home/dqnid/" + ;; + esac + case "$files_to_sync" in + Documents) + for dir in "${docs[@]}" + do + rsync -vrP -e "ssh -i ~/.ssh/id_local" --delete-after $origin/$dir $dest/$dir + done + ;; + Images) + for dir in "${images[@]}" + do + rsync -vrP -e "ssh -i ~/.ssh/id_local" --delete-after $origin/$dir $dest/$dir + done + ;; + Videos) + for dir in "${videos[@]}" + do + rsync -vrP -e "ssh -i ~/.ssh/id_local" --delete-after $origin/$dir $dest/$dir + done + ;; + Music) + rsync -vrP -e "ssh -i ~/.ssh/id_local" --delete-after $origin/Music/ $dest/Music/ + ;; + esac +fi