-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup
executable file
·145 lines (123 loc) · 3.33 KB
/
setup
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
#!/usr/bin/env bash
set -e -u
# Configurations
GHUSER=${GHUSER:-skatsuta}
REPO=${REPO:-ansible-macos}
DEST=${DEST:-${HOME}/src/github.com/${GHUSER}}
DIR="${DEST}/${REPO}"
SSH_KEY_TYPE=${SSH_KEY_TYPE:-ed25519}
SSH_KEY_PATH=$HOME/.ssh/id_$SSH_KEY_TYPE
# Show variables
show_variables() {
echo "Configurations:"
echo " - Username: ${GHUSER}"
echo " - Repository: ${REPO}"
echo " - Destination: ${DEST}"
echo " - SSH key type: ${SSH_KEY_TYPE}"
}
# Show ~/Library folder
configure() {
echo "Setting to show ~/Library..."
chflags nohidden ~/Library
echo "Turning off startup chime..."
sudo nvram SystemAudioVolume=" "
}
# Generate SSH Key
generate_ssh_key() {
if [[ -f "$SSH_KEY_PATH" ]]; then
echo "Your SSH key already exists."
return
fi
echo "Generating a SSH key..."
read -p "Type your email address: " email
ssh-keygen -t "$SSH_KEY_TYPE" -C "$email"
echo "Adding your SSH key to your ssh-agent..."
eval "$(ssh-agent -s)"
ssh-add "$SSH_KEY_PATH"
}
# Prompt the confirmation of adding the SSH key to GitHub
prompt_confirmation() {
echo "Copying your SSH public key into your clipboard..."
pbcopy < "$SSH_KEY_PATH.pub"
echo "Now you should add the generated key to GitHub before proceeding."
while true; do
read -p "Are you sure you want to proceed? [Y/n] " yn
case $yn in
[Yy]*|'')
echo "Proceeding..."
break
;;
[Nn]*)
echo "Stopped."
exit 1
;;
esac
done
}
# Install Command Line Tools
install_command_line_tools() {
if [[ -d /Library/Developer/CommandLineTools ]]; then
echo "Command Line Tools is already installed."
return
fi
echo "Installing Command Line Tools..."
echo "*** If a dialog is shown, push 'Install' button to install Command Line Tools before proceeding! ***"
xcode-select --install
}
# Install Homebrew
install_homebrew() {
if [[ -f /usr/local/bin/brew ]]; then
echo "Homebrew is already installed."
return
fi
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo "Adding environment variables to $HOME/.zprofile..."
local homebrew_home=/usr/local
if [[ $(sysctl -n machdep.cpu.brand_string) =~ 'Apple' ]]; then
homebrew_home=/opt/homebrew
fi
echo '# Homebrew' >> $HOME/.zprofile
echo 'eval $('${homebrew_home}'/bin/brew shellenv)' >> $HOME/.zprofile
eval $(${homebrew_home}/bin/brew shellenv)
echo "Running 'brew doctor'..."
brew doctor
}
# Install packages for running Ansible playbook
install_packages_for_ansible() {
echo "Installing packages for running Ansible..."
brew install git ansible
}
# Clone my GitHub repository
clone_repo() {
if [[ -d "${DIR}" ]]; then
echo "Repository already exists."
return
fi
git clone [email protected]:${GHUSER}/${REPO}.git ${DIR}
cd ${DIR}
}
# Provision
provision() {
#cd ${DEST}/${REPO}
#echo "Start provisioning..."
#ansible-playbook playbook.yml
echo "Initialization has been completed successfully."
echo "To start provisioning, run"
echo
echo " \$ cd ${DIR}"
echo ' $ ansible-playbook playbook.yml'
}
# Run the above functions
run() {
show_variables
configure
generate_ssh_key
prompt_confirmation
install_command_line_tools
install_homebrew
install_packages_for_ansible
clone_repo
provision
}
run