-
Notifications
You must be signed in to change notification settings - Fork 1
/
pre.sh
71 lines (63 loc) · 2 KB
/
pre.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
#!/bin/bash
# Set the mirror addr, host_name and logining without secret between nodes.
_get_distribution() {
local lsb_dist=
if [[ -r /etc/os-release ]]; then
# shellcheck source=/dev/null
lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
# perform some very rudimentary platform detection
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
# Returning an empty string here should be alright since the
# case statements don't act unless you provide an actual value
echo "$lsb_dist"
}
function set_yum() {
if [[ -z ${YUM_URL} ]]; then
YUM_URL="http://mirrors.aliyun.com"
fi
local dist
dist=$(_get_distribution)
case "${dist}" in
centos)
# https://stackoverflow.com/questions/6363441/check-if-a-file-exists-with-a-wildcard-in-a-shell-script
# if [[ $(compgen -G "/etc/yum.repos.d/CentOS-*.repo.bak") ]]; then
if compgen -G "/etc/yum.repos.d/CentOS-*.repo.bak"; then
rm -f /etc/yum.repos.d/CentOS-*.repo
rename '.bak' '' /etc/yum.repos.d/CentOS-*.bak
else
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e "s|^#baseurl=http://mirror.centos.org|baseurl=${YUM_URL}|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
yum makecache
fi
;;
*)
logger error "Unsupported distribution '$dist'"
exit 1
;;
esac
}
function set_docker() {
:
}
function pre_main() {
logger info "$(beauty "set yum and docker repo" 60)"
# shellcheck source=/dev/null
. ./core/core.sh
set_yum
set_docker
logger info "$(beauty "set no password login around members." 60)"
yum install net-tools -y
# shellcheck disable=SC2091
if isMaster; then
copy_id
set_host_name
fi
}
# Invoke main with args if not sourced
# Approach via: https://stackoverflow.com/a/28776166/8787985
if ! (return 0 2>/dev/null); then
logger error "Must run this shell in current process."
fi