add new verify options

This commit is contained in:
流生
2019-07-26 11:25:51 +08:00
parent ee7a05f93e
commit 3c4b4e24a1

View File

@@ -1,5 +1,9 @@
#!/usr/bin/env bash
REQUIRED_TOOLS=("cloud-init" "wget" "curl")
CLEANUP_TOOLS=("kubeadm" "kubelet" "kubectl" "kubernetes-cni")
REQUIRED_KERNEL_VERSION=3.10
REQUIRED_SYSTEMD_VERSION=219
public::common::log() {
if [ $2 == "fail" ];then
@@ -9,22 +13,36 @@ public::common::log() {
fi
}
# func for checking kernel version >= 3.10
# func for checking kernel version >= $REQUIRED_KERNEL_VERSION
public::check::kernel() {
current_kernel_version=$(uname -r)
required_kernel_version=3.10
if [ "$(printf '%s\n' "$required_kernel_version" "$current_kernel_version" | sort -V | head -n1)" = "$required_kernel_version" ] ;then
public::common::log "Check if kernel version >= $required_kernel_version." "pass"
if [ "$(printf '%s\n' "$REQUIRED_KERNEL_VERSION" "$current_kernel_version" | sort -V | head -n1)" = "$REQUIRED_KERNEL_VERSION" ] ;then
public::common::log "Check if kernel version >= $REQUIRED_KERNEL_VERSION." "pass"
else
public::common::log "Check if kernel version >= $required_kernel_version." "fail"
public::common::log "Check if kernel version >= $REQUIRED_KERNEL_VERSION." "fail"
exit 1
fi
}
# check kernel version >= 3.10
# check kernel version >= $REQUIRED_KERNEL_VERSION
public::check::kernel
# func for checking systemd version >= $REQUIRED_SYSTEMD_VERSION
public::check::systemd() {
current_systemd_version=$(systemctl --version|grep systemd |cut -d " " -f2)
if [ "$(printf '%s\n' "$REQUIRED_SYSTEMD_VERSION" "$current_systemd_version" | sort -V | head -n1)" = "$REQUIRED_SYSTEMD_VERSION" ] ;then
public::common::log "Check if systemd version >= $REQUIRED_SYSTEMD_VERSION." "pass"
else
public::common::log "Check if systemd version >= $REQUIRED_SYSTEMD_VERSION." "fail"
exit 1
fi
}
# check systemd version >= $REQUIRED_SYSTEMD_VERSION
public::check::systemd
# func for checking if sshd is running and listen on port 22
public::check::sshd() {
@@ -41,37 +59,43 @@ public::check::sshd() {
public::check::sshd
# func for checking if cloud-init is installed
public::check::cloudinit() {
which cloud-init >/dev/null 2>&1
if [ $? -ne 0 ];then
public::common::log "Check if cloud-init is installed." "fail"
exit 1
else
public::common::log "Check if cloud-init is installed." "pass"
fi
# func for checking if required tools are installed
public::check::requiredtools() {
for required_tool in ${REQUIRED_TOOLS[@]}
do
which $required_tool >/dev/null 2>&1
if [ $? -ne 0 ];then
public::common::log "Check if $required_tool is installed." "fail"
exit 1
else
public::common::log "Check if $required_tool is installed." "pass"
fi
done
}
# check if cloud-init is installed
public::check::cloudinit
# check if required tools are installed
public::check::requiredtools
# func for checking if clean up kubeadm
public::check::kubeadm() {
which kubeadm >/dev/null 2>&1
if [ $? -ne 0 ];then
public::common::log "Check if clean up kubeadm." "pass"
else
public::common::log "Check if clean up kubeadm." "fail"
exit 1
fi
# func for checking if tools are cleaned up
public::check::cleanuptools() {
for cleanup_tool in ${CLEANUP_TOOLS[@]}
do
which $cleanup_tool >/dev/null 2>&1
if [ $? -ne 0 ];then
public::common::log "Check if $cleanup_tool is cleaned up." "pass"
else
public::common::log "Check if $cleanup_tool is cleaned up." "fail"
exit 1
fi
done
}
# check if clean up kubeadm
public::check::kubeadm
public::check::cleanuptools
#TODO
#E.g. Check chronyd or ntpd is configured properly
#E.g. Check iptables
#E.. Check iptables