2023-11-10 21:12:15 +00:00
|
|
|
# ------------------------------------------------------
|
|
|
|
# Backup existing dotfiles
|
|
|
|
# ------------------------------------------------------
|
|
|
|
|
|
|
|
datets=$(date '+%Y%m%d%H%M%S')
|
2023-11-12 13:16:53 +00:00
|
|
|
if [ -d ~/dotfiles ] || [ -f ~/.bashrc ]; then
|
2023-11-10 21:12:15 +00:00
|
|
|
|
|
|
|
cat <<"EOF"
|
|
|
|
____ _
|
|
|
|
| __ ) __ _ ___| | ___ _ _ __
|
|
|
|
| _ \ / _` |/ __| |/ / | | | '_ \
|
|
|
|
| |_) | (_| | (__| <| |_| | |_) |
|
|
|
|
|____/ \__,_|\___|_|\_\\__,_| .__/
|
|
|
|
|_|
|
|
|
|
|
|
|
|
EOF
|
2023-11-12 13:16:53 +00:00
|
|
|
if [ -d ~/dotfiles ]; then
|
|
|
|
echo "The script has detected an existing dotfiles folder and will try to create a backup into the folder ~/dotfiles-versions/backups/$datets"
|
|
|
|
fi
|
|
|
|
if [ -f ~/.bashrc ]; then
|
|
|
|
echo "The script has detected an existing .bashrc file and will try to create a backup ~/dotfiles-versions/backups/$datets/.bashrc-old"
|
|
|
|
fi
|
2023-11-10 21:12:15 +00:00
|
|
|
echo ""
|
|
|
|
while true; do
|
|
|
|
read -p "Do you want to proceed? (Yy/Nn): " yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]* )
|
|
|
|
if [ ! -d ~/dotfiles-versions ]; then
|
|
|
|
mkdir ~/dotfiles-versions
|
2023-11-11 10:19:28 +00:00
|
|
|
echo "~/dotfiles-versions created."
|
2023-11-10 21:12:15 +00:00
|
|
|
fi
|
|
|
|
if [ ! -d ~/dotfiles-versions/backups ]; then
|
|
|
|
mkdir ~/dotfiles-versions/backups
|
2023-11-11 10:19:28 +00:00
|
|
|
echo "~/dotfiles-versions/backups created"
|
2023-11-10 21:12:15 +00:00
|
|
|
fi
|
2023-11-12 13:16:53 +00:00
|
|
|
if [ ! -d ~/dotfiles-versions/backups/$datets ]; then
|
|
|
|
mkdir ~/dotfiles-versions/backups/$datets
|
|
|
|
echo "~/dotfiles-versions/backups/$datets created"
|
|
|
|
fi
|
2023-11-10 21:12:15 +00:00
|
|
|
if [ -d ~/dotfiles ]; then
|
|
|
|
cp -r ~/dotfiles ~/dotfiles-versions/backups/$datets
|
|
|
|
echo "Backup of your current dotfiles in ~/dotfiles-versions/backups/$datets created."
|
|
|
|
fi
|
|
|
|
if [ -f ~/.bashrc ]; then
|
|
|
|
cp ~/.bashrc ~/dotfiles-versions/backups/$datets/.bashrc-old
|
|
|
|
echo "Existing .bashrc file found in homefolder. .bashrc-old created"
|
|
|
|
fi
|
|
|
|
break;;
|
|
|
|
[Nn]* )
|
|
|
|
break;;
|
|
|
|
* ) echo "Please answer yes or no.";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
fi
|