forked from platform9/pf9ctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pf9ctl_setup
executable file
·143 lines (124 loc) · 4.19 KB
/
pf9ctl_setup
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
#!/bin/bash
set -o pipefail
start_time=$(date +"%s.%N")
assert() {
if [ $# -gt 0 ]; then stdout_log "ASSERT: ${1}"; fi
if [[ -f ${log_file} ]]; then
echo -e "\n\n"
echo ""
echo "Installation failed, Here are the last 10 lines from the log"
echo "The full installation log is available at ${log_file}"
echo "If more information is needed re-run the install with --debug"
echo "$(tail ${log_file})"
else
echo "Installation failed prior to log file being created"
echo "Try re-running with --debug"
echo "Installation instructions: https://docs.platform9.com/kubernetes/PMK-CLI/#installation"
fi
exit 1
}
debugging() {
# This function handles formatting all debugging text.
# debugging is always sent to the logfile.
# If no debug flag, this function will silently log debugging messages.
# If debug flag is present then debug output will be formatted then echo'd to stdout and sent to logfile.
# If debug flag is present messages sent to stdout_log will be forwarded to debugging for consistancy.
# Avoid error if bc is not installed yet
if (which bc > /dev/null 2>&1); then
output="$(date +"%T")$(bc <<<$(date +"%s.%N")-${start_time}) :$(basename $0) : ${1}"
else
output="$(date +"%T"):$(basename $0) : ${1}"
fi
if [ -f "${log_file}" ]; then
echo "${output}" 2>&1 >> ${log_file}
fi
#echo "${output}"
}
stdout_log() {
echo "$1"
debugging "$1"
}
initialize_basedir() {
debugging "Initializing: ${pf9_basedir}"
for dir in ${pf9_state_dirs}; do
debugging "Ensuring ${dir} exists"
if ! mkdir -p "${dir}" > /dev/null 2>&1; then assert "Failed to create directory: ${dir}"; fi
done
debugging "Ensuring ${log_file} exists"
if ! mkdir -p "${dir}" > /dev/null 2>&1; then assert "Failed to create directory: ${dir}"; fi
if ! touch "${log_file}" > /dev/null 2>&1; then assert "failed to create log file: ${log_file}"; fi
}
refresh_symlink() {
# Create symlink in /usr/bin
if [ -L /usr/bin/pf9ctl ]; then
if ! (sudo rm /usr/bin/pf9ctl >> ${log_file} 2>&1); then
assert "Failed to remove existing symlink: ${cli_exec}"; fi
fi
if ! (sudo ln -s ${cli_exec} /usr/bin/pf9ctl >> ${log_file} 2>&1); then
assert "Failed to create Platform9 CLI symlink in /usr/bin"; fi
}
check_installation() {
if ! (${cli_exec} --help >> ${log_file} 2>&1); then
assert "Installation of Platform9 CLI Failed"; fi
}
download_cli_binary() {
echo "Note: SUDO access required to run Platform9 CLI."
echo " You might be prompted for your SUDO password."
echo ""
echo "Downloading Platform9 CLI binary..."
sudo rm ${cli_exec} 2> /dev/null
cd ${pf9_bin} > /dev/null && sudo curl -s -O ${cli_path} -o ${log_file} 2>&1 && cd - > /dev/null
sudo chmod 555 ${cli_exec}
echo ""
echo "Platform9 CLI binary downloaded."
echo ""
}
print_pf9_logo() {
cat << "EOF"
____ _ _ __ ___
| _ \| | __ _| |_ / _| ___ _ __ _ __ ___ / _ \
| |_) | |/ _` | __| |_ / _ \| '__| '_ ` _ \ (_) |
| __/| | (_| | |_| _| (_) | | | | | | | \__, |
|_| |_|\__,_|\__|_| \___/|_| |_| |_| |_| /_/
EOF
}
checkOS_version() {
cat /etc/*release &>/dev/null
if [ $? != 0 ];
then
echo "This OS is not supported. Supported operating systems are: Ubuntu (16.04, 18.04, 20.04), CentOS (7.x, 8.3) & RHEL 7.x"
exit
fi
}
checkCPU_Architecture() {
requiredArch="x86_64"
cpuArchitecture=$(uname -m)
if [ $cpuArchitecture != $requiredArch ];
then
echo "This CPU Architecture is not supported."
exit
fi
}
##main
pf9_basedir=$(dirname ~/pf9/.)
log_file=${pf9_basedir}/log/cli_install.log
pf9_bin=${pf9_basedir}/bin
pf9_state_dirs="${pf9_bin} ${pf9_basedir}/db ${pf9_basedir}/log"
cli_exec=${pf9_bin}/pf9ctl
cli_path="https://pmkft-assets.s3-us-west-1.amazonaws.com/pf9ctl"
checkCPU_Architecture
checkOS_version
print_pf9_logo
initialize_basedir
download_cli_binary
echo "Installing Platform9 CLI..."
echo ""
refresh_symlink
check_installation
debugging "Platform9 CLI installation completed successfully."
echo "Platform9 CLI installation completed successfully !"
echo ""
echo "To start building a Kubernetes cluster execute:"
echo " pf9ctl help"
echo ""
#eval "${cli_exec}" help