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
files=(~/.zshrc ~/.config/.dotfiles/.zshrc 'n')
echo Setting up dotfiles
for (( i=0; i<${#files[@]} ; i+=3 )) ; do
if [ -f ${files[i+1]} ]; then
if [[ ${files[i+2]} == *'y'* ]]; then
rm ${files[i]}.bak
sudo mv ${files[i]} ${files[i]}.bak
else
rm ${files[i]}.bak
mv ${files[i]} ${files[i]}.bak
# Check if sudo is needed
pre=''
if [[ ${files[i+2]} == *'y'* ]]; then
pre='sudo'
fi
if [ -f ${files[i]} ]; then
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
if [[ $* == *-b* ]]; then
cp ${files[i]} ${files[i+1]}
else
if [[ ${files[i+2]} == *'y'* ]]; then
sudo ln -sf ${files[i+1]} ${files[i]}
else
ln -sf ${files[i+1]} ${files[i]}
fi
${pre} ln -sf ${files[i+1]} ${files[i]}
fi
done