-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·29 lines (27 loc) · 1 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
# the for loop wasn't working in zsh (not sure why), hence the shebang
BACKUPDIR=backup_`date +%F`_`date +%T | tr : -`
echo "making backup directory $BACKUPDIR"
mkdir $BACKUPDIR
SCRIPTDIR=`dirname $0`
DOTFILES=`find $SCRIPTDIR -maxdepth 1 -name ".*" -not -type d`
for f in $DOTFILES; do
FILENAME="`basename $f`"
BACKUPPATH="$BACKUPDIR/$FILENAME"
INSTALLPATH="$HOME/$FILENAME"
if [ -h $INSTALLPATH ]; then
echo "found symlink at $INSTALLPATH. Removing..."
rm $INSTALLPATH
elif [ -d $INSTALLPATH ]; then
echo "found directory at $INSTALLPATH. Skipping..."
continue
elif [ -f $INSTALLPATH ]; then
echo "found regular file at $INSTALLPATH; moving to $BACKUPPATH..."
mv "$INSTALLPATH" "$BACKUPPATH"
elif [ -e $INSTALLPATH ]; then
echo "found something strange at $INSTALLPATH. Skipping..."
continue
fi
echo "creating symlink "$INSTALLPATH" -> `pwd`/$FILENAME"
ln -s "`pwd`/$FILENAME" "$INSTALLPATH"
done