/
install.sh
executable file
·120 lines (105 loc) · 3.51 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
#!/bin/bash
if [[ $OSTYPE == "darwin"* ]]; then
# Install CommandLineTools if not installed.
if pkgutil --pkgs=com.apple.pkg.CLTools_Executables >/dev/null; then
echo "macOS CommandLineTools are installed."
echo CommandLineTools: $(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | awk '/version:/ {print $2}')
else
echo "Installing macOS CommandLineTools."
echo "The script will continue once installation is finished . . ."
xcode-select --install &> /dev/null
until pkgutil --pkgs=com.apple.pkg.CLTools_Executables >/dev/null; do
sleep 2
done
fi
fi
if [[ $OSTYPE == "darwin"* ]]; then
# Install python3 if not installed.
if python3 --version >/dev/null 2>&1; then
echo "python3 is installed."
else
echo "Error python3 is not installed."
exit 1
fi
# Install pip if not installed.
if python3 -m pip -V >/dev/null 2>&1; then
echo "pip is installed."
else
echo "pip is not installed."
exit 1
fi
# Install Ansible if not installed.
if ansible --version >/dev/null 2>&1; then
echo "Ansible is installed."
else
echo "Installing Ansible."
python3 -m pip install ansible
fi
# Ensure pip binaies install location is in path.
# Get python version.
py_version=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
pip_path="$HOME/Library/Python/$py_version/bin"
if [ -d "$pip_path" ]; then
echo "PIP_PATH exists: $pip_path"
export PATH="$pip_path:$PATH"
else
echo "PIP_PATH does not exist: $pip_path"
exit 1
fi
if [ -d "/opt/homebrew" ]; then
if [ ! "$(command -v brew)" ]; then
eval $(/opt/homebrew/bin/brew shellenv)
fi
else
if [ ! "$(command -v brew)" ]; then
echo "Homebrew is not installed."
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval $(/opt/homebrew/bin/brew shellenv)
fi
fi
else
# Update the package list
sudo apt-get update
sudo apt-get install ansible
fi
ask_computer_type() {
local type
while true; do
read -p "What type of computer are you provisioning? (personal/work)? " type
case $type in personal|work)
export COMPUTER_TYPE="$type"
return
;;
*)
echo "Invalid input. Please enter 'personal' or 'work'."
;;
esac
done
}
ask_computer_kind() {
local kind
while true; do
read -p "What kind of computer are you provisioning? (client/server)? " kind
case $kind in client|server)
export COMPUTER_KIND="$kind"
return
;;
*)
echo "Invalid input $kind. Please enter 'client' or 'server'."
;;
esac
done
}
if [ -z "${COMPUTER_TYPE}" ]; then
ask_computer_type
fi
if [ -z "${COMPUTER_KIND}" ]; then
ask_computer_kind
fi
if [ -z "${WORK_DOTFILES_URL}" ]; then
read -p "Enter the URL for work dotfiles repo: " WORK_DOTFILES_URL
export WORK_DOTFILES_URL
fi
ansible-galaxy collection install community.general
ansible-playbook tasks.yml --ask-become-pass -e "computer_type=${COMPUTER_TYPE}" -e "computer_kind=${COMPUTER_KIND}" -e "work_dotfiles_url=${WORK_DOTFILES_URL}" -e "py_version=${py_version}" -t "dotfiles"