-
Notifications
You must be signed in to change notification settings - Fork 1
/
up
executable file
Β·180 lines (144 loc) Β· 5.37 KB
/
up
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
set -eu
set -o pipefail
: ${DOTFILES_PATH:="$HOME/.dotfiles"}
: ${DOTFILES_BRANCH:=master}
ARGS=('')
for a in "$@"; do
ARGS=(${ARGS[@]} "$a")
done
#=== Utils
#==============================================================================================
compare_versions() {
declare -a v1=(${1//./ })
declare -a v2=(${2//./ })
local i=""
for (( i=${#v1[@]}; i<${#v2[@]}; i++ )); do
v1[i]=0
done
for (( i=0; i<${#v1[@]}; i++ )); do
if [[ -z ${v2[i]} ]]; then
v2[i]=0
fi
if (( 10#${v1[i]} > 10#${v2[i]} )); then
printf ">"
return 0
fi
if (( 10#${v1[i]} < 10#${v2[i]} )); then
printf "<"
return 0
fi
done
printf "="
}
#=== Steps
#==============================================================================================
print_header() {
printf "\e[34m"
echo '--------------------------------------------------------------------------------'
echo ' '
echo ' βββββββ βββββββ βββββββββββββββββββββββ ββββββββββββββββ '
echo ' ββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββ '
echo ' βββ ββββββ βββ βββ ββββββ ββββββ ββββββ ββββββββ '
echo ' βββ ββββββ βββ βββ ββββββ ββββββ ββββββ ββββββββ '
echo ' βββββββββββββββββ βββ βββ βββββββββββββββββββββββββββ '
echo ' βββββββ βββββββ βββ βββ βββββββββββββββββββββββββββ '
echo ' '
echo ' Thereβs no place like ~/ '
echo ' '
echo ' github.com/probberechts/dotfiles '
echo ' '
echo '--------------------------------------------------------------------------------'
printf "\e[0m\n"
}
check_os() {
if [ "$(uname -s)" == "Darwin" ]; then
if [ $(compare_versions "$(sw_vers -productVersion)" "10.9") == '<' ]; then
echo "Sorry, this script is intended only for OS X 10.9.0+"
exit 1
fi
else
echo "Sorry, this script is intended only for OS X"
exit 1
fi
}
clone_or_update_repo() {
local git_dir="$DOTFILES_PATH/.git"
if [ -d "$git_dir" ]; then
echo 'Updating repo...'
if [ "$(git --git-dir="$git_dir" symbolic-ref --short HEAD 2> /dev/null)" != "master" ]; then
echo 'skip (working on a non-master branch)'
return
fi
if ! git --git-dir="$git_dir" diff --no-ext-diff --quiet --exit-code > /dev/null 2>&1; then
echo 'skip (unstaged changes present)'
return
fi
if ! git --git-dir="$git_dir" diff-index --cached --quiet HEAD -- > /dev/null 2>&1; then
echo 'skip (uncommitted changes present)'
return
fi
git --git-dir="$git_dir" pull origin master
git --git-dir="$git_dir" submodule sync
echo 'done'
elif ! [ -d "$DOTFILES_PATH" ]; then
echo 'Cloning repo...'
git clone --recursive https://github.com/probberechts/dotfiles.git --branch $DOTFILES_BRANCH $DOTFILES_PATH
echo 'done'
fi
}
check_xcode_license_approved() {
echo 'Agreeing to Xcode license...'
local has_error=0
if ! [[ "$(/usr/bin/xcrun clang 2>&1 || true)" =~ 'license' ]]; then
echo 'skip (already approved)'
return
fi
sudo expect -c '
set timeout 3
spawn xcodebuild -license
expect {
timeout { exit 2 }
-exact "for more" {
send "G"
exp_continue
}
-exact "agree, print, cancel" {
send "agree\n"
exp_continue
}
-exact "You can view the license agreements" {
exit 0
}
}
' > /dev/null || has_error=1
[ $has_error -eq 1 ] && sudo xcodebuild -license
echo 'done'
}
fix_permission() {
[ -d $(brew --prefix) ] || mkdir -p $(brew --prefix)
[ "$(brew --prefix | stat -f '%Su')" = "$(whoami)" ] && return # GNU: stat -c '%U'
echo 'Fixing permission of $(brew --prefix)...'
sudo chown -R $(whoami) $(brew --prefix)/*
echo 'done'
}
install_homebrew() {
command -v 'brew' > /dev/null 2>&1 && return
echo 'Installing homebrew...'
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" < /dev/null
echo 'done'
}
#=== Entrypoint
#==============================================================================================
print_header
clone_or_update_repo
if [[ "$OSTYPE" == *'arwin'* ]]; then
check_os
check_xcode_license_approved
fix_permission
install_homebrew
. $DOTFILES_PATH/bootstrap/mac
else
. $DOTFILES_PATH/bootstrap/symlink
. $DOTFILES_PATH/bootstrap/cleanup
fi