forked from jeffaco/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·70 lines (59 loc) · 1.45 KB
/
bootstrap.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /bin/bash
# This script assumes none of the dotfiles that are to be replaced are
# symlinks
BACKUPDIR="$HOME/.dotfilebak"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function backup_old {
TARGET=$1
mkdir -p "${BACKUPDIR}"
if [ -e $TARGET -a ! -L $TARGET ]; then
mv $TARGET "$BACKUPDIR/$(basename $TARGET)"
fi
}
for d in $DIR/*; do
# iterate only over directories
[ ! -d $d ] && continue
[ $d = "$DIR/config" ] && continue
for entry in $d/*; do
TARGET="${HOME}/.$(basename $entry)"
backup_old $TARGET
if [ -L $TARGET ]; then
if [ -e $TARGET ]; then
# skip existing, valid links.
continue
fi
echo "Removing old link for $TARGET"
rm $TARGET
fi
echo "Linking $entry"
ln -s $entry "${HOME}/.$(basename $entry)"
print "WILL FAIL ON GENTOO"
if [ -e $entry/install.sh ]; then
$entry/install.sh
fi
done
done
for entry in $DIR/config/*; do
# iterate only over directories
[ ! -d $d ] && continue
echo $d
TARGET="${HOME}/.config/$(basename $entry)"
backup_old $TARGET
if [ -L $TARGET ]; then
if [ -e $TARGET ]; then
# skip existing, valid links.
continue
fi
echo "Removing old link for $TARGET"
rm $TARGET
fi
echo "Linking $entry"
ln -s $entry "$TARGET"
done
# delete old / stale links
for x in ~/.[!.]*; do
if [ -L "$x" ] && ! [ -e "$x" ]; then
echo "removing $x"
rm -- "$x";
fi;
done