-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·107 lines (98 loc) · 2.79 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
#!/usr/bin/env bash
set -e
# https://regex101.com/r/Uvm9bs/2
RHEL_SED_VERSION_PARSE='s/^[^0-9]+([0-9]+\.[0-9]+).*$/\1/'
COLOR_NC='\e[0m' # No Color
COLOR_LIGHT_BLUE='\e[1;34m'
COLOR_LIGHT_RED='\e[1;31m'
RUN=${RUN:-1}
DEBUG=${DEBUG:-0}
SUDO=${SUDO:-1}
APT_UPDATE_INTERVAL=${APT_UPDATE_INTERVAL:-7200}
MODE=${MODE:-puppeter}
if [ $DEBUG == 1 ]; then
set -x
fi
if [ -f /etc/redhat-release ]; then
if [ -f /etc/oracle-release ]; then
os=oraclelinux
version=$(cat /etc/oracle-release | sed -E $RHEL_SED_VERSION_PARSE)
elif [ -f /etc/centos-release ]; then
os=centos
version=$(cat /etc/centos-release | sed -E $RHEL_SED_VERSION_PARSE)
else
os=rhel
version=$(cat /etc/redhat-release | sed -E $RHEL_SED_VERSION_PARSE)
fi
osfamily=redhat
elif [ -f /etc/debian_version ]; then
osfamily=debian
if [ -f /etc/lsb-release ]; then
source /etc/lsb-release
os=$(echo $DISTRIB_ID | tr '[:upper:]' '[:lower:]')
version=$DISTRIB_RELEASE
else
os=debian
version=$(cat /etc/debian_version)
fi
fi
majversion=$(echo $version | cut -d. -f1)
run() {
command="$*"
if [[ $EUID -ne 0 ]] && [ $SUDO == 1 ]; then
command="sudo -i ${command}"
fi
echo -e "${COLOR_LIGHT_BLUE}Executing: ${command}${COLOR_NC}"
if [ $RUN == 1 ]; then
eval "$command"
fi
}
unsupported() {
echo -e "${COLOR_LIGHT_RED}Unsupported operating system: ${os} ${version}${COLOR_NC}" 1>&2
exit 1
}
last_aptget_update() {
local apt_date now_date
apt_date="$(stat -c %Y '/var/cache/apt')"
now_date="$(date +'%s')"
echo $((now_date - apt_date))
}
if [ $osfamily == redhat ]; then
if [ $majversion == 6 ]; then
if [ $os == centos ]; then
run yum install -y centos-release-scl
run yum install -y python27-python-pip
fi
if [ $os == oraclelinux ]; then
run yum install -y yum-utils gcc
run yum-config-manager --enable public_ol6_software_collections
run yum install -y python27-python-pip python27-python-devel
fi
echo 'source /opt/rh/python27/enable' >> /etc/profile.d/python27.sh
run source /opt/rh/python27/enable
elif [ $majversion == 7 ]; then
if [ $os == centos ]; then
run yum install -y epel-release
run yum install -y python-pip
fi
if [ $os == oraclelinux ]; then
run yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
run yum install -y python-pip
fi
else
unsupported
fi
elif [ $osfamily == debian ]; then
flavor="$os-$majversion"
if [[ "$(last_aptget_update)" -gt $APT_UPDATE_INTERVAL ]]; then
run apt-get update -m
fi
if [ $flavor == ubuntu-14 ] || [ $flavor == debian-8 ]; then
run apt-get install -y python-pip python-dev
else
run apt-get install -y python-pip
fi
fi
if [ $MODE == puppeter ]; then
run LC_ALL=C pip install puppeter
fi