Sync fixed

This commit is contained in:
2023-04-09 20:46:09 +02:00
parent a2bdf977d9
commit 22b71a2f59

View File

@@ -2,18 +2,41 @@
# To-do: Add Eww widgets or other interface # To-do: Add Eww widgets or other interface
theme="~/Scripts/Temas/" theme="~/Scripts/rofi/"
server_routes=("Anotaciones" "Universidad/Segundo[[:space:]]Cuatrimestre/" "Universidad/TFG/") 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")" ask_what_to_sync(){
case "$net" in 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"
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")"
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 case "$operation" in
PUSH) PUSH)
origin="/home/danih/" origin="/home/danih/"
@@ -24,34 +47,27 @@ case "$net" in
origin="dqnid@192.168.0.109:/home/dqnid/" origin="dqnid@192.168.0.109:/home/dqnid/"
;; ;;
esac 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 case "$files_to_sync" in
Documents | Images | Videos | Music) Documents)
for dir in "$origin$files_to_sync"/* for dir in "${docs[@]}"
rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after $origin/$dir $dest/$dir
;;
Dotfiles)
for i in "${dotfiles[@]}"
do do
rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after $origin/$i $dest/$i rsync -vrP -e "ssh -i ~/.ssh/id_local" --delete-after $origin/$dir $dest/$dir
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 done
;; ;;
esac Images)
;; for dir in "${images[@]}"
WAN)
for i in "${server_routes[@]}"
do do
rsync -vrP -e "ssh -i ~/.ssh/id_rsa_dqnid" --delete-after /home/danih/Documents/$i dqnid@dqnid.com:/home/dqnid/Documents rsync -vrP -e "ssh -i ~/.ssh/id_local" --delete-after $origin/$dir $dest/$dir
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 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 esac
fi