forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 49
/
bootstrap.sh
executable file
·152 lines (129 loc) · 3.61 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
echo -e "${COLOR_GREEN}"
for z in {1..50}; do
for i in {1..16}; do
r="$(($RANDOM % 2))"
if [[ $(($RANDOM % 5)) == 1 ]]; then
if [[ $(($RANDOM % 4)) == 1 ]]; then
v+="\e[1m $r "
else
v+="\e[2m $r "
fi
else
v+=" "
fi
done
echo -e "$v"
v="";
done
echo " _ _ __ _ _"
echo " __| | ___ | |_ / _(_) | ___ ___"
echo " / _\` |/ _ \| __|____| |_| | |/ _ \/ __|"
echo " | (_| | (_) | ||_____| _| | | __/\__ \\"
echo " \__,_|\___/ \__| |_| |_|_|\___||___/"
echo ""
echo -e "${COLOR_NO_COLOUR}"
if [[ "$1" == "--force" ]] || [[ "$1" == "-f" ]]; then
FORCE=1
else
FORCE=0
fi
git pull origin master
doIt()
{
if [ ! -f ~/.config_dotfiles ]; then
cp .config_dotfiles_default ~/.config_dotfiles
fi
# save old global git config
OLDMASK=$(umask)
umask 0077
git config --global -l | LANG=C sort > .oldgit$$.tmp
umask $OLDMASK
# copy dotfiles
if which rsync >/dev/null 2>&1; then
rsync --exclude-from .IGNORE -avhiE --no-perms . ~/
else
local ignore=""
local line_tmp
while read -ra line; do
line_tmp=$(echo $line | sed "s/\n//g")
if [[ ! -z $line_tmp ]]; then
ignore="$ignore|$line_tmp"
fi
done < .IGNORE
ignore=$(echo $ignore | sed "s/\./\\\./g")
cp -pvr `ls -A | grep -vE ".git$ignore"` ~/
fi
# check for "force"
if [[ "$FORCE" == "1" ]]; then
return 0
fi
# save new global git config
OLDMASK=$(umask)
umask 0077
git config --global -l | LANG=C sort > .newgit$$.tmp
umask $OLDMASK
echo "git configuration not present anymore after bootstrapping:"
LANG=C comm -23 .oldgit$$.tmp .newgit$$.tmp
echo -e "\nYou can use the following commands to add it again:"
LANG=C comm -23 .oldgit$$.tmp .newgit$$.tmp | while read line; do echo "git config --global "$(echo $line | sed 's/=/ '"'"'/;s/$/\'"'"'/'); done
# restore git?
read -p "Do you want to restore these git configs now? (y/n) " -n 1 yesOrNo
echo
if [[ $yesOrNo =~ ^[Yy]$ ]]; then
LANG=C comm -23 .oldgit$$.tmp .newgit$$.tmp | while IFS="=" read key value; do git config --global "$key" "$value"; done
fi
rm .oldgit$$.tmp .newgit$$.tmp
crlf_warning=""
# vim doesn't like ^M (CRLF) in .vim files. Make sure this will not happen on cygwin / windows systems
if [ "$(git config --system --get core.autocrlf)" == "true" ]; then
crlf_warning="--system "
fi
if [ "$(git config --global --get core.autocrlf)" == "true" ]; then
crlf_warning="${crlf_warning}--global"
fi
if [ -n "$crlf_warning" ]; then
echo "git config 'core.autocrlf' is currently true in '$crlf_warning'. Unset temporarly, otherwise VIM may have big problems!"
return 1
fi
# install vim-plugin-manager
if [ ! -d ~/.vim/bundle/vundle ]; then
mkdir ~/.vim/bundle
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
vim +BundleInstall +qall
else
read -p "Do you want to update vim-plugins? (y/n) " -n 1 yesOrNo
echo
if [[ $yesOrNo =~ ^[Yy]$ ]]; then
(
cd ~/.vim/bundle/vundle
git pull
vim +BundleUpdate +qall
)
fi
fi
}
dryRun()
{
if which rsync >/dev/null 2>&1; then
rsync --exclude-from .IGNORE -avhniE --no-perms . ~/
else
LC_ALL=C diff -w -B -r . ~/ | grep -v '^Only in'
fi
}
if [[ "$FORCE" == "1" ]]; then
doIt
else
echo "Executing dry run..."
echo
dryRun
echo
echo
read -p "The files listed above will overwritten in your home directory. Are you sure you want to continue? (y/n) " -n 1 yesOrNo
echo
if [[ $yesOrNo =~ ^[Yy]$ ]]; then
doIt
fi
fi
unset -f doIt
unset -f dryRun