hyprland-dotfiles/.install/restore.sh

334 lines
15 KiB
Bash
Raw Normal View History

2023-11-10 21:12:15 +00:00
# ------------------------------------------------------
# Restore
# ------------------------------------------------------
2023-11-22 11:01:41 +00:00
restorelist=""
2023-12-07 08:36:08 +00:00
selectedlist=""
2023-11-26 10:57:21 +00:00
monitorrestored=0
2023-11-22 11:01:41 +00:00
_showRestoreOptions() {
2023-11-26 14:52:49 +00:00
echo "The following configurations can be transferred into the new installation."
2023-11-22 11:01:41 +00:00
echo "(SPACE = select/unselect a profile. RETURN = confirm. No selection = CANCEL)"
2023-11-10 21:12:15 +00:00
echo ""
2023-11-22 11:01:41 +00:00
restorelist=""
2023-11-10 21:12:15 +00:00
if [ -f ~/dotfiles/.bashrc ]; then
2023-11-22 11:01:41 +00:00
restorelist+="~/dotfiles/.bashrc "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/.bashrc,"
2023-11-10 21:12:15 +00:00
fi
2023-12-06 20:00:34 +00:00
if [ -d ~/dotfiles/.settings ]; then
restorelist+="~/dotfiles/.settings "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/.settings,"
2023-12-06 20:00:34 +00:00
fi
2023-11-21 20:19:51 +00:00
if [[ $profile == *"Hyprland"* ]]; then
2023-12-10 13:30:53 +00:00
if [ -f ~/dotfiles/hypr/conf/custom.conf ]; then
restorelist+="~/dotfiles/hypr/conf/custom.conf "
selectedlist+="~/dotfiles/hypr/conf/custom.conf,"
fi
2023-11-10 21:12:15 +00:00
if [ -f ~/dotfiles/hypr/conf/keyboard.conf ]; then
2023-11-22 11:01:41 +00:00
restorelist+="~/dotfiles/hypr/conf/keyboard.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/keyboard.conf,"
2023-11-10 21:12:15 +00:00
fi
2023-11-27 07:57:38 +00:00
if [ -f ~/dotfiles/hypr/conf/keybinding.conf ] && [ -d ~/dotfiles/hypr/conf/keybindings/ ]; then
restorelist+="~/dotfiles/hypr/conf/keybinding.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/keybinding.conf,"
2023-11-27 07:57:38 +00:00
fi
if [ -f ~/dotfiles/hypr/conf/environment.conf ] && [ -d ~/dotfiles/hypr/conf/environments/ ]; then
restorelist+="~/dotfiles/hypr/conf/environment.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/environment.conf,"
2023-11-27 07:57:38 +00:00
fi
if [ -f ~/dotfiles/hypr/conf/windowrule.conf ] && [ -d ~/dotfiles/hypr/conf/windowrules/ ]; then
restorelist+="~/dotfiles/hypr/conf/windowrule.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/windowrule.conf,"
2023-11-22 11:01:41 +00:00
fi
2023-11-24 12:58:59 +00:00
if [ -f ~/dotfiles/hypr/conf/monitor.conf ] && [ -d ~/dotfiles/hypr/conf/monitors/ ]; then
2023-11-22 11:01:41 +00:00
restorelist+="~/dotfiles/hypr/conf/monitor.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/monitor.conf,"
2023-11-22 11:01:41 +00:00
fi
2023-11-24 12:58:59 +00:00
if [ -f ~/dotfiles/hypr/conf/animation.conf ] && [ -d ~/dotfiles/hypr/conf/animations/ ]; then
2023-11-22 11:01:41 +00:00
restorelist+="~/dotfiles/hypr/conf/animation.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/animation.conf,"
2023-11-22 11:01:41 +00:00
fi
if [ -f ~/dotfiles/hypr/conf/decoration.conf ] && [ -d ~/dotfiles/hypr/conf/decorations/ ]; then
restorelist+="~/dotfiles/hypr/conf/decoration.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/decoration.conf,"
2023-11-22 11:01:41 +00:00
fi
if [ -f ~/dotfiles/hypr/conf/window.conf ] && [ -d ~/dotfiles/hypr/conf/windows/ ]; then
restorelist+="~/dotfiles/hypr/conf/window.conf "
2023-12-07 08:36:08 +00:00
selectedlist+="~/dotfiles/hypr/conf/window.conf,"
2023-11-10 21:12:15 +00:00
fi
fi
2023-11-21 20:19:51 +00:00
if [[ $profile == *"Qtile"* ]]; then
2023-12-20 10:05:15 +00:00
if [ -f ~/dotfiles/qtile/autostart.sh ]; then
restorelist+="~/dotfiles/qtile/autostart.sh "
selectedlist+="~/dotfiles/qtile/autostart.sh,"
2023-11-26 11:30:31 +00:00
fi
2023-11-10 21:12:15 +00:00
fi
2023-12-07 08:36:08 +00:00
restoreselect=$(gum choose --no-limit --height 20 --cursor-prefix "( ) " --selected-prefix "(x) " --unselected-prefix "( ) " --selected="$selectedlist" $restorelist)
2023-11-22 11:01:41 +00:00
if [ ! -z "$restoreselect" ] ;then
echo "Selected to restore:"
echo "$restoreselect"
echo ""
confirmrestore=$(gum choose "Start restore" "Change restore" "Cancel restore")
if [ "$confirmrestore" == "Start restore" ] ;then
_startRestore
elif [ "$confirmrestore" == "Change restore" ]; then
_showRestoreOptions
else
echo "Restore skipped."
return 0
2023-11-21 20:19:51 +00:00
fi
2023-11-20 21:11:39 +00:00
else
2023-11-22 11:01:41 +00:00
echo "No files selected to restore."
confirmrestore=$(gum choose "Change restore" "Cancel restore")
2024-02-19 17:14:24 +00:00
if [ -z "${confirmrestore}" ] ;then
echo "Installation canceled."
exit
fi
2023-11-22 11:01:41 +00:00
if [ "$confirmrestore" == "Change restore" ]; then
echo ""
_showRestoreOptions
else
echo "Restore skipped."
return 0
fi
2023-11-20 21:11:39 +00:00
fi
2023-11-22 11:01:41 +00:00
}
_startRestore() {
if [[ $restoreselect == *"~/dotfiles/.bashrc"* ]] || [[ $restoreselect == *"All"* ]] ; then
2023-11-26 11:30:31 +00:00
if [ -f ~/dotfiles/.bashrc ]; then
cp ~/dotfiles/.bashrc ~/dotfiles-versions/$version/
echo ".bashrc restored!"
fi
2023-11-22 11:01:41 +00:00
fi
2023-12-06 20:00:34 +00:00
if [[ $restoreselect == *"~/dotfiles/.settings"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -d ~/dotfiles/.settings ]; then
rsync -a -I ~/dotfiles/.settings/ ~/dotfiles-versions/$version/.settings/
echo ".settings restored!"
fi
fi
2023-11-26 11:30:31 +00:00
if [[ $profile == *"Hyprland"* ]]; then
2023-12-10 13:30:53 +00:00
if [[ $restoreselect == *"~/dotfiles/hypr/conf/custom.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/custom.conf ]; then
cp ~/dotfiles/hypr/conf/custom.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland custom.conf restored!"
fi
fi
2023-11-26 11:30:31 +00:00
if [[ $restoreselect == *"~/dotfiles/hypr/conf/keyboard.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/keyboard.conf ]; then
cp ~/dotfiles/hypr/conf/keyboard.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland keyboard.conf restored!"
fi
2023-12-10 13:30:53 +00:00
fi
2023-11-26 11:30:31 +00:00
if [[ $restoreselect == *"~/dotfiles/hypr/conf/monitor.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/monitor.conf ]; then
cp ~/dotfiles/hypr/conf/monitor.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland monitor.conf restored!"
fi
fi
2023-11-27 07:57:38 +00:00
if [[ $restoreselect == *"~/dotfiles/hypr/conf/keybinding.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/keybinding.conf ]; then
cp ~/dotfiles/hypr/conf/keybinding.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland keybinding.conf restored!"
2023-11-26 11:30:31 +00:00
fi
fi
2023-11-27 07:57:38 +00:00
if [[ $restoreselect == *"~/dotfiles/hypr/conf/environment.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/environment.conf ]; then
cp ~/dotfiles/hypr/conf/environment.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland environment.conf restored!"
fi
fi
if [[ $restoreselect == *"~/dotfiles/hypr/conf/windowrule.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/windowrule.conf ]; then
cp ~/dotfiles/hypr/conf/windowrule.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland windowrule.conf restored!"
fi
fi
2023-11-26 11:30:31 +00:00
if [[ $restoreselect == *"~/dotfiles/hypr/conf/animation.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/animation.conf ]; then
cp ~/dotfiles/hypr/conf/animation.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland animation.conf restored!"
fi
fi
if [[ $restoreselect == *"~/dotfiles/hypr/conf/decoration.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/decoration.conf ]; then
cp ~/dotfiles/hypr/conf/decoration.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland decoration.conf restored!"
fi
fi
if [[ $restoreselect == *"~/dotfiles/hypr/conf/window.conf"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/hypr/conf/window.conf ]; then
cp ~/dotfiles/hypr/conf/window.conf ~/dotfiles-versions/$version/hypr/conf/
echo "Hyprland window.conf restored!"
fi
fi
2023-11-22 11:01:41 +00:00
fi
2023-11-26 11:30:31 +00:00
if [[ $profile == *"Qtile"* ]]; then
2023-12-21 10:06:51 +00:00
if [[ $restoreselect == *"~/dotfiles/qtile/autostart.sh"* ]] || [[ $restoreselect == *"All"* ]] ; then
if [ -f ~/dotfiles/qtile/autostart.sh ]; then
cp ~/dotfiles/qtile/autostart.sh ~/dotfiles-versions/$version/qtile/
echo "Qtile autostart.sh restored!"
2023-11-26 11:30:31 +00:00
fi
fi
2023-11-22 11:01:41 +00:00
fi
restored=1
return 0
}
if [ -d ~/dotfiles ]; then
echo -e "${GREEN}"
2024-01-01 10:40:15 +00:00
figlet "Restore"
2023-11-22 11:01:41 +00:00
echo -e "${NONE}"
restored=0
echo "The script will try to restore existing configurations."
2024-01-07 14:45:51 +00:00
echo "PLEASE NOTE: Restoring is not possible with version < 2.6 of the dotfiles."
2023-11-22 11:01:41 +00:00
echo "In that case, please use the automated backup or create your own backup manually."
echo ""
_showRestoreOptions
2023-12-27 22:19:24 +00:00
# Restore Waybar Workspaces
targetFile="$HOME/dotfiles-versions/$version/waybar/modules.json"
settingsFile="$HOME/dotfiles/.settings/waybar_workspaces"
if [ -f $settingsFile ] ;then
startMarker="START WORKSPACE"
endMarker="END WORKSPACES"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile"
echo "Waybar Workspaces restored."
fi
# Restore Waybar Appslabel
targetFile="$HOME/dotfiles-versions/$version/waybar/modules.json"
settingsFile="$HOME/dotfiles/.settings/waybar_appslabel"
if [ -f $settingsFile ] ;then
startMarker="START APPS LABEL"
endMarker="END APPS LABEL"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile"
echo "Waybar Appslabel restored."
fi
2024-01-05 17:56:52 +00:00
# Restore Waybar ChatGPT
targetFile="$HOME/dotfiles/waybar/modules.json"
settingsFile="$HOME/dotfiles/.settings/waybar_chatgpt"
if [ -f $settingsFile ] ;then
startMarker="START CHATGPT TOOGLE"
endMarker="END CHATGPT TOOGLE"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile"
echo "Waybar ChatGPT restored."
fi
2023-12-27 22:19:24 +00:00
# Restore Waybar Bluetooth
targetFile1="$HOME/dotfiles-versions/$version/waybar/themes/ml4w/config"
targetFile2="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-blur/config"
targetFile3="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-blur-bottom/config"
targetFile4="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-bottom/config"
2024-01-24 14:40:36 +00:00
targetFile5="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-minimal/config"
2023-12-27 22:19:24 +00:00
settingsFile="$HOME/dotfiles/.settings/waybar_bluetooth"
if [ -f $settingsFile ] ;then
startMarker="START BT TOOGLE"
endMarker="END BT TOOGLE"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile1"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile2"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile3"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile4"
2024-01-24 14:40:36 +00:00
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile5"
2023-12-27 22:19:24 +00:00
echo "Waybar Bluetooth restored."
fi
# Restore Waybar Systray
targetFile1="$HOME/dotfiles-versions/$version/waybar/themes/ml4w/config"
targetFile2="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-blur/config"
targetFile3="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-blur-bottom/config"
targetFile4="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-bottom/config"
2024-01-24 14:40:36 +00:00
targetFile5="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-minimal/config"
2023-12-27 22:19:24 +00:00
settingsFile="$HOME/dotfiles/.settings/waybar_systray"
if [ -f $settingsFile ] ;then
startMarker="START TRAY TOOGLE"
endMarker="END TRAY TOOGLE"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile1"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile2"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile3"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile4"
2024-01-24 14:40:36 +00:00
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile5"
2023-12-27 22:19:24 +00:00
echo "Waybar Systray restored."
fi
2024-01-01 10:40:15 +00:00
# Restore Waybar Network
targetFile1="$HOME/dotfiles-versions/$version/waybar/themes/ml4w/config"
targetFile2="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-blur/config"
targetFile3="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-blur-bottom/config"
targetFile4="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-bottom/config"
2024-01-24 14:40:36 +00:00
targetFile5="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-minimal/config"
2024-01-01 10:40:15 +00:00
settingsFile="$HOME/dotfiles/.settings/waybar_network"
if [ -f $settingsFile ] ;then
startMarker="START NETWORK TOOGLE"
endMarker="END NETWORK TOOGLE"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile1"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile2"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile3"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile4"
2024-01-24 14:40:36 +00:00
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile5"
2024-01-01 10:40:15 +00:00
echo "Waybar Network restored."
fi
2024-01-11 15:03:36 +00:00
# Restore Waybar Idle
targetFile1="$HOME/dotfiles/waybar/themes/ml4w/config"
targetFile2="$HOME/dotfiles/waybar/themes/ml4w-blur/config"
targetFile3="$HOME/dotfiles/waybar/themes/ml4w-blur-bottom/config"
targetFile4="$HOME/dotfiles/waybar/themes/ml4w-bottom/config"
2024-01-24 14:40:36 +00:00
targetFile5="$HOME/dotfiles-versions/$version/waybar/themes/ml4w-minimal/config"
2024-01-11 15:03:36 +00:00
settingsFile="$HOME/dotfiles/.settings/waybar_swaylock"
if [ -f $settingsFile ] ;then
startMarker="START IDLE TOOGLE"
endMarker="END IDLE TOOGLE"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile1"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile2"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile3"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile4"
2024-01-24 14:40:36 +00:00
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile5"
2024-01-11 15:03:36 +00:00
echo "Waybar Idle restored."
fi
2024-01-01 10:40:15 +00:00
# Restore Waybar nmapplet
targetFile="$HOME/dotfiles-versions/$version/hypr/conf/autostart.conf"
settingsFile="$HOME/dotfiles/.settings/waybar_nmapplet"
if [ -f $settingsFile ] ;then
startMarker="START NM APPLET"
endMarker="END NM APPLET"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile"
echo "nm-applet restored."
fi
2024-01-01 14:08:52 +00:00
# Restore Keyboard natural_scroll
targetFile="$HOME/dotfiles-versions/$version/hypr/conf/keyboard.conf"
settingsFile="$HOME/dotfiles/.settings/keyboard_naturalscroll"
if [ -f $settingsFile ] ;then
findMarker="natural_scroll"
customtext="$(cat $settingsFile)"
_replaceLineInFile "$findMarker" "$customtext" "$targetFile"
echo "keyboard natural_scroll restored."
fi
2024-01-11 15:03:36 +00:00
# Restore Start Swaylock
targetFile="$HOME/dotfiles/hypr/scripts/lockscreentime.sh"
settingsFile="$HOME/dotfiles/.settings/hypr_lockscreen"
if [ -f $settingsFile ] ;then
startMarker="START SWAYIDLE"
endMarker="END SWAYIDLE"
customtext="$(cat $settingsFile)"
_replaceInFile "$startMarker" "$endMarker" "$customtext" "$targetFile"
echo "Swaylock start restored."
fi
2023-11-17 12:48:02 +00:00
echo ""
2023-11-24 12:58:59 +00:00
fi