forked from johnsudaar/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·44 lines (32 loc) · 954 Bytes
/
installer.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
#!/bin/bash
# set -x
set -o nounset
if [ $# -gt 1 ]; then
echo "Usage $0 [HOME_DIR]" >&2
exit 1
fi
# HOME_DIR is either $1 or $HOME if $1 is undefined
HOME_DIR=${1-$HOME}
BASEDIR=$(cd $(dirname $0) && pwd)
cd $BASEDIR
source $BASEDIR/libraries/bootstrap.sh
load $BASEDIR/libraries
OLD_IFS=$IFS
IFS=$'\n'
info "Starting dotfiles synchronisation"
# Loop through every line in the `map` file, except empty and comment
for line in $( sed -e '/^$/d' -e '/^\#.*$/d' $BASEDIR/map) ; do
src=$(echo $line | tr -s ' ' | cut -d' ' -f1)
dst=$(echo $line | tr -s ' ' | cut -d' ' -f2)
mkdir -p $HOME_DIR/$(dirname $dst)
if [ -e $HOME_DIR/$dst ]; then
info "Backup the existing file to '$HOME/$dst.bak'"
mv $HOME/$dst $HOME/$dst.bak
elif [ -L $HOME_DIR/$dst ]; then
info "Remove the existing symbolic link"
rm $HOME_DIR/$dst
fi
ln -s $BASEDIR/$src $HOME_DIR/$dst
done
IFS=$OLD_IFS
success "Dotfiles synchronisation ended!"