-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·153 lines (126 loc) · 4.12 KB
/
install.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
153
#!/bin/bash
# Stolen miserably from brew installer
TOUCH=("/usr/bin/touch")
should_install_command_line_tools() {
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
}
abort() {
printf "%s\n" "$1"
exit 1
}
chomp() {
printf "%s" "${1/"$'\n'"/}"
}
shell_join() {
local arg
printf "%s" "$1"
shift
for arg in "$@"; do
printf " "
printf "%s" "${arg// /\ }"
done
}
execute() {
if ! "$@"; then
abort "$(printf "Failed during: %s" "$(shell_join "$@")")"
fi
}
unset HAVE_SUDO_ACCESS # unset this from the environment
have_sudo_access() {
if [[ ! -x "/usr/bin/sudo" ]]; then
return 1
fi
local -a SUDO=("/usr/bin/sudo")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
SUDO+=("-A")
elif [[ -n "${NONINTERACTIVE-}" ]]; then
SUDO+=("-n")
fi
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
if [[ -n "${NONINTERACTIVE-}" ]]; then
"${SUDO[@]}" -l mkdir &>/dev/null
else
"${SUDO[@]}" -v && "${SUDO[@]}" -l mkdir &>/dev/null
fi
HAVE_SUDO_ACCESS="$?"
fi
if [[ "${HAVE_SUDO_ACCESS}" -ne 0 ]]; then
abort "Need sudo access (e.g. the user ${USER} needs to be an Administrator)!"
fi
return "${HAVE_SUDO_ACCESS}"
}
execute_sudo() {
local -a args=("$@")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A" "${args[@]}")
fi
if have_sudo_access; then
echo "/usr/bin/sudo" "${args[@]}"
execute "/usr/bin/sudo" "${args[@]}"
else
echo "${args[@]}"
execute "${args[@]}"
fi
}
getc() {
local save_state
save_state=$(/bin/stty -g)
/bin/stty raw -echo
IFS= read -r -n 1 -d ''
/bin/stty "$save_state"
}
install_git() {
if should_install_command_line_tools; then
echo "The Xcode Command Line Tools will be installed."
# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
execute_sudo "${TOUCH[@]}" "${clt_placeholder}"
clt_label_command="/usr/sbin/softwareupdate -l |
grep -B 1 -E 'Command Line Tools' |
awk -F'*' '/^ *\\*/ {print \$2}' |
sed -e 's/^ *Label: //' -e 's/^ *//' |
sort -V |
tail -n1"
clt_label="$(chomp "$(/bin/bash -c "$clt_label_command")")"
if [[ -n "$clt_label" ]]; then
echo "Installing $clt_label"
execute_sudo "/usr/sbin/softwareupdate" "-i" "$clt_label"
execute_sudo "/bin/rm" "-f" "$clt_placeholder"
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi
fi
if should_install_command_line_tools && test -t 0; then
echo "Installing the Command Line Tools (expect a GUI popup):"
execute_sudo "/usr/bin/xcode-select" "--install"
echo "Press any key when the installation has completed."
getc
execute_sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools"
fi
}
if [[ -d "$HOME/.macup" ]]; then
echo "Mac up already installed. Updating it"
macup update
else
install_git
git clone https://github.com/jalopez/macup.git ~/.macup
CONFIGURE_PATH="$HOME/.macup/configure.sh"
CONFIGURE_PATH_TEMPLATE="$HOME/.macup/configure.sh.template"
if [[ -z $MACUP_BACKUP_PATH ]]; then
echo "Backup path not set. Which path do you want to use for backups?"
read -r MACUP_BACKUP_PATH
cp "$CONFIGURE_PATH_TEMPLATE" "$CONFIGURE_PATH"
cat >>"$CONFIGURE_PATH" <<EOF
if [[ -z "\$MACUP_BACKUP_PATH" ]]; then
export MACUP_BACKUP_PATH=$MACUP_BACKUP_PATH
export DOTFILES=$MACUP_BACKUP_PATH/dotfiles
fi
EOF
fi
if [[ ":${PATH}:" != *"$HOME/.macup/bin:"* ]]; then
echo "test -e \$HOME/.macup/configure.sh && . \$HOME/.macup/configure.sh" >>~/.zshrc
fi
echo "Successfully installed macup."
fi
echo "Your backup path is set to $MACUP_BACKUP_PATH"
echo "You can modify this config by changing \$MACUP_BACKUP_PATH env variable"
echo "Please open a new tab and run 'macup setup' to finish the installation"