This repository has been archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpack
executable file
·106 lines (84 loc) · 2.18 KB
/
unpack
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
#!/usr/bin/env bash
set -eu
set -o pipefail
: ${NAPSAC_PATH:="$HOME/napsac"}
: ${NAPSAC_BRANCH:="master"}
ARGS=('')
for a in "$@"; do
ARGS=(${ARGS[@]} "$a")
done
clone_napsac() {
local git_dir="$NAPSAC_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
echo 'done'
elif ! [ -d "$NAPSAC_PATH" ]; then
echo 'Cloning repo...'
git clone git://github.com/ngtk/napsac.git --branch $NAPSAC_BRANCH $NAPSAC_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'
}
install_homebrew() {
command -v 'brew' > /dev/null 2>&1 && return
echo 'Installing homebrew...'
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null
echo 'done'
}
install_ansible() {
command -v 'ansible' > /dev/null 2>&1 && return
echo 'Installing ansible...'
brew install ansible
echo 'done'
}
run_provisioning() {
$NAPSAC_PATH/provisioning/play.sh ${ARGS[@]}
}
main() {
check_xcode_license_approved
clone_napsac
install_homebrew
install_ansible
run_provisioning
}
main