Backup regular files and replace broken links
This commit is contained in:
parent
8a5bb606b9
commit
27ef0d98fa
44
install.sh
44
install.sh
@ -1,28 +1,46 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script loops through files in this repository, creating symlinks in your
|
||||||
|
# home directory targeting here. It will prompt you to backup regular files and
|
||||||
|
# replace broken symlinks but will ignore good symlinks regardless of their
|
||||||
|
# target.
|
||||||
|
|
||||||
DOTFILES="$(pwd)/.*[a-z]"
|
DOTFILES="$(pwd)/.*[a-z]"
|
||||||
DATE=$(date '+%Y%m%d%H%M%S')
|
|
||||||
|
|
||||||
for FILE in $DOTFILES ; do
|
for FILE in $DOTFILES ; do
|
||||||
BASEFILE=$(basename $FILE)
|
BASEFILE=$(basename $FILE)
|
||||||
|
NEWLINK=0
|
||||||
|
|
||||||
# Exclude the repo's .git folder
|
# Exclude the repo's .git folder
|
||||||
if [ "$BASEFILE" != ".git" ] ; then
|
if [ "$BASEFILE" != ".git" ] ; then
|
||||||
|
|
||||||
# If dotfile is not a symlink and exists then back it up
|
# If basefile is a link
|
||||||
if [ ! -L ~/$BASEFILE ] ; then
|
if [ -L ~/$BASEFILE ] ; then
|
||||||
read -p "Press [ENTER] to move ~/$BASEFILE to ~/$BASEFILE-$DATE"
|
# If basefile is not a file, and therefore is a broken symlink
|
||||||
echo "mv ~/$BASEFILE ~/$BASEFILE-$DATE"
|
if [ ! -f ~/$BASEFILE ] ; then
|
||||||
|
read -p "Press [ENTER] to replace broken symlink ~/$BASEFILE. CTRL+C aborts"
|
||||||
|
rm ~/$BASEFILE
|
||||||
|
NEWLINK=1
|
||||||
|
else
|
||||||
|
echo "~/$BASEFILE is already linked."
|
||||||
|
fi
|
||||||
|
# If basefile is a regular file
|
||||||
|
elif [ -f ~/$BASEFILE ] ; then
|
||||||
|
DATE=$(date '+%Y%m%d%H%M%S')
|
||||||
|
read -p "Press [ENTER] to move ~/$BASEFILE to ~/$BASEFILE-$DATE. CTRL+C aborts"
|
||||||
|
mv ~/$BASEFILE ~/$BASEFILE-$DATE
|
||||||
|
NEWLINK=1
|
||||||
|
else
|
||||||
|
echo "Nothing in location ~/$BASEFILE"
|
||||||
|
NEWLINK=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If dotfile doesn't exist then link it.
|
# Create a new symlink
|
||||||
if [ ! -e "~/$BASEFILE" ] ; then
|
if [ $NEWLINK -eq 1 ] ; then
|
||||||
echo "ln -s $FILE ~/$BASEFILE"
|
echo "Creating new link to $(pwd)/$BASEFILE from" ~
|
||||||
|
ln -s $(pwd)/$BASEFILE ~/$BASEFILE
|
||||||
else
|
source ~/$BASEFILE
|
||||||
echo "~/$BASEFILE is already a symlink. Nothing to do."
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user