-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·112 lines (91 loc) · 2.62 KB
/
setup.sh
File metadata and controls
executable file
·112 lines (91 loc) · 2.62 KB
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
#!/usr/bin/env sh
## Config
#
SYSTEM_OS="Unknown"
SYSTEM_OS_VERSION="Unknown"
PACKAGE_MANAGER="Unknown"
GIT_VERSION="Unknown"
ANSIBLE_VERSION="Unknown"
ROOT_RUN=""
GIT_REPO_URL="https://github.com/manieperplex/dotFiles.git"
GIT_CLONE_FOLDER="$HOME/dotFiles"
ANSIBLE_PLAYBOOK_PATH="ansible/site.yml"
ANSIBLE_PLAYBOOK_CMD="ansible-playbook --inventory localhost, ${ANSIBLE_PLAYBOOK_PATH}"
## Func
#
# Print error message
error_print() {
echo ${RED}"Error: $@"${RESET} >&2
}
# Detects if script is run as root
root_detect() {
if ! [ $(id -u) -eq 0 ]; then
ROOT_RUN="sudo "
fi
}
# Install homebrew
install_homebrew() {
printf "Installing Homebrew... If it's already installed, update.\n"
if [[ $(command -v brew) == "" ]]; then
echo "Installing Hombrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
else
echo "Updating Homebrew..."
brew update
fi
PACKAGE_MANAGER=$(brew -v)
}
# Clone git repository if not existing
clone_git_repo() {
if [ ! -d "$GIT_CLONE_FOLDER" ] ; then
printf "Cloning git repository $GIT_REPO_URL in folder: $GIT_CLONE_FOLDER \n"
git clone --depth=1 --branch master "$GIT_REPO_URL" "$GIT_CLONE_FOLDER"
fi
}
# Install ansible if not existing
install_ansible() {
printf "Installing Ansible... If it's already installed, update.\n"
if [[ $(command -v ansible) == "" ]]; then
echo "Installing Ansible..."
brew install ansible
else
echo "Updating Ansible..."
brew upgrade ansible
fi
ANSIBLE_VERSION=$(ansible --version)
}
# Run ansible playbook installation
run_ansible() {
printf "\n"
printf "### INFORMATION\n"
printf "SYSTEM_OS=$SYSTEM_OS\n"
printf "SYSTEM_OS_VERSION=$SYSTEM_OS_VERSION\n"
printf "PACKAGE_MANAGER=$PACKAGE_MANAGER\n"
printf "GIT_VERSION=$GIT_VERSION\n"
printf "ANSIBLE_VERSION=$ANSIBLE_VERSION\n"
printf "ROOT_RUN=$ROOT_RUN\n"
printf "\n"
printf "Run ansible-playbook syntax check...\n"
${ANSIBLE_PLAYBOOK_CMD} --syntax-check
printf "Run ansible-playbook install...\n"
${ANSIBLE_PLAYBOOK_CMD}
}
## Main
#
printf "Start installing Ansible prerequisites (git, etc.)...\n"
root_detect
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*)
SYSTEM_OS="OSX"
SYSTEM_OS_VERSION=$(defaults read loginwindow SystemVersionStampAsString)
install_homebrew
clone_git_repo
install_ansible
cd "$GIT_CLONE_FOLDER"
run_ansible
;;
*)
error_print "UNKNOWN OS: ${unameOut}\nPlease add support in script!\n"
;;
esac