Skip backing up symbolic links

This commit is contained in:
Christian Colglazier 2019-09-23 21:33:38 -04:00
parent 5f4927b3e0
commit 9bfe1ab53c

View File

@ -3,23 +3,24 @@
# source backup sudo # source backup sudo
files=(~/.zshrc ~/.config/.dotfiles/.zshrc 'n') files=(~/.zshrc ~/.config/.dotfiles/.zshrc 'n')
echo Setting up dotfiles
for (( i=0; i<${#files[@]} ; i+=3 )) ; do for (( i=0; i<${#files[@]} ; i+=3 )) ; do
if [ -f ${files[i+1]} ]; then # Check if sudo is needed
if [[ ${files[i+2]} == *'y'* ]]; then pre=''
rm ${files[i]}.bak if [[ ${files[i+2]} == *'y'* ]]; then
sudo mv ${files[i]} ${files[i]}.bak pre='sudo'
else fi
rm ${files[i]}.bak if [ -f ${files[i]} ]; then
mv ${files[i]} ${files[i]}.bak if ! [ -L ${files[i]} ]; then
echo Backing up ${files[i+1]}
${pre} rm ${files[i]}.bak
${pre} mv ${files[i]} ${files[i]}.bak
fi fi
fi fi
if [[ $* == *-b* ]]; then if [[ $* == *-b* ]]; then
cp ${files[i]} ${files[i+1]} cp ${files[i]} ${files[i+1]}
else else
if [[ ${files[i+2]} == *'y'* ]]; then ${pre} ln -sf ${files[i+1]} ${files[i]}
sudo ln -sf ${files[i+1]} ${files[i]}
else
ln -sf ${files[i+1]} ${files[i]}
fi
fi fi
done done