diff --git a/k8s/install-kube-u22-wg.sh b/k8s/install-kube-u22-wg.sh new file mode 100644 index 0000000..1222c54 --- /dev/null +++ b/k8s/install-kube-u22-wg.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +# This bash script is designed to prepare and install docker and Kubernetes for Ubuntu 22.04. +# If an error occur, the script will exit with the value of the PID to point at the logfile. +# Author: Ali Jawad FAHS, Activeeon + + +# Set up the script variables +STARTTIME=$(date +%s) +PID=$(echo $$) +EXITCODE=$PID +DATE=$(date) +LOGFILE="/var/log/kube-install.$PID.log" + + +# Set up the logging for the script +sudo touch $LOGFILE +sudo chown $USER:$USER $LOGFILE + + +# All the output of this shell script is redirected to the LOGFILE +exec 3>&1 4>&2 +trap 'exec 2>&4 1>&3' 0 1 2 3 +exec 1>$LOGFILE 2>&1 + +# A function to print a message to the stdout as well as as the LOGFILE +log_print(){ + level=$1 + Message=$2 + echo "$level [$(date)]: $Message" + echo "$level [$(date)]: $Message" >&3 + } +# A function to check for the apt lock +Check_lock() { +i=0 +log_print INFO "Checking for apt lock" +while [ `ps aux | grep [l]ock_is_held | wc -l` != 0 ]; do + echo "Lock_is_held $i" + ps aux | grep [l]ock_is_held + sleep 10 + ((i=i+10)); +done +log_print INFO "Exited the while loop, time spent: $i" +echo "ps aux | grep apt" +ps aux | grep apt +log_print INFO "Waiting for lock task ended properly." +} + + +# Start the Configuration +log_print INFO "Configuration started!" +log_print INFO "Logs are saved at: $LOGFILE" + + +# Update the package list +log_print INFO "Updating the package list." +sudo apt-get update +sudo unattended-upgrade -d + +# Check for lock +Check_lock + +# Install curl +log_print INFO "Installing curl" +sudo apt-get install -y curl || { log_print ERROR "curl installation failed!"; exit $EXITCODE; } + +# Install Docker +log_print INFO "Installing Docker" +sudo apt-get install -y docker.io +sudo systemctl enable docker +sudo systemctl status docker +sudo systemctl start docker +cat <