Files
hauler/k3ama.sh
2020-08-17 17:57:31 -04:00

96 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# , , _______________________________
# ,-----------|'------'| | |
# /. '-' |-' |_____________________________|
# |/| | |
# | .________.'----' _______________________________
# | || | || | |
# \__|' \__|' |_____________________________|
#
# |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
# |________________________________________________________|
# |
# |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
# |________________________________________________________|
#
# k3ama - airgap migration assistant
LOCAL_IMAGES_FILEPATH=/var/lib/rancher/k3s/agent/images
ADDL_IMAGES=./artifacts/images
copy_images(){
cp -rvf ${ADDL_IMAGES}/* ${LOCAL_IMAGES_FILEPATH}
}
install_k3s(){
AIRGAP_IMAGES_TAR="$1"
## Note: currently requires root
mkdir -p ${LOCAL_IMAGES_FILEPATH}
echo "copying ${AIRGAP_IMAGES_TAR} -> ${LOCAL_IMAGES_FILEPATH}"
cp artifacts/k3s-airgap-images-amd64.tar /var/lib/rancher/k3s/agent/images
# copy over the k3s binary
cp ./artifacts/k3s /usr/local/bin/k3s
chmod +x /usr/local/bin/k3s
INSTALL_K3S_SKIP_DOWNLOAD=true ./scripts/k3s-install.sh
}
uninstall_k3s(){
if [ -f "/usr/local/bin/k3s-uninstall.sh" ]; then
/usr/local/bin/k3s-uninstall.sh
else
echo "k3s is not installed"
fi
}
#gather_selinux_rpms(){
# if ! yum list installed yum-utils >/dev/null 2>&1; then
# yum install -y yum-utils
# fi
#wget -O ./https://rpm.rancher.io/k3s-selinux-0.1.1-rc1.el7.noarch.rpm
#yumdownloader --destdir=. --resolve container-selinux selinux-policy-base
#}
usage () {
echo "USAGE: $0 [--image-list rancher-images.txt] [--images rancher-images.tar.gz]"
echo " [-l|--image-list path] text file with list of images; one image per line."
echo " [-i|--images path] tar.gz generated by docker save."
echo " [-h|--help] Usage message"
}
check_firewalld(){
if pgrep -x "firewalld" >/dev/null
then
echo "[FATAL] disable firewalld first"
fi
}
check_selinux(){
# yes i know we want selinux, but it's a pain in the ass right now and i will come back to it
SELINUXSTATUS=$(getenforce)
if [ "$SELINUXSTATUS" == "Permissive" ]; then
echo "[FATAL] disable selinux"
exit 1
else
echo "SELINUX disabled. continuing"
fi
}
copy_yaml_manifests(){
cp -r ./yaml/* /var/lib/rancher/k3s/server/manifests
}
## TODO: Make this interactive with case statements
# debug
uninstall_k3s
check_firewalld
#check_selinux
install_k3s ./artifacts/k3s-airgap-images-amd64.tar
copy_images
copy_yaml_manifests
/usr/local/bin/k3s kubectl get pods -A -w