-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_devtools.sh
More file actions
executable file
·146 lines (127 loc) · 4.97 KB
/
install_devtools.sh
File metadata and controls
executable file
·146 lines (127 loc) · 4.97 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
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
#!/bin/bash
# ============================================================================
# Script installs dev tools:
# pip, git, git-review, virtualenv, build-essential among others
# ============================================================================
# Uncomment the following line to debug this script
set -o xtrace
#=============================================================================
# GLOBAL FUNCTIONS
#=============================================================================
dluxPath='https://raw.githubusercontent.com/dlux/InstallScripts/master'
[[ ! -f common_packages ]] && curl -O $dluxPath/common_functions -O $dluxPath/common_packages
[[ ! -f common_packages ]] && exit 1
source common_packages
EnsureRoot
SetLocale /root
umask 022
PY3=False
_ANSIBLE=False
_KEYPAIR=False
# ======================= Processes installation options =====================
# Handle file sent as parameter - from where proxy info will be retrieved.
while [[ ${1} ]]; do
case "${1}" in
--help|-h)
read -d '' extraOptsH <<- EOM
\ --py3 To setup Python3.
--ansible To install ansible 2.6.1
--keypair To create id_rsa keypair.
EOM
PrintHelp "Install devtools" $(basename "$0") "$extraOptsH"
;;
--py3)
PY3=True
;;
--ansible)
_ANSIBLE=True
;;
--keypair)
_KEYPAIR=True
;;
*)
HandleOptions "$@"
shift
esac
shift
done
# ============================================================================
# BEGIN PACKAGE INSTALATATION
# If proxy passed as parameter - set it on the environment
[[ -n $_PROXY ]] && source ".PROXY"
echo "<<--------------- Update Package Manager ------------------------------"
UpdatePackageManager
[[ $_PACKAGE_MANAGER == 'yum' ]] && $_INSTALLER_CMD redhat-lsb-core
[[ $_PACKAGE_MANAGER == 'zypper' || $_PACKAGE_MANAGER == 'apt' ]] && $_INSTALLER_CMD lsb-release
# Setup user calling this script (non-root)
caller_user=$(who -m | awk '{print $1;}')
if [ -z $caller_user ]; then
# For ubuntuOS except trusty use 'ubuntu'
# Any other OS or trustyUbuntu-12.04 use 'vagrant'
[[ $(IsUbuntu) == True && $(IsTrusty) != True ]] && caller_user='ubuntu' || caller_user='vagrant'
fi
echo "<<--------------- Install development libraries -----------------------"
$_INSTALLER_CMD curl git vim
if [[ $(IsUbuntu) == True ]]; then
apt-get install -y build-essential libssl-dev libffi-dev libxml2-dev \
libxslt1-dev libpq-dev htop
else
yum clean all
yum groupinstall -y "Development Tools"
fi
[ $_KEYPAIR == True ] && SetKeyPair $caller_user
[ $_ANSIBLE == True ] && echo "<<--- Install Ansible ---" && InstallAnsible
# By default install and configure Python 2.7 unless PY3 flag is setup
echo "<<--------------- Install python (2|3) --------------------------------"
if [ $PY3 == False ]; then
echo 'Setting up PY2.x'
[[ $(IsUbuntu) == True ]] && pck='python-dev' || pck='python-devel'
$_INSTALLER_CMD python $pck
# Install pip
curl -Lo- https://bootstrap.pypa.io/get-pip.py | python
pip install --upgrade pip
pip install git-review virtualenv
else
# USE Python 3.6
echo 'Setting up PY3.6'
if [[ $(IsUbuntu) == True ]]; then
$_INSTALLER_CMD python3.6 python3.6-dev
else
$_INSTALLER_CMD https://centos7.iuscommunity.org/ius-release.rpm
yum -y update
$_INSTALLER_CMD python36u python36u-libs python36u-devel
fi
# Make python 3.6 the default python version
alternatives --install /usr/bin/python python /usr/bin/python2 50
alternatives --install /usr/bin/python python /usr/bin/python3.6 60
curl -Lo- https://bootstrap.pypa.io/get-pip.py | python
pip install git-review virtualenv
fi
echo "<<--------------- Configure git and user settings ---------------------"
if [ ! -f "/home/$caller_user/.bashrc" ]; then
cp /etc/skel/.bashrc "/home/$caller_user/.bashrc"
chown $caller_user:$caller_user "/home/$caller_user/.bashrc"
fi
echo 'Configuring git & git-review'
cmd='git config --global'
sudo -H -u $caller_user bash -c "$cmd user.name 'Luz Cazares'"
sudo -H -u $caller_user bash -c "$cmd user.email 'luz.cazares@intel.com'"
sudo -H -u $caller_user bash -c "$cmd core.editor 'vim'"
sudo -H -u $caller_user bash -c "$cmd gitreview.username 'luzcazares'"
#runuser -l $caller_user -c 'command'
curl -O https://raw.githubusercontent.com/dlux/InstallScripts/master/.vimrc
chown $caller_user:$caller_user .vimrc
# Bypass proxy on ssh (used by git) via .ssh/config file.
if [[ ! -z "${_ORIGINAL_PROXY}" ]]; then
echo 'Setting proxy on .ssh/config'
pxSvr=$(echo "${_ORIGINAL_PROXY}" | awk -F '//' '{print $2}' \
| awk -F ':' '{print $1}')
cfgFile="/home/$caller_user/.ssh/config"
mkdir -p "/home/$caller_user/.ssh"
echo "Host *" >> "${cfgFile}"
echo "ProxyCommand nc -X 5 -x $pxSvr:1080 %h %p" >> "${cfgFile}"
chown $caller_user:$caller_user "${cfgFile}"
# Lastly unset proxy
UnsetProxy "${_ORIGINAL_PROXY}"
fi
echo 'Script Finished.'