-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathup
executable file
·192 lines (153 loc) · 4.93 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
181
182
183
184
185
186
187
188
189
190
191
192
#!/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 ' 888 888 .d888 d8b 888 '
echo ' 888 888 d88P" Y8P 888 '
echo ' 888 888 888 888 '
echo ' .d88888 .d88b. 888888 888888 888 888 .d88b. .d8888b '
echo ' d88" 888 d88""88b 888 888 888 888 d8P Y8b 88K '
echo ' 888 888 888 888 888 888 888 888 88888888 "Y8888b. '
echo ' Y88b 888 Y88..88P Y88b. 888 888 888 Y8b. X88 '
echo ' "Y88888 "Y88P" "Y888 888 888 888 "Y8888 88888P" '
echo ' '
echo ' comfortable envs for you '
echo ' '
echo ' github.com/hiramekun/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 git://github.com/creasty/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'
}
load_env() {
source shell/env.sh
}
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)"
echo 'done'
}
brew_tap() {
brew tap AdoptOpenJDK/openjdk
}
install_ansible() {
command -v 'ansible' > /dev/null 2>&1 && return
echo 'Installing ansible...'
brew install ansible
echo 'done'
}
run_provisioning() {
echo 'Provisioning...'
$DOTFILES_PATH/provisioning/run.sh ${ARGS[@]}
echo 'done'
}
#=== Entrypoint
#==============================================================================================
main() {
print_header
check_os
clone_or_update_repo
check_xcode_license_approved
load_env
install_homebrew
brew_tap
install_ansible
run_provisioning
}
main