Hyprland-dotfiles/.install/backup.sh

162 lines
6.8 KiB
Bash
Raw Normal View History

2023-11-10 16:12:15 -05:00
# ------------------------------------------------------
# Backup existing dotfiles
# ------------------------------------------------------
datets=$(date '+%Y%m%d%H%M%S')
2024-03-29 08:08:22 -04:00
# Create Backup File Structure
if [ ! -d ~/dotfiles-versions ]; then
mkdir ~/dotfiles-versions
echo "~/dotfiles-versions created."
fi
if [ ! -d ~/dotfiles-versions/backup ]; then
mkdir ~/dotfiles-versions/backup
echo "~/dotfiles-versions/backup created"
fi
if [ -d ~/dotfiles-versions/backups ]; then
mv ~/dotfiles-versions/backups ~/dotfiles-versions/archive
echo ":: Existing backups moved into ~/dotfiles-versions/archive"
fi
if [ ! -d ~/dotfiles-versions/archive ]; then
mkdir ~/dotfiles-versions/archive
echo "~/dotfiles-versions/archive created"
fi
# Backup Existing Dotfiles
if [ -d ~/dotfiles ] || ! test -L ~/.bashrc || [ -d ~/.config/hypr ] || [ -d ~/.config/qtile ]; then
echo -e "${GREEN}"
figlet "Backup"
echo -e "${NONE}"
echo "The script has detected the following files and folders for a backup:"
2023-11-12 08:16:53 -05:00
if [ -d ~/dotfiles ]; then
2024-03-29 08:08:22 -04:00
echo " - $HOME/dotfiles"
fi
if ! test -L ~/.bashrc ;then
echo " - $HOME/.bashrc"
fi
if ! test -L ~/.config/qtile && [ -d ~/.config/qtile ] ;then
echo " - $HOME/.config/qtile/"
fi
if ! test -L ~/.config/hypr && [ -d ~/.config/hypr ] ;then
echo " - $HOME/.config/hypr/"
fi
if ! test -L ~/.config/rofi && [ -d ~/.config/rofi ] ;then
echo " - $HOME/.config/rofi/"
fi
if ! test -L ~/.config/wal && [ -d ~/.config/wal ] ;then
echo " - $HOME/.config/wal/"
fi
if ! test -L ~/.config/waybar && [ -d ~/.config/waybar ] ;then
echo " - $HOME/.config/waybar/"
fi
if ! test -L ~/.config/wlogout && [ -d ~/.config/wlogout ] ;then
echo " - $HOME/.config/wlogout/"
fi
if ! test -L ~/.config/alacritty && [ -d ~/.config/alacritty ] ;then
echo " - $HOME/.config/alacritty/"
fi
if ! test -L ~/.config/starship && [ -d ~/.config/starship ] ;then
echo " - $HOME/.config/starship/"
fi
if ! test -L ~/.config/picom && [ -d ~/.config/picom ] ;then
echo " - $HOME/.config/picom/"
2023-11-12 08:16:53 -05:00
fi
2024-03-29 08:08:22 -04:00
if ! test -L ~/.config/nvim && [ -d ~/.config/nvim ] ;then
echo " - $HOME/.config/nvim/"
2023-11-12 08:16:53 -05:00
fi
2024-03-29 08:08:22 -04:00
if ! test -L ~/.config/vim && [ -d ~/.config/vim ] ;then
echo " - $HOME/.config/vim/"
fi
if ! test -L ~/.config/dunst && [ -d ~/.config/dunst ] ;then
echo " - $HOME/.config/dunst/"
fi
if ! test -L ~/.config/swappy && [ -d ~/.config/swappy ] ;then
echo " - $HOME/.config/swappy/"
fi
# Start Backup
2023-11-20 16:24:53 -05:00
if gum confirm "Do you want to create a backup?" ;then
2024-03-29 08:08:22 -04:00
if [ ! -z "$(ls -A ~/dotfiles-versions/backup)" ] ;then
if gum confirm "Do you want to archive the existing backup?" ;then
rsync -a ~/dotfiles-versions/backup/ ~/dotfiles-versions/archive/$datets/
echo ":: Current backup archived in ~/dotfiles-versions/archive/$datets"
fi
2023-11-20 16:11:39 -05:00
fi
2024-03-29 08:08:22 -04:00
if [ -d ~/dotfiles ]; then
rsync -a ~/dotfiles ~/dotfiles-versions/backup/
echo ":: Backup of $HOME/dotfiles created in ~/dotfiles-versions/backup"
2023-11-20 16:11:39 -05:00
fi
2024-03-29 08:08:22 -04:00
if ! test -L ~/.bashrc ;then
cp ~/.bashrc ~/dotfiles-versions/backup
echo ":: Backup of $HOME/.bashrc created in ~/dotfiles-versions/backup"
2023-11-20 16:11:39 -05:00
fi
2024-03-29 08:08:22 -04:00
if [ ! -d ~/dotfiles-versions/backup/config ] ;then
mkdir ~/dotfiles-versions/backup/config
fi
if ! test -L ~/.config/qtile && [ -d ~/.config/qtile ] ;then
cp ~/.config/qtile ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/qtile created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/hypr && [ -d ~/.config/hypr ] ;then
cp ~/.config/hypr ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/hypr created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/qtile && [ -d ~/.config/rofi ] ;then
cp ~/.config/rofi ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/rofi created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/wal && [ -d ~/.config/wal ] ;then
cp ~/.config/wal ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/wal created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/waybar && [ -d ~/.config/waybar ] ;then
cp ~/.config/waybar ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/waybar created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/wlogout && [ -d ~/.config/wlogout ] ;then
cp ~/.config/wlogout ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/wlogout created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/alacritty && [ -d ~/.config/alacritty ] ;then
cp ~/.config/alacritty ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/alacritty created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/starship && [ -d ~/.config/starship ] ;then
cp ~/.config/starship ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/starship created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/picom && [ -d ~/.config/picom ] ;then
cp ~/.config/picom ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/picom created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/nvim && [ -d ~/.config/nvim ] ;then
cp ~/.config/nvim ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/nvim created in ~/dotfiles-versions/backup/config/"
fi
if ! test -L ~/.config/vim && [ -d ~/.config/vim ] ;then
cp ~/.config/vim ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/vim created in ~/dotfiles-versions/backup/config/"
2023-11-20 16:11:39 -05:00
fi
2024-03-29 08:08:22 -04:00
if ! test -L ~/.config/dunst && [ -d ~/.config/dunst ] ;then
cp ~/.config/dunst ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/dunst created in ~/dotfiles-versions/backup/config/"
2023-11-20 16:11:39 -05:00
fi
2024-03-29 08:08:22 -04:00
if ! test -L ~/.config/swappy && [ -d ~/.config/swappy ] ;then
cp ~/.config/swappy ~/dotfiles-versions/backup/config
echo ":: Backup of $HOME/.config/swappy created in ~/dotfiles-versions/backup/config/"
fi
2023-11-21 15:19:51 -05:00
elif [ $? -eq 130 ]; then
exit 130
2023-11-20 16:11:39 -05:00
else
2024-01-25 14:55:32 -05:00
echo ":: Backup skipped."
2023-11-20 16:11:39 -05:00
fi
2024-03-29 08:08:22 -04:00
else
echo ":: Nothing to backup"
2023-11-10 16:12:15 -05:00
fi
2024-03-29 08:08:22 -04:00
echo