forked from caarlos0/dotfiles.zsh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·116 lines (100 loc) · 2.77 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·116 lines (100 loc) · 2.77 KB
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
#!/bin/sh
#
# bootstrap installs things.
cd "$(dirname "$0")/.."
DOTFILES_ROOT=$(pwd -P)
set -e
echo ''
info() {
# shellcheck disable=SC2059
printf "\r [ \033[00;34m..\033[0m ] $1\n"
}
user() {
# shellcheck disable=SC2059
printf "\r [ \033[0;33m??\033[0m ] $1\n"
}
success() {
# shellcheck disable=SC2059
printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"
}
fail() {
# shellcheck disable=SC2059
printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"
echo ''
exit
}
setup_gitconfig() {
info 'setup gitconfig'
# if there is no user.email, we'll assume it's a new machine/setup and ask it
if [ -z "$(git config --global --get user.email)" ]; then
user ' - What is your github author name?'
read -r user_name
user ' - What is your github author email?'
read -r user_email
git config --global user.name "$user_name"
git config --global user.email "$user_email"
elif [ "$(git config --global --get dotfiles.managed)" != "true" ]; then
# if user.email exists, let's check for dotfiles.managed config. If it is
# not true, we'll backup the gitconfig file and set previous user.email and
# user.name in the new one
user_name="$(git config --global --get user.name)"
user_email="$(git config --global --get user.email)"
mv ~/.gitconfig ~/.gitconfig.backup
success "moved ~/.gitconfig to ~/.gitconfig.backup"
git config --global user.name "$user_name"
git config --global user.email "$user_email"
else
# otherwise this gitconfig was already made by the dotfiles
info "already managed by dotfiles"
fi
# include the gitconfig.local file
git config --global include.path ~/.gitconfig.local
# finally make git knows this is a managed config already, preventing later
# overrides by this script
git config --global dotfiles.managed true
success 'gitconfig'
}
link_file() {
if [ -e "$2" ]; then
if [ "$(readlink "$2")" = "$1" ]; then
success "skipped $1"
return 0
else
mv "$2" "$2.backup"
success "moved $2 to $2.backup"
fi
fi
ln -sf "$1" "$2"
success "linked $1 to $2"
}
install_dotfiles() {
info 'installing dotfiles'
find -H "$DOTFILES_ROOT" -maxdepth 3 -name '*.symlink' -not -path '*.git*' |
while read -r src; do
dst="$HOME/.$(basename "${src%.*}")"
link_file "$src" "$dst"
done
}
find_zsh() {
if command -v zsh >/dev/null 2>&1 && grep "$(command -v zsh)" /etc/shells >/dev/null; then
command -v zsh
else
echo "/bin/zsh"
fi
}
setup_gitconfig
install_dotfiles
info "installing dependencies"
if ./bin/dot_update; then
success "dependencies installed"
else
fail "error installing dependencies"
fi
zsh="$(find_zsh)"
test -z "$TRAVIS_JOB_ID" &&
test "$(expr "$SHELL" : '.*/\(.*\)')" != "zsh" &&
command -v chsh >/dev/null 2>&1 &&
chsh -s "$zsh" &&
success "set $("$zsh" --version) at $zsh as default shell"
echo ''
echo ' All installed!'