-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·251 lines (232 loc) · 9.92 KB
/
setup.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/bash
# Detect the host os type
HOSTOS=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
# Set home path
UPATH=$HOME
# Function for loading animation
function loading {
PID=$1
i=1
sp="/-\|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "\b${sp:i++%${#sp}:1}"
sleep 0.2
done
printf "\n"
}
# Call the loading animation with loading $! after you've sent a command in bg with &
# Ask for sudo password
sudo printf "Starting script...\n"
######################################################################################
# OS SPECIFIC
######################################################################################
case $HOSTOS in
######################################################################################
# HOST OS IS FEDORA
######################################################################################
'Fedora')
# Update
printf "***Update the System\n"
sudo dnf -y -q update &
loading $!
printf ">>>Update finished\n\n"
# Install packages
printf "***Install packages: git openssh openssh-clients vim ansible wget curl\n"
sudo dnf -y -q install git openssh openssh-clients vim ansible wget curl
printf ">>>Installation finished\n\n"
printf "***Install azure-cli: adding azure repo key and repo\n"
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
sudo dnf -y -q install azure-cli
printf ">>>Installation finished\n\n"
;;
######################################################################################
# HOST OS IS RHEL
######################################################################################
'"Red Hat Enterprise Linux Server"')
# Update
printf "***Update the System\n"
sudo yum -y -q update &
loading $!
printf ">>>Update finished\n\n"
# Install packages
printf "***Install packages: git openssh openssh-clients vim ansible wget curl\n"
sudo subscription-manager repos --enable rhel-7-server-ansible-2.6-rpms
sudo yum -y -q install git openssh openssh-clients vim ansible wget curl
printf ">>>Installation finished\n\n"
printf "***Install azure-cli: adding azure repo key and repo\n"
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
sudo yum -y -q install azure-cli
printf ">>>Installation finished\n\n"
;;
######################################################################################
# HOST OS IS CENTOS
######################################################################################
'"CentOS Linux"')
# Update
printf "***Update the System\n"
sudo yum -y -q update &
loading $!
printf ">>>Update finished\n\n"
# Install EPEL
printf "***Install EPEL repo\n"
sudo yum -y -q install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
printf ">>>Installation finished\n\n"
# Install packages
printf "***Install packages: git openssh openssh-clients vim ansible wget curl\n"
sudo yum -y -q install git openssh openssh-clients vim ansible wget curl
printf ">>>Installation finished\n\n"
printf "***Install azure-cli: adding azure repo key and repo\n"
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
sudo yum -y -q install azure-cli
printf ">>>Installation finished\n\n"
;;
######################################################################################
# HOST OS IS UBUNTU
######################################################################################
'"Ubuntu"')
# Update
printf "***Update the System\n"
sudo apt-get -y -q update &
loading $!
printf ">>>Update finished\n\n"
printf "***Upgrade the System\n"
sudo apt-get -y -q upgrade &
loading $!
printf ">>>Upgrade finished\n\n"
# Update ubuntu repos
printf "***Update repos to use main, restricted, universe, multiverse\n"
echo -e 'deb http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse\ndeb http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse\ndeb http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse' | sudo tee /etc/apt/sources.list
sudo apt-get update
printf ">>>Repos updated\n\n"
# Add ansible repo
printf "***Add ansible repo\n"
sudo apt-get -y -q install software-properties-common
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update
printf ">>>Repo added\n\n"
# Install packages
printf "***Install packages: python git vim ansible wget curl\n"
sudo apt-get -y -q install python git vim ansible wget curl
printf ">>>Installation finished\n\n"
printf "***Install azure-cli: adding azure repo key and repo\n"
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y -q install apt-transport-https azure-cli
printf ">>>Installation finished\n\n"
;;
######################################################################################
# HOST OS IS DEBIAN
######################################################################################
'"Debian GNU/Linux"')
# Update
printf "***Update the System\n"
sudo apt-get -y -q update &
loading $!
printf ">>>Update finished\n\n"
printf "***Upgrade the System\n"
sudo apt-get -y -q upgrade &
loading $!
printf ">>>Upgrade finished\n\n"
# Install packages
printf "***Install packages: python git vim ansible wget curl\n"
sudo apt-get -y -q install python git vim ansible wget curl
printf ">>>Installation finished\n\n"
printf "***Install azure-cli: adding azure repo key and repo\n"
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y -q install apt-transport-https azure-cli
printf ">>>Installation finished\n\n"
;;
*)
echo "Unknown OS"
exit 1
esac
######################################################################################
# UNIVERSAL
######################################################################################
### SET ALIASES
printf "***Set aliases\n"
echo "alias vi='vim'" >> $UPATH/.bashrc
printf ">>>Aliases set\n\n"
### SHOW GIT BRANCH IN SHELL PATH
printf "***Show git branch in CLI path\n"
cat <<EOT >> $UPATH/.bashrc
# Show git branch in shell path
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="[\u@\h \W]\[\033[00;32m\]\$(git_branch)\[\033[00m\]\$ "
EOT
printf ">>>Git branch added\n\n"
### VIM CONFIG
printf "***Configuring vim\n"
# Check if vimrc is present
if [ ! -f $UPATH/.vimrc ]; then
touch $UPATH/.vimrc
fi
echo 'set number' >> $UPATH/.vimrc
echo 'set tabstop=2' >> $UPATH/.vimrc
echo 'set shiftwidth=2' >> $UPATH/.vimrc
echo 'set expandtab' >> $UPATH/.vimrc
printf ">>>VIM configured\n\n"
### Setting up local bin dir for user
printf "***Check if $UPATH/.local/bin is present if not create it\n"
if [ ! -d $UPATH/.local/bin ]; then
mkdir -p $UPATH/.local/bin
fi
echo 'export PATH=~/.local/bin:$PATH' >> $UPATH/.bash_profile
source $UPATH/.bash_profile
printf ">>>Check done\n\n"
### INSTALL PIP
printf "***Install pip (Python package manager)\n"
curl -o /tmp/get-pip.py -O https://bootstrap.pypa.io/get-pip.py
python /tmp/get-pip.py --user
printf ">>>Installation finished\n\n"
### INSTALL VMWARE API CLIENT
printf "***Install pyvmomi (VMware ESXi & vCenter API client)\n"
pip install --upgrade --user pyvmomi
printf ">>>Installation finished\n\n"
### INSTALL DOCKER CLIENT
printf "***Install docker (Docker client without the daemon dockerd)\n"
printf "***This script installs version 18.06.1-ce of docker\n"
printf "***Check: https://download.docker.com/linux/static/stable/x86_64/\n"
wget -O /tmp/docker-client.tar.gz https://download.docker.com/linux/static/stable/x86_64/docker-18.06.1-ce.tgz
tar -zxvf /tmp/docker-client.tar.gz -C /tmp/
mv /tmp/docker/docker $UPATH/.local/bin/docker
printf ">>>Installation finished\n\n"
### INSTALL OPENSHIFT CLIENT
printf "***Install openshift-cli: downloading oc binary from github, placing it in $UPATH/.local/bin\n"
printf "***This script installs version v3.11.0 of oc\n"
printf "***Check: https://github.com/openshift/origin/releases for a newer version\n"
wget -O /tmp/oc-client.tar.gz https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
tar -zxvf /tmp/oc-client.tar.gz -C /tmp/
mv /tmp/openshift-origin-client-tools*/oc $UPATH/.local/bin/oc
mv /tmp/openshift-origin-client-tools*/kubectl $UPATH/.local/bin/kubectl
printf ">>>Installation finished\n\n"
### INSTALL AWS CLIENT
printf "***Install awscli\n"
$UPATH/.local/bin/pip install awscli --upgrade --user
printf ">>>Installation finished\n\n"
### SETUP GIT USER AND EMAIL
printf "***Setup git\n"
printf "The following git information is set globally for all repositories.\n"
read -r -p "Enter your git user name: " GITUSER
read -r -p "Enter your git user email: " GITEMAIL
git config --global user.name "$GITNAME"
git config --global user.email "$GITEMAIL"
printf ">>>Git setup finished\n\n"
### REFRESH CURRENT BASH SESSION
printf "***Importing new parameters\n"
reset
printf ">>>Import done\n\n"
printf ">>>Workstation preparation is done...\n"
exit 0